[util] replace '/' with '\' in base-directory paths

... on Windows to have consistent path separators.
pull/73/head
Mike Fährmann 7 years ago
parent d0886f411e
commit d241a0fb60
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88

@ -132,6 +132,8 @@ def expand_path(path):
"""Expand environment variables and tildes (~)""" """Expand environment variables and tildes (~)"""
if not path: if not path:
return path return path
if not isinstance(path, str):
path = os.path.join(*path)
return os.path.expandvars(os.path.expanduser(path)) return os.path.expandvars(os.path.expanduser(path))
@ -353,10 +355,10 @@ class PathFormat():
self.directory = self.realdirectory = "" self.directory = self.realdirectory = ""
self.path = self.realpath = self.partpath = "" self.path = self.realpath = self.partpath = ""
bdir = extractor.config("base-directory", (".", "gallery-dl")) self.basedirectory = expand_path(
if not isinstance(bdir, str): extractor.config("base-directory", (".", "gallery-dl")))
bdir = os.path.join(*bdir) if os.altsep:
self.basedirectory = expand_path(bdir) self.basedirectory = self.basedirectory.replace(os.altsep, os.sep)
skipmode = extractor.config("skip", True) skipmode = extractor.config("skip", True)
if skipmode == "abort": if skipmode == "abort":
@ -407,7 +409,7 @@ class PathFormat():
self.keywords["extension"] = extension self.keywords["extension"] = extension
self.build_path() self.build_path()
def build_path(self, sep=os.path.sep): def build_path(self):
"""Use filename-keywords and directory to build a full path""" """Use filename-keywords and directory to build a full path"""
try: try:
filename = text.clean_path( filename = text.clean_path(
@ -415,7 +417,7 @@ class PathFormat():
except Exception as exc: except Exception as exc:
raise exception.FormatError(exc, "filename") raise exception.FormatError(exc, "filename")
filename = sep + filename filename = os.sep + filename
self.path = self.directory + filename self.path = self.directory + filename
self.realpath = self.realdirectory + filename self.realpath = self.realdirectory + filename

Loading…
Cancel
Save