1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-22 02:32:33 +01:00

Merge branch 'options'

This commit is contained in:
Mike Fährmann 2015-11-14 17:23:24 +01:00
commit 5db2aa29cf
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88
2 changed files with 40 additions and 19 deletions

View File

@ -19,47 +19,66 @@ import sys
import argparse
from . import config, jobs
def parse_cmdline_options():
def build_cmdline_parser():
parser = argparse.ArgumentParser(
description='Download images from various sources')
parser.add_argument(
"-c", "--config",
default="~/.config/gallery/config", metavar="CFG",
help="alternate configuration file"
metavar="CFG", dest="cfgfiles", action="append",
help="additional configuration files",
)
parser.add_argument(
"-d", "--dest",
metavar="DEST",
help="destination directory"
help="destination directory",
)
parser.add_argument(
"-o", "--option",
metavar="OPT", action="append", default=[],
help="option value",
)
parser.add_argument(
"--list-modules", dest="list_modules", action="store_true",
help="print a list of available modules/supported sites",
)
parser.add_argument(
"--list-keywords", dest="keywords", action="store_true",
help="print a list of available keywords",
help="print a list of available keywords for the given URLs",
)
parser.add_argument(
"urls",
nargs="+", metavar="URL",
nargs="*", metavar="URL",
help="url to download images from"
)
return parser.parse_args()
return parser
def main():
config.load()
args = parse_cmdline_options()
for opt in args.option:
try:
key, value = opt.split("=", 1)
config.set(key.split("."), value)
except TypeError:
pass
jobtype = jobs.KeywordJob if args.keywords else jobs.DownloadJob
try:
for url in args.urls:
jobtype(url).run()
config.load()
parser = build_cmdline_parser()
args = parser.parse_args()
if args.cfgfiles:
config.load(*args.cfgfiles, strict=True)
if args.dest:
config.set(("base-directory",), args.dest)
for opt in args.option:
try:
key, value = opt.split("=", 1)
config.set(key.split("."), value)
except TypeError:
pass
if args.list_modules:
for module_name in extractor.modules:
print(module_name)
else:
if not args.urls:
parser.error("the following arguments are required: URL")
jobtype = jobs.KeywordJob if args.keywords else jobs.DownloadJob
for url in args.urls:
jobtype(url).run()
except KeyboardInterrupt:
print("\nKeyboardInterrupt")

View File

@ -16,7 +16,7 @@ import platform
# --------------------------------------------------------------------
# public interface
def load(*files):
def load(*files, strict=False):
"""Load JSON configuration files"""
configfiles = files or _default_configs
for conf in configfiles:
@ -26,6 +26,8 @@ def load(*files):
confdict = json.load(file)
_config.update(confdict)
except FileNotFoundError:
if strict:
raise
continue
except json.decoder.JSONDecodeError as exception:
print("Error while loading '", path, "':", sep="", file=sys.stderr)