1
0
Fork 0

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.
This commit is contained in:
Florent Rougon 2018-02-07 23:31:38 +01:00
parent cb6b267430
commit 1ae1ecc6c2

View file

@ -644,7 +644,7 @@ def parseCommandLine():
parser.add_argument("--only-subdir", dest="onlySubdir", metavar="SUBDIR", parser.add_argument("--only-subdir", dest="onlySubdir", metavar="SUBDIR",
default="", help="""\ default="", help="""\
restrict processing to this subdirectory of the TerraSync repository. Use 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]""") [default: process the whole repository]""")
parser.add_argument("-q", "--quick", dest="quick", action="store_true", parser.add_argument("-q", "--quick", dest="quick", action="store_true",
@ -689,14 +689,17 @@ def parseCommandLine():
file=sys.stderr) file=sys.stderr)
sys.exit(ExitStatus.ERROR.value) sys.exit(ExitStatus.ERROR.value)
# Remove leading and trailing '/', collapse consecutive slashes. Yes, this # Replace backslashes with forward slashes, remove leading and trailing
# implies that we tolerate leading slashes for --only-subdir. # slashes, collapse consecutive slashes. Yes, this implies that we tolerate
args.virtualSubdir = VirtualPath(args.onlySubdir) # 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. # Be nice to our user in case the path starts with '\', 'C:\', etc.
if os.path.isabs(args.virtualSubdir.asRelative()): if os.path.isabs(args.virtualSubdir.asRelative()):
print("{}: option --only-subdir expects a *relative*, slash-separated " print("{prg}: option --only-subdir expects a *relative* path, but got "
"path, but got '{}'".format(PROGNAME, args.onlySubdir), "'{subdir}'".format(prg=PROGNAME, subdir=args.onlySubdir),
file=sys.stderr) file=sys.stderr)
sys.exit(ExitStatus.ERROR.value) sys.exit(ExitStatus.ERROR.value)