Rename --fs-fix -> --fix-filenames

Also, reorder/group options so that the help message is more readable.
This commit is contained in:
Matteo Cypriani 2018-10-14 19:08:31 +02:00
parent 0995d580c9
commit 43da9301fa
1 changed files with 43 additions and 37 deletions

80
gcp
View File

@ -264,7 +264,7 @@ class GCP():
@param path: absolute path of dir @param path: absolute path of dir
@param options: options as return by optparse""" @param options: options as return by optparse"""
#We first check that the dest path exists, and create it if needed #We first check that the dest path exists, and create it if needed
dest_path = self.__filename_fix(dest_path, options, no_journal=True) dest_path = self.__fix_filenames(dest_path, options, no_journal=True)
if not os.path.exists(dest_path): if not os.path.exists(dest_path):
debug ("Creating directory %s" % dest_path) debug ("Creating directory %s" % dest_path)
os.makedirs(dest_path) #TODO: check permissions os.makedirs(dest_path) #TODO: check permissions
@ -340,10 +340,10 @@ class GCP():
filename = os.path.basename(source_file) filename = os.path.basename(source_file)
assert(filename) assert(filename)
if options.dest_file: if options.dest_file:
dest_file = self.__filename_fix(options.dest_file, options) dest_file = self.__fix_filenames(options.dest_file, options)
else: else:
dest_file = self.__filename_fix(os.path.join(dest_path, filename), dest_file = self.__fix_filenames(os.path.join(dest_path, filename),
options) options)
if os.path.exists(dest_file) and not options.force: if os.path.exists(dest_file) and not options.force:
warning (_("File [%s] already exists, skipping it!") % dest_file) warning (_("File [%s] already exists, skipping it!") % dest_file)
self.journal.copyFailed() self.journal.copyFailed()
@ -417,7 +417,7 @@ class GCP():
except KeyboardInterrupt: except KeyboardInterrupt:
self._userInterruption() self._userInterruption()
def __filename_fix(self, filename, options, no_journal=False): def __fix_filenames(self, filename, options, no_journal=False):
"""Fix filenames incompatibilities/mistake according to options """Fix filenames incompatibilities/mistake according to options
@param filename: full path to the file @param filename: full path to the file
@param options: options as parsed on command line @param options: options as parsed on command line
@ -425,7 +425,7 @@ class GCP():
@return: fixed filename""" @return: fixed filename"""
fixed_filename = filename fixed_filename = filename
if options.fs_fix == 'force' or (options.fs_fix == 'auto' and self.getFsType(filename) == 'vfat'): if options.fix_filenames == 'force' or (options.fix_filenames == 'auto' and self.getFsType(filename) == 'vfat'):
fixed_filename = filename.replace('\\','_')\ fixed_filename = filename.replace('\\','_')\
.replace(':',';')\ .replace(':',';')\
.replace('*','+')\ .replace('*','+')\
@ -561,8 +561,6 @@ class GCP():
_usage=""" _usage="""
%(prog)s [options] FILE DEST %(prog)s [options] FILE DEST
%(prog)s [options] FILE1 [FILE2 ...] DEST-DIR %(prog)s [options] FILE1 [FILE2 ...] DEST-DIR
%(prog)s --help for options list
""" """
for idx in range(len(full_args)): for idx in range(len(full_args)):
full_args[idx] = full_args[idx].encode('utf-8') full_args[idx] = full_args[idx].encode('utf-8')
@ -570,54 +568,62 @@ class GCP():
parser = ArgumentParser(usage=_usage, parser = ArgumentParser(usage=_usage,
formatter_class=RawDescriptionHelpFormatter) formatter_class=RawDescriptionHelpFormatter)
parser.add_argument("-r", "-R", "--recursive", parser.add_argument("-V", "--version",
action="store_true", default=False, action="version", version=ABOUT
help=_("copy directories recursively")
) )
parser.add_argument("-f", "--force",
group_cplike = parser.add_argument_group("cp-like options")
group_cplike.add_argument("-f", "--force",
action="store_true", default=False, action="store_true", default=False,
help=_("force overwriting of existing files") help=_("force overwriting of existing files")
) )
parser.add_argument("-p", group_cplike.add_argument("-L", "--dereference",
action="store_true", default=False,
help=_("same as --preserve=%s" % const_PRESERVE_p)
)
parser.add_argument("--preserve",
action="store", default='',
help=_("preserve specified attributes; accepted values: \
'all', or one or more amongst %s") % str(const_PRESERVE)
)
parser.add_argument("-L", "--dereference",
action="store_true", default=False, action="store_true", default=False,
help=_("always follow symbolic links in sources") help=_("always follow symbolic links in sources")
) )
parser.add_argument("-P", "--no-dereference", group_cplike.add_argument("-P", "--no-dereference",
action="store_false", dest='dereference', action="store_false", dest='dereference',
help=_("never follow symbolic links in sources") help=_("never follow symbolic links in sources")
) )
group_cplike.add_argument("-p",
action="store_true", default=False,
help=_("same as --preserve=%s" % const_PRESERVE_p)
)
group_cplike.add_argument("--preserve",
action="store", default='',
help=_("preserve specified attributes; accepted values: \
'all', or one or more amongst %s") % str(const_PRESERVE)
)
group_cplike.add_argument("-r", "-R", "--recursive",
action="store_true", default=False,
help=_("copy directories recursively")
)
group_cplike.add_argument("-v", "--verbose",
action="store_true", default=False,
help=_("Show what is currently done")
)
parser.add_argument_group(group_cplike)
group_gcpspecific = parser.add_argument_group("gcp-specific options")
#parser.add_argument("--no-unicode-fix", #parser.add_argument("--no-unicode-fix",
# action="store_false", dest='unicode_fix', default=True, # action="store_false", dest='unicode_fix', default=True,
# help=_("don't fix name encoding errors") #TODO # help=_("don't fix name encoding errors") #TODO
#) #)
parser.add_argument("--fs-fix", group_gcpspecific.add_argument("--fix-filenames",
choices = const_FS_FIX, dest='fs_fix', default='auto', choices = const_FS_FIX, dest='fix_filenames', default='auto',
help=_("fix filesystem name incompatibily (default: auto)") help=_("fix file names incompatible with the destination \
file system (default: auto)")
) )
parser.add_argument("--no-fs-fix", group_gcpspecific.add_argument("--no-fs-fix",
action="store_true", dest='no_fs_fix', default=False, action="store_true", dest='no_fs_fix', default=False,
help=_("same as --fs-fix=no (overrides --fs-fix)") help=_("[DEPRECATED] same as --fix-filename=no (overrides \
--fix-filenames)")
) )
parser.add_argument("--no-progress", group_gcpspecific.add_argument("--no-progress",
action="store_false", dest="progress", default=True, action="store_false", dest="progress", default=True,
help=_("disable progress bar") help=_("disable progress bar")
) )
parser.add_argument("-v", "--verbose", parser.add_argument_group(group_gcpspecific)
action="store_true", default=False,
help=_("Show what is currently done")
)
parser.add_argument("-V", "--version",
action="version", version=ABOUT
)
group_saving = parser.add_argument_group("sources saving") group_saving = parser.add_argument_group("sources saving")
group_saving.add_argument("--sources-save", group_saving.add_argument("--sources-save",
@ -663,7 +669,7 @@ class GCP():
logging.getLogger().setLevel(logging.DEBUG) logging.getLogger().setLevel(logging.DEBUG)
if options.no_fs_fix: if options.no_fs_fix:
options.fs_fix = 'no' options.fix_filenames = 'no'
preserve = set() preserve = set()