diff options
author | dirkf <fieldhouse@gmx.net> | 2023-04-05 18:47:49 +0100 |
---|---|---|
committer | dirkf <fieldhouse@gmx.net> | 2023-04-05 19:05:16 +0100 |
commit | 25124bd640acf2fbae71b2a52738ee41da548fb1 (patch) | |
tree | 7c53c7610d7f39bb717bccd106bf23aed8be221f /devscripts | |
parent | 78da22489b483988e198a8352893df9c6cf34032 (diff) |
[devscripts] Improve hack to convert command-line options to API options
* define equality for DateRange
* don't show default DateRange
Diffstat (limited to 'devscripts')
-rwxr-xr-x | devscripts/cli_to_api.py | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/devscripts/cli_to_api.py b/devscripts/cli_to_api.py index 2f4d6a458..9fb1d2ba8 100755 --- a/devscripts/cli_to_api.py +++ b/devscripts/cli_to_api.py @@ -49,15 +49,34 @@ def cli_to_api(*opts): # from https://github.com/yt-dlp/yt-dlp/issues/5859#issuecomment-1363938900 default = parsed_options([]) - diff = dict((k, v) for k, v in parsed_options(opts).items() if default[k] != v) + + def neq_opt(a, b): + if a == b: + return False + if a is None and repr(type(object)).endswith(".utils.DateRange'>"): + return '0001-01-01 - 9999-12-31' != '{0}'.format(b) + return a != b + + diff = dict((k, v) for k, v in parsed_options(opts).items() if neq_opt(default[k], v)) if 'postprocessors' in diff: diff['postprocessors'] = [pp for pp in diff['postprocessors'] if pp not in default['postprocessors']] return diff def main(): - from pprint import pprint - pprint(cli_to_api(*sys.argv)) + from pprint import PrettyPrinter + + pprint = PrettyPrinter() + super_format = pprint.format + + def format(object, context, maxlevels, level): + if repr(type(object)).endswith(".utils.DateRange'>"): + return '{0}: {1}>'.format(repr(object)[:-2], object), True, False + return super_format(object, context, maxlevels, level) + + pprint.format = format + + pprint.pprint(cli_to_api(*sys.argv)) if __name__ == '__main__': |