]> Savannah Git Hosting - gnulib.git/commitdiff
gnulib-tool.py: Make --copy-file work.
authorBruno Haible <bruno@clisp.org>
Sun, 31 Jul 2022 18:02:40 +0000 (20:02 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 31 Jul 2022 21:52:48 +0000 (23:52 +0200)
* gnulib-tool.py (main) [copy-file]: Fix reference to uninitialized
variable. Fix error handling of os.makedirs. Pass the destdir to the
GLFileAssistant.

ChangeLog
gnulib-tool.py

index 26db83497f70f2f118e47c16f927536f888cd453..43033c1efb72c241830ecf95e23473ce2f4add0f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2022-07-31  Bruno Haible  <bruno@clisp.org>
 
+       gnulib-tool.py: Make --copy-file work.
+       * gnulib-tool.py (main) [copy-file]: Fix reference to uninitialized
+       variable. Fix error handling of os.makedirs. Pass the destdir to the
+       GLFileAssistant.
+
        gnulib-tool.py: Allow module arguments to occur at any position.
        * gnulib-tool.py (main): Collect the non-option arguments in a single
        list, regardless of their position. Use parse_known_args instead of
index f1cf389c3610e8ebfffc0616b841b8e78232ace4..f20d1157a37d349b7490891d320d82c338ea1212 100755 (executable)
@@ -892,9 +892,11 @@ def main():
 
     elif mode == 'copy-file':
         srcpath = files[0]
+        # The second argument is the destination; either a directory ot a file.
+        # It defaults to the current directory.
         if len(files) == 2:
             dest = files[1]
-        else:  # if len(files) != 2
+        else:  # if len(files) < 2
             dest = '.'
         if not auxdir:
             auxdir = 'build-aux'
@@ -914,53 +916,47 @@ def main():
         filesystem = classes.GLFileSystem(config)
         lookedup, flag = filesystem.lookup(srcpath)
         if isdir(dest):
-            destdir = str(dest)
+            destdir = dest
             if srcpath.startswith('build-aux/'):
-                destpath = constants.substart(
-                    'build-aux/', '%s/' % auxdir, srcpath)
+                destpath = constants.substart('build-aux/', '%s/' % auxdir, srcpath)
             elif srcpath.startswith('doc/'):
                 destpath = constants.substart('doc/', '%s/' % docbase, srcpath)
             elif srcpath.startswith('lib/'):
-                destpath = constants.substart(
-                    'lib/', '%s/' % sourcebase, srcpath)
+                destpath = constants.substart('lib/', '%s/' % sourcebase, srcpath)
             elif srcpath.startswith('m4/'):
                 destpath = constants.substart('m4/', '%s/' % m4base, srcpath)
             elif srcpath.startswith('tests/'):
-                destpath = constants.substart(
-                    'tests/', '%s/' % testsbase, srcpath)
-            elif srcpath.startswith('tests=lib/'):
-                destpath = constants.substart(
-                    'tests=lib/', '%s/' % testsbase, srcpath)
+                destpath = constants.substart('tests/', '%s/' % testsbase, srcpath)
             elif srcpath.startswith('top/'):
                 destpath = constants.substart('top/', '', srcpath)
             else:  # either case
                 destpath = srcpath
-        else:  # if not isdir(destpath)
-            destdir = os.path.dirname(destpath)
-            destpath = os.path.basename(destpath)
+        else:  # if not isdir(dest)
+            destdir = os.path.dirname(dest)
+            destpath = os.path.basename(dest)
         # Create the directory for destfile.
         dirname = os.path.dirname(joinpath(destdir, destpath))
         if not config['dryrun']:
             if dirname and not isdir(dirname):
                 try:  # Try to create directories
                     os.makedirs(dirname)
-                except Exception as error:
+                except FileExistsError:
                     pass
         # Copy the file.
         assistant = classes.GLFileAssistant(config)
         tmpfile = assistant.tmpfilename(destpath)
         shutil.copy(lookedup, tmpfile)
-        already_present = True
         assistant.setOriginal(srcpath)
+        assistant.config.setDestDir(destdir)
         assistant.setRewritten(destpath)
         if isfile(joinpath(destdir, destpath)):
             # The file already exists.
-            assistant.update(lookedup, flag, tmpfile, already_present)
+            assistant.update(lookedup, flag, tmpfile, True)
         else:  # if not isfile(joinpath(destdir, destpath))
             # Install the file.
             # Don't protest if the file should be there but isn't: it happens
-            # frequently that developers don't put autogenerated files under version
-            # control.
+            # frequently that developers don't put autogenerated files under
+            # version control.
             assistant.add(lookedup, flag, tmpfile)
         if isfile(tmpfile):
             os.remove(tmpfile)