aboutsummaryrefslogtreecommitdiff
path: root/src/wikiget/wikiget.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/wikiget/wikiget.py')
-rw-r--r--src/wikiget/wikiget.py137
1 files changed, 82 insertions, 55 deletions
diff --git a/src/wikiget/wikiget.py b/src/wikiget/wikiget.py
index a8679c9..b9a227f 100644
--- a/src/wikiget/wikiget.py
+++ b/src/wikiget/wikiget.py
@@ -19,8 +19,8 @@ import argparse
import logging
import sys
-from . import DEFAULT_SITE, DEFAULT_PATH, wikiget_version
-from .dl import download
+import wikiget
+from wikiget.dl import download
def main():
@@ -29,65 +29,92 @@ def main():
when installed with `pip install` or `python setup.py install`.
"""
- parser = argparse.ArgumentParser(description="""
- A tool for downloading files from
- MediaWiki sites using the file name or
- description page URL
- """,
- epilog="""
- Copyright (C) 2018-2021 Cody Logan
- and contributors.
- License GPLv3+: GNU GPL version 3 or later
- <http://www.gnu.org/licenses/gpl.html>.
- This is free software; you are free to
- change and redistribute it under certain
- conditions. There is NO WARRANTY, to the
- extent permitted by law.
- """)
- parser.add_argument("FILE", help="""
- name of the file to download with the File:
- prefix, or the URL of its file description page
- """)
- parser.add_argument("-V", "--version", action="version",
- version=f"%(prog)s {wikiget_version}")
+ parser = argparse.ArgumentParser(
+ description="""
+ A tool for downloading files from
+ MediaWiki sites using the file name or
+ description page URL
+ """,
+ epilog="""
+ Copyright (C) 2018-2023 Cody Logan
+ and contributors.
+ License GPLv3+: GNU GPL version 3 or later
+ <http://www.gnu.org/licenses/gpl.html>.
+ This is free software; you are free to
+ change and redistribute it under certain
+ conditions. There is NO WARRANTY, to the
+ extent permitted by law.
+ """,
+ )
+ parser.add_argument(
+ "FILE",
+ help="""
+ name of the file to download with the File:
+ prefix, or the URL of its file description page
+ """,
+ )
+ parser.add_argument(
+ "-V",
+ "--version",
+ action="version",
+ version=f"%(prog)s {wikiget.wikiget_version}",
+ )
message_options = parser.add_mutually_exclusive_group()
- message_options.add_argument("-q", "--quiet",
- help="suppress warning messages",
- action="store_true")
- message_options.add_argument("-v", "--verbose",
- help="print detailed information; "
- "use -vv for even more detail",
- action="count", default=0)
- parser.add_argument("-f", "--force",
- help="force overwriting existing files",
- action="store_true")
- parser.add_argument("-s", "--site", default=DEFAULT_SITE,
- help="MediaWiki site to download from "
- "(default: %(default)s)")
- parser.add_argument("-p", "--path", default=DEFAULT_PATH,
- help="MediaWiki site path, where api.php is located "
- "(default: %(default)s)")
- parser.add_argument("--username", default="",
- help="MediaWiki site username, for private wikis")
- parser.add_argument("--password", default="",
- help="MediaWiki site password, for private wikis")
+ message_options.add_argument(
+ "-q", "--quiet", help="suppress warning messages", action="store_true"
+ )
+ message_options.add_argument(
+ "-v",
+ "--verbose",
+ help="print detailed information; use -vv for even more detail",
+ action="count",
+ default=0,
+ )
+ parser.add_argument(
+ "-f", "--force", help="force overwriting existing files", action="store_true"
+ )
+ parser.add_argument(
+ "-s",
+ "--site",
+ default=wikiget.DEFAULT_SITE,
+ help="MediaWiki site to download from (default: %(default)s)",
+ )
+ parser.add_argument(
+ "-p",
+ "--path",
+ default=wikiget.DEFAULT_PATH,
+ help="MediaWiki site path, where api.php is located (default: %(default)s)",
+ )
+ parser.add_argument(
+ "--username", default="", help="MediaWiki site username, for private wikis"
+ )
+ parser.add_argument(
+ "--password", default="", help="MediaWiki site password, for private wikis"
+ )
output_options = parser.add_mutually_exclusive_group()
- output_options.add_argument("-o", "--output",
- help="write download to OUTPUT")
- output_options.add_argument("-a", "--batch",
- help="treat FILE as a textfile containing "
- "multiple files to download, one URL or "
- "filename per line", action="store_true")
- parser.add_argument("-l", "--logfile", default="",
- help="save log output to LOGFILE")
+ output_options.add_argument("-o", "--output", help="write download to OUTPUT")
+ output_options.add_argument(
+ "-a",
+ "--batch",
+ help="treat FILE as a textfile containing "
+ "multiple files to download, one URL or "
+ "filename per line",
+ action="store_true",
+ )
+ parser.add_argument(
+ "-l",
+ "--logfile",
+ default="",
+ help="save log output to LOGFILE"
+ )
args = parser.parse_args()
loglevel = logging.WARNING
- if args.verbose >= 2:
+ if args.verbose >= wikiget.VERY_VERBOSE:
# this includes API and library messages
loglevel = logging.DEBUG
- elif args.verbose >= 1:
+ elif args.verbose >= wikiget.STD_VERBOSE:
loglevel = logging.INFO
elif args.quiet:
loglevel = logging.ERROR
@@ -120,7 +147,7 @@ def main():
# log events are appended to the file if it already exists,
# so note the start of a new download session
- logging.info(f"Starting download session using wikiget {wikiget_version}")
+ logging.info(f"Starting download session using wikiget {wikiget.wikiget_version}")
# logging.info(f"Log level is set to {loglevel}")
if args.batch:
@@ -132,7 +159,7 @@ def main():
try:
fd = open(input_file, "r")
- except IOError as e:
+ except OSError as e:
logging.error("File could not be read. "
"The following error was encountered:")
logging.error(e)