2015-04-05 17:15:27 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# Copyright 2014, 2015 Mike Fährmann
|
|
|
|
#
|
|
|
|
# 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
|
|
|
|
# published by the Free Software Foundation.
|
|
|
|
|
2014-10-12 21:56:44 +02:00
|
|
|
__author__ = "Mike Fährmann"
|
2015-04-05 17:15:27 +02:00
|
|
|
__copyright__ = "Copyright 2014, 2015 Mike Fährmann"
|
2014-10-12 21:56:44 +02:00
|
|
|
|
2015-04-05 17:15:27 +02:00
|
|
|
__license__ = "GPLv2"
|
2015-11-04 00:07:03 +01:00
|
|
|
__version__ = "0.3.2"
|
2014-10-12 21:56:44 +02:00
|
|
|
__maintainer__ = "Mike Fährmann"
|
|
|
|
__email__ = "mike_faehrmann@web.de"
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import argparse
|
2015-11-12 03:28:01 +01:00
|
|
|
from . import config, jobs
|
2014-10-12 21:56:44 +02:00
|
|
|
|
|
|
|
def parse_cmdline_options():
|
2015-04-05 17:15:27 +02:00
|
|
|
parser = argparse.ArgumentParser(
|
2014-10-12 21:56:44 +02:00
|
|
|
description='Download images from various sources')
|
2015-04-05 17:15:27 +02:00
|
|
|
parser.add_argument(
|
|
|
|
"-c", "--config",
|
|
|
|
default="~/.config/gallery/config", metavar="CFG",
|
|
|
|
help="alternate configuration file"
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"-d", "--dest",
|
|
|
|
metavar="DEST",
|
|
|
|
help="destination directory"
|
|
|
|
)
|
2015-11-10 01:56:31 +01:00
|
|
|
parser.add_argument(
|
|
|
|
"-o", "--option",
|
2015-11-12 02:26:27 +01:00
|
|
|
metavar="OPT", action="append", default=[],
|
2015-11-10 01:56:31 +01:00
|
|
|
help="option value",
|
|
|
|
)
|
2015-11-13 01:19:01 +01:00
|
|
|
parser.add_argument(
|
|
|
|
"--list-keywords", dest="keywords", action="store_true",
|
|
|
|
help="print a list of available keywords",
|
|
|
|
)
|
2015-04-05 17:15:27 +02:00
|
|
|
parser.add_argument(
|
|
|
|
"urls",
|
|
|
|
nargs="+", metavar="URL",
|
|
|
|
help="url to download images from"
|
|
|
|
)
|
|
|
|
return parser.parse_args()
|
2014-10-12 21:56:44 +02:00
|
|
|
|
|
|
|
def main():
|
2015-10-05 13:26:38 +02:00
|
|
|
config.load()
|
2015-11-12 02:26:27 +01:00
|
|
|
args = parse_cmdline_options()
|
2015-11-10 01:56:31 +01:00
|
|
|
for opt in args.option:
|
2015-11-12 02:26:27 +01:00
|
|
|
try:
|
|
|
|
key, value = opt.split("=", 1)
|
|
|
|
config.set(key.split("."), value)
|
|
|
|
except TypeError:
|
|
|
|
pass
|
2015-11-13 01:19:01 +01:00
|
|
|
jobtype = jobs.KeywordJob if args.keywords else jobs.DownloadJob
|
2015-04-10 17:31:49 +02:00
|
|
|
try:
|
2015-11-12 02:26:27 +01:00
|
|
|
for url in args.urls:
|
2015-11-13 01:19:01 +01:00
|
|
|
jobtype(url).run()
|
2015-04-10 17:31:49 +02:00
|
|
|
except KeyboardInterrupt:
|
2015-06-28 12:45:52 +02:00
|
|
|
print("\nKeyboardInterrupt")
|