diff options
author | Bruno Haible <bruno@clisp.org> | 2022-07-31 20:02:40 +0200 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2022-07-31 23:52:48 +0200 |
commit | 9d5acb8d7ebb11ad90861bbae95dff01ad156085 (patch) | |
tree | d6fe3596e827688ada2167ee4536cc0232e11ac5 /gnulib-tool.py | |
parent | 7d155923a8772e83395e5c5b439d92ce352b4bf2 (diff) | |
download | gnulib-9d5acb8d7ebb11ad90861bbae95dff01ad156085.tar.gz |
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.
Diffstat (limited to 'gnulib-tool.py')
-rwxr-xr-x | gnulib-tool.py | 34 |
1 files changed, 15 insertions, 19 deletions
diff --git a/gnulib-tool.py b/gnulib-tool.py index f1cf389c36..f20d1157a3 100755 --- a/gnulib-tool.py +++ b/gnulib-tool.py @@ -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) |