Skip to content

Commit

Permalink
feat: Add support to mark specifiers as deprecated
Browse files Browse the repository at this point in the history
Across the formats, different specifiers are either buggy or undocumented.
To provide a safe way for users to migrate, a deprecation notice has been added.

Mapping tuples now can have a third field with a deprecation message that is
shown to the user as Warning, when the specifier is replaced.

See: nzbget#52
  • Loading branch information
fleXible committed Aug 25, 2019
1 parent a2c83a0 commit ce7c406
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion VideoSort.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,24 @@
# for duplicate files such as "My Movie (2).mkv"
dupe_separator = ' '


class deprecation_support:
"""Class implementing iterator for deprecation message support"""

def __init__(self, mapping):
self.iter = iter(mapping)

def __iter__(self):
return self

def __next__(self):
map_entry = next(self.iter)
return map_entry if len(map_entry) >= 3 else list(map_entry) + [None]

def next(self):
return self.__next__()


def guess_dupe_separator(format):
""" Find out a char most suitable as dupe_separator
"""
Expand Down Expand Up @@ -573,10 +591,12 @@ def path_subst(path, mapping):
while n < plen:
result = path[n]
if result == '%':
for key, value in mapping:
for key, value, msg in deprecation_support(mapping):
if path.startswith(key, n):
n += len(key)-1
result = value
if msg:
print('[WARNING] specifier %s is deprecated, %s' % (key, msg))
break
newpath.append(result)
n += 1
Expand Down

0 comments on commit ce7c406

Please sign in to comment.