add '--abort-on-skip' option and ability to control skip behavior

the 'skip' config option controls skipping behavior:
    true    - skip download if file already exist (default)
    false   - download and overwrite files even if it exists
    "abort" - abort extractor run if a download would be skipped
              (same as '--abort-on-skip')
This commit is contained in:
Mike Fährmann
2017-05-03 15:17:08 +02:00
parent 7c8f61a116
commit fc9223c072
5 changed files with 37 additions and 15 deletions

View File

@@ -22,6 +22,12 @@ class ConfigAction(argparse.Action):
namespace.options.append(((self.dest,), values))
class ConfigConstAction(argparse.Action):
"""Set argparse const values as config values"""
def __call__(self, parser, namespace, values, option_string=None):
namespace.options.append(((self.dest,), self.const))
class ParseAction(argparse.Action):
"""Parse <key>=<value> options and set them as config values"""
def __call__(self, parser, namespace, values, option_string=None):
@@ -98,6 +104,12 @@ def build_parser():
metavar="ITEM-SPEC", action=ConfigAction, dest="chapters",
help=("Same as '--images' except for chapters")
)
parser.add_argument(
"--abort-on-skip",
action=ConfigConstAction, nargs=0, dest="skip", const="abort",
help=("Abort extractor run if a file download would normally be "
"skipped, i.e. if a file with the same filename already exists")
)
parser.add_argument(
"-R", "--retries",
metavar="RETRIES", action=ConfigAction, dest="retries", type=int,
@@ -105,7 +117,7 @@ def build_parser():
)
parser.add_argument(
"--http-timeout",
metavar="SECONDS", action=ConfigAction, dest="timeout", type=int,
metavar="SECONDS", action=ConfigAction, dest="timeout", type=float,
help="Timeout for HTTP connections (defaut: no timeout)",
)
parser.add_argument(