From 1ae1ecc6c2fdf1fba61758134f90ab4b67c13e6e Mon Sep 17 00:00:00 2001 From: Florent Rougon <f.rougon@free.fr> Date: Wed, 7 Feb 2018 23:31:38 +0100 Subject: [PATCH] terrasync.py: accept paths using backslash separators for --only-subdir We don't lose anything by accepting this, because using backslashes in file or dir names is out of question, as Windows users can't see them. --- scripts/python/TerraSync/terrasync/main.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/scripts/python/TerraSync/terrasync/main.py b/scripts/python/TerraSync/terrasync/main.py index b654e7bd1..db22da6df 100755 --- a/scripts/python/TerraSync/terrasync/main.py +++ b/scripts/python/TerraSync/terrasync/main.py @@ -644,7 +644,7 @@ def parseCommandLine(): parser.add_argument("--only-subdir", dest="onlySubdir", metavar="SUBDIR", default="", help="""\ restrict processing to this subdirectory of the TerraSync repository. Use - a relative path with '/' separators, for instance 'Models/Residential' + a path relative to the repository root, for instance 'Models/Residential' [default: process the whole repository]""") parser.add_argument("-q", "--quick", dest="quick", action="store_true", @@ -689,14 +689,17 @@ def parseCommandLine(): file=sys.stderr) sys.exit(ExitStatus.ERROR.value) - # Remove leading and trailing '/', collapse consecutive slashes. Yes, this - # implies that we tolerate leading slashes for --only-subdir. - args.virtualSubdir = VirtualPath(args.onlySubdir) + # Replace backslashes with forward slashes, remove leading and trailing + # slashes, collapse consecutive slashes. Yes, this implies that we tolerate + # leading slashes for --only-subdir (which makes sense because virtual + # paths are printed like that by this program, therefore it is natural for + # users to copy & paste such paths in order to use them for --only-subdir). + args.virtualSubdir = VirtualPath(args.onlySubdir.replace('\\', '/')) # Be nice to our user in case the path starts with '\', 'C:\', etc. if os.path.isabs(args.virtualSubdir.asRelative()): - print("{}: option --only-subdir expects a *relative*, slash-separated " - "path, but got '{}'".format(PROGNAME, args.onlySubdir), + print("{prg}: option --only-subdir expects a *relative* path, but got " + "'{subdir}'".format(prg=PROGNAME, subdir=args.onlySubdir), file=sys.stderr) sys.exit(ExitStatus.ERROR.value)