diff options
| author | 2019-08-31 19:59:31 -0400 | |
|---|---|---|
| committer | 2019-08-31 19:59:31 -0400 | |
| commit | 01b2d06c57d52b2c6f241b1beb0e377ee3a8b2a6 (patch) | |
| tree | 8bd4f4b1b36c1a531829e150394ffffd25e1ccdb /gallery_dl/util.py | |
| parent | b75d158d014d6c43d7d785c46c9372a9cf84d144 (diff) | |
New upstream version 1.10.3upstream/1.10.3
Diffstat (limited to 'gallery_dl/util.py')
| -rw-r--r-- | gallery_dl/util.py | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/gallery_dl/util.py b/gallery_dl/util.py index 79fa175..17cd73a 100644 --- a/gallery_dl/util.py +++ b/gallery_dl/util.py @@ -608,11 +608,13 @@ class PathFormat(): """Build directory path and create it if necessary""" # Build path segments by applying 'kwdict' to directory format strings + segments = [] + append = segments.append try: - segments = [ - self.clean_segment(format_map(kwdict).strip()) - for format_map in self.directory_formatters - ] + for formatter in self.directory_formatters: + segment = formatter(kwdict).strip() + if segment: + append(self.clean_segment(segment)) except Exception as exc: raise exception.FormatError(exc, "directory") @@ -620,16 +622,20 @@ class PathFormat(): sep = os.sep directory = self.clean_path(self.basedirectory + sep.join(segments)) - # Ensure directory ends with a path separator - if directory[-1] != sep: + # Ensure 'directory' ends with a path separator + if segments: directory += sep self.directory = directory - # Enable longer-than-260-character paths on Windows if os.name == "nt": - self.realdirectory = "\\\\?\\" + os.path.abspath(directory) + sep - else: - self.realdirectory = directory + # Enable longer-than-260-character paths on Windows + directory = "\\\\?\\" + os.path.abspath(directory) + + # abspath() in Python 3.7+ removes trailing path separators (#402) + if directory[-1] != sep: + directory += sep + + self.realdirectory = directory # Create directory tree os.makedirs(self.realdirectory, exist_ok=True) |
