smaller adjustments and improvements
- requests and urllib3 version on 1 line - close input file after reading from it - use expand_path for unsupported-urls file - remove unnecessary logging from options.py
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# Copyright 2014-2017 Mike Fährmann
|
# Copyright 2014-2018 Mike Fährmann
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# This program is free software; you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License version 2 as
|
# it under the terms of the GNU General Public License version 2 as
|
||||||
@@ -28,6 +28,7 @@ log = logging.getLogger("gallery-dl")
|
|||||||
|
|
||||||
|
|
||||||
def initialize_logging(loglevel, formatter):
|
def initialize_logging(loglevel, formatter):
|
||||||
|
"""Setup basic logging functionality before configfiles have been loaded"""
|
||||||
# convert levelnames to lowercase
|
# convert levelnames to lowercase
|
||||||
for level in (10, 20, 30, 40, 50):
|
for level in (10, 20, 30, 40, 50):
|
||||||
name = logging.getLevelName(level)
|
name = logging.getLevelName(level)
|
||||||
@@ -41,6 +42,7 @@ def initialize_logging(loglevel, formatter):
|
|||||||
|
|
||||||
|
|
||||||
def progress(urls, pformat):
|
def progress(urls, pformat):
|
||||||
|
"""Wrapper around urls to output a simple progress indicator"""
|
||||||
if pformat is True:
|
if pformat is True:
|
||||||
pformat = "[{current}/{total}] {url}"
|
pformat = "[{current}/{total}] {url}"
|
||||||
pinfo = {"total": len(urls)}
|
pinfo = {"total": len(urls)}
|
||||||
@@ -50,6 +52,7 @@ def progress(urls, pformat):
|
|||||||
|
|
||||||
|
|
||||||
def sanatize_input(file):
|
def sanatize_input(file):
|
||||||
|
"""Filter and strip strings from an input file"""
|
||||||
for line in file:
|
for line in file:
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
if line:
|
if line:
|
||||||
@@ -110,13 +113,15 @@ def main():
|
|||||||
if args.loglevel >= logging.ERROR:
|
if args.loglevel >= logging.ERROR:
|
||||||
config.set(("output", "mode"), "null")
|
config.set(("output", "mode"), "null")
|
||||||
elif args.loglevel <= logging.DEBUG:
|
elif args.loglevel <= logging.DEBUG:
|
||||||
import platform, requests
|
import platform
|
||||||
|
import requests
|
||||||
log.debug("Version %s", __version__)
|
log.debug("Version %s", __version__)
|
||||||
log.debug("Python %s - %s",
|
log.debug("Python %s - %s",
|
||||||
platform.python_version(), platform.platform())
|
platform.python_version(), platform.platform())
|
||||||
try:
|
try:
|
||||||
log.debug("requests %s", requests.__version__)
|
log.debug("requests %s - urllib3 %s",
|
||||||
log.debug("urllib3 %s", requests.packages.urllib3.__version__)
|
requests.__version__,
|
||||||
|
requests.packages.urllib3.__version__)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -157,14 +162,15 @@ def main():
|
|||||||
file = sys.stdin
|
file = sys.stdin
|
||||||
else:
|
else:
|
||||||
file = open(args.inputfile)
|
file = open(args.inputfile)
|
||||||
|
|
||||||
urls += sanatize_input(file)
|
urls += sanatize_input(file)
|
||||||
|
file.close()
|
||||||
except OSError as exc:
|
except OSError as exc:
|
||||||
log.warning("input-file: %s", exc)
|
log.warning("input-file: %s", exc)
|
||||||
|
|
||||||
if args.unsupportedfile:
|
if args.unsupportedfile:
|
||||||
try:
|
try:
|
||||||
job.Job.ufile = open(args.unsupportedfile, "w")
|
path = util.expand_path(args.unsupportedfile)
|
||||||
|
job.Job.ufile = open(path, "w")
|
||||||
except OSError as exc:
|
except OSError as exc:
|
||||||
log.warning("unsupported-URL file: %s", exc)
|
log.warning("unsupported-URL file: %s", exc)
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# Copyright 2017 Mike Fährmann
|
# Copyright 2017-2018 Mike Fährmann
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# This program is free software; you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License version 2 as
|
# it under the terms of the GNU General Public License version 2 as
|
||||||
@@ -13,8 +13,6 @@ import logging
|
|||||||
import json
|
import json
|
||||||
from .version import __version__
|
from .version import __version__
|
||||||
|
|
||||||
log = logging.getLogger("option")
|
|
||||||
|
|
||||||
|
|
||||||
class ConfigAction(argparse.Action):
|
class ConfigAction(argparse.Action):
|
||||||
"""Set argparse results as config values"""
|
"""Set argparse results as config values"""
|
||||||
@@ -31,16 +29,13 @@ class ConfigConstAction(argparse.Action):
|
|||||||
class ParseAction(argparse.Action):
|
class ParseAction(argparse.Action):
|
||||||
"""Parse <key>=<value> options and set them as config values"""
|
"""Parse <key>=<value> options and set them as config values"""
|
||||||
def __call__(self, parser, namespace, values, option_string=None):
|
def __call__(self, parser, namespace, values, option_string=None):
|
||||||
|
key, _, value = values.partition("=")
|
||||||
try:
|
try:
|
||||||
key, _, value = values.partition("=")
|
value = json.loads(value)
|
||||||
try:
|
|
||||||
value = json.loads(value)
|
|
||||||
except ValueError:
|
|
||||||
pass
|
|
||||||
key = key.split(".")
|
|
||||||
namespace.options.append((key, value))
|
|
||||||
except ValueError:
|
except ValueError:
|
||||||
log.warning("Invalid '<key>=<value>' pair: %s", values)
|
pass
|
||||||
|
key = key.split(".")
|
||||||
|
namespace.options.append((key, value))
|
||||||
|
|
||||||
|
|
||||||
class Formatter(argparse.HelpFormatter):
|
class Formatter(argparse.HelpFormatter):
|
||||||
|
|||||||
Reference in New Issue
Block a user