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'
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)