implement a 'path-strip' option
This commit is contained in:
@@ -245,6 +245,24 @@ Description
|
||||
escaped with backslashes, e.g. ``"\\[\\]"``
|
||||
|
||||
|
||||
extractor.*.path-strip
|
||||
----------------------
|
||||
Type
|
||||
``string``
|
||||
Default
|
||||
``"auto"``
|
||||
Description
|
||||
Set of characters to remove from the end of generated path segment names
|
||||
using `str.rstrip() <https://docs.python.org/3/library/stdtypes.html#str.rstrip>`_
|
||||
|
||||
Special values:
|
||||
|
||||
* ``"auto"``: Use characters from ``"unix"`` or ``"windows"``
|
||||
depending on the local operating system
|
||||
* ``"unix"``: ``""``
|
||||
* ``"windows"``: ``". "``
|
||||
|
||||
|
||||
extractor.*.extension-map
|
||||
-------------------------
|
||||
Type
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
"path-restrict": "auto",
|
||||
"path-replace": "_",
|
||||
"path-remove": "\\u0000-\\u001f\\u007f",
|
||||
"path-strip": "auto",
|
||||
"extension-map": {
|
||||
"jpeg": "jpg",
|
||||
"jpe" : "jpg",
|
||||
|
||||
@@ -849,6 +849,15 @@ class PathFormat():
|
||||
remove = config("path-remove", "\x00-\x1f\x7f")
|
||||
self.clean_path = self._build_cleanfunc(remove, "")
|
||||
|
||||
strip = config("path-strip", "auto")
|
||||
if strip == "auto":
|
||||
strip = ". " if WINDOWS else ""
|
||||
elif strip == "unix":
|
||||
strip = ""
|
||||
elif strip == "windows":
|
||||
strip = ". "
|
||||
self.strip = strip
|
||||
|
||||
basedir = extractor._parentdir
|
||||
if not basedir:
|
||||
basedir = config("base-directory")
|
||||
@@ -982,13 +991,14 @@ class PathFormat():
|
||||
"""Apply 'kwdict' to directory format strings"""
|
||||
segments = []
|
||||
append = segments.append
|
||||
strip = self.strip
|
||||
|
||||
try:
|
||||
for formatter in self.directory_formatters:
|
||||
segment = formatter(kwdict).strip()
|
||||
if WINDOWS:
|
||||
if strip:
|
||||
# remove trailing dots and spaces (#647)
|
||||
segment = segment.rstrip(". ")
|
||||
segment = segment.rstrip(strip)
|
||||
if segment:
|
||||
append(self.clean_segment(segment))
|
||||
return segments
|
||||
@@ -998,6 +1008,7 @@ class PathFormat():
|
||||
def build_directory_conditional(self, kwdict):
|
||||
segments = []
|
||||
append = segments.append
|
||||
strip = self.strip
|
||||
|
||||
try:
|
||||
for condition, formatters in self.directory_conditions:
|
||||
@@ -1007,8 +1018,8 @@ class PathFormat():
|
||||
formatters = self.directory_formatters
|
||||
for formatter in formatters:
|
||||
segment = formatter(kwdict).strip()
|
||||
if WINDOWS:
|
||||
segment = segment.rstrip(". ")
|
||||
if strip:
|
||||
segment = segment.rstrip(strip)
|
||||
if segment:
|
||||
append(self.clean_segment(segment))
|
||||
return segments
|
||||
|
||||
Reference in New Issue
Block a user