aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/python.yml38
-rw-r--r--.travis.yml22
-rw-r--r--MANIFEST.in5
-rw-r--r--README.md20
-rw-r--r--pyproject.toml186
-rw-r--r--setup.cfg11
-rw-r--r--setup.py79
-rw-r--r--src/wikiget/__init__.py9
-rw-r--r--src/wikiget/dl.py26
-rw-r--r--src/wikiget/validations.py4
-rw-r--r--src/wikiget/wikiget.py137
-rw-r--r--tests/test_validations.py35
12 files changed, 374 insertions, 198 deletions
diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml
new file mode 100644
index 0000000..bef2670
--- /dev/null
+++ b/.github/workflows/python.yml
@@ -0,0 +1,38 @@
+# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
+# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
+
+name: Python package
+
+on:
+ push:
+ branches: [ "master" ]
+ pull_request:
+ branches: [ "master" ]
+
+jobs:
+ build:
+
+ runs-on: ubuntu-latest
+ strategy:
+ fail-fast: false
+ matrix:
+ python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
+
+ steps:
+ - uses: actions/checkout@v3
+ - name: Set up Python ${{ matrix.python-version }}
+ uses: actions/setup-python@v3
+ with:
+ python-version: ${{ matrix.python-version }}
+ - name: Install dependencies
+ run: |
+ python -m pip install --upgrade pip setuptools wheel
+ python -m pip install flake8 pytest pytest-cov
+ python -m pip install .
+ - name: Lint with flake8
+ run: |
+ # stop the build if there are Python syntax errors or undefined names
+ flake8 . --count --show-source --statistics
+ - name: Test with pytest
+ run: |
+ pytest
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index c1ca29c..0000000
--- a/.travis.yml
+++ /dev/null
@@ -1,22 +0,0 @@
-language: python
-dist: xenial
-python:
- - '3.6'
- - '3.7'
- - '3.8'
- - '3.9'
- - '3.10-dev'
-install:
- - pip install -U pip
- - pip install .
-script:
- - python setup.py test
-deploy:
- provider: pypi
- user: clpo13
- password:
- secure: KvcviHqqT4YprtmzAtf9w8BkKPfwJ53LIOXmUFotzT1Qjt3FSE7bWVzDItFjy54zZM+tqKAniL91R+2tM5uQFn4fVS/yykN1Akts6ZnkJdq99Lgdb1V3gEv366K5AWoYKgjZX+PRvmOk8BXSrqbVtXN0lhmoemmeJVDqDHg2HJZNYFwvmr/g64amm2d/cdfLxKHpduwciNY6xUhOFIdlbrJ1T767mpC+gnqfzmJeNF7K95pmyBF6Wvl4AkKzwJJkyZULQF2VFtIT6bzSuM6G26ZT6H7UyoP+8+CvI4Fe6h8Ol7sWSuVC5gz+5istRORUy8RQ22HWW1ZZKOw1+8/dHuBPvIZOnfcTvNw07e7267KUoO4FfGLvTxU2likorr5gZh1YaCNut6XJkjzwNddkutCXv65H7zOhSn2gl7vMFkUUf+kEM9pSBcA1zf7Y9+7U3HgyD1OH+a5jRIOe0Vy9r3PPaMXuDgsHxZkrVlsr3LgtGwFD0jWMDZtROXds6OXW6/n6cN30IPSf/qWdgduNIq3wj0JbALI5AB0rugNNPhePMVOfF90W9WLPFlxQCjLji8NpvM5341bS8aLhFIgIfRGDgG9AN+I/dZNIwD2J0vfw/BDaLVNc2XUAGLa359Lbz9bFYUp0J5B8hdMMyR6YULaN5alz2VsUC5sD6kPiqTo=
- on:
- tags: true
- distributions: sdist bdist_wheel
- skip_existing: true
diff --git a/MANIFEST.in b/MANIFEST.in
index 04f196a..7592f0e 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -1,2 +1,3 @@
-include README.md
-include LICENSE
+graft wikiget
+graft test
+global-exclude *.py[cod]
diff --git a/README.md b/README.md
index 53061b6..fd4d464 100644
--- a/README.md
+++ b/README.md
@@ -1,13 +1,13 @@
# wikiget
-[![Build Status](https://travis-ci.org/clpo13/wikiget.svg?branch=master)](https://travis-ci.org/clpo13/wikiget)
+[![Python package](https://github.com/clpo13/wikiget/actions/workflows/python.yml/badge.svg?branch=master)](https://github.com/clpo13/wikiget/actions/workflows/python.yml)
[![PyPI version](https://badge.fury.io/py/wikiget.svg)](https://badge.fury.io/py/wikiget)
Something like wget for downloading a file from MediaWiki sites (like Wikipedia
or Wikimedia Commons) using only the file name or the URL of its description
page.
-Requires Python 3.6+. Get it with `pip install --user wikiget`.
+Requires Python 3.7+. Get it with `pip install --user wikiget` or `pipx install wikiget`.
## Usage
@@ -79,7 +79,10 @@ to clutter your system Python environment:
# and clone that instead
git clone https://github.com/clpo13/wikiget
cd wikiget
+
python3 -m venv venv
+# or
+virtualenv venv
```
To activate the virtual environment, use one of the following commands:
@@ -93,13 +96,18 @@ source venv/bin/activate
```
Then run `pip install -e .` to invoke an
-["editable" install](https://pip.pypa.io/en/stable/reference/pip_install/#editable-installs),
-meaning any changes made to the source will be reflected immediately in the
-executable script. Unit tests can be run with `python setup.py test`.
+["editable" install](https://pip.pypa.io/en/stable/topics/local-project-installs/#editable-installs)
+meaning any changes made to the source will be reflected immediately in the executable
+script. Unit tests can be run with `pytest` (make sure to run `pip install pytest`
+in the virtual environment first.)
+
+Alternatively, using [Hatch](https://hatch.pypa.io/latest/), simply clone the repository
+and run `hatch run test` to create the environment and run pytest. Also try `hatch shell`
+or `hatch run wikiget --help`.
## License
-Copyright (C) 2018-2021 Cody Logan and contributors
+Copyright (C) 2018-2023 Cody Logan and contributors
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
diff --git a/pyproject.toml b/pyproject.toml
new file mode 100644
index 0000000..aab4b3f
--- /dev/null
+++ b/pyproject.toml
@@ -0,0 +1,186 @@
+[build-system]
+requires = ["hatchling"]
+build-backend = "hatchling.build"
+
+[project]
+name = "wikiget"
+dynamic = ["version"]
+description = "CLI tool for downloading files from MediaWiki sites"
+readme = "README.md"
+authors = [
+ {name = "Cody Logan", email = "clpo13@gmail.com"}
+]
+requires-python = ">=3.7"
+license = {text = "GPL-3.0-or-later"}
+keywords = ["commons", "mediawiki", "wikimedia", "wikipedia"]
+classifiers = [
+ "Development Status :: 4 - Beta",
+ "Environment :: Console",
+ "Intended Audience :: End Users/Desktop",
+ "Operating System :: OS Independent",
+ "Topic :: Internet",
+ "Topic :: Internet :: WWW/HTTP",
+ "Topic :: Multimedia",
+ "Topic :: Multimedia :: Graphics",
+ "Topic :: Multimedia :: Sound/Audio",
+ "Topic :: Multimedia :: Video",
+ "Topic :: Utilities",
+ "Programming Language :: Python",
+ "Programming Language :: Python :: 3",
+ "Programming Language :: Python :: 3 :: Only",
+ "Programming Language :: Python :: 3.7",
+ "Programming Language :: Python :: 3.8",
+ "Programming Language :: Python :: 3.9",
+ "Programming Language :: Python :: 3.10",
+ "Programming Language :: Python :: 3.11",
+]
+dependencies = [
+ "mwclient>=0.10.0",
+ "requests",
+ "tqdm",
+]
+
+[project.urls]
+Repository = "https://github.com/clpo13/wikiget"
+"Bug Reports" = "https://github.com/clpo13/wikiget/issues"
+
+[project.scripts]
+wikiget = "wikiget.wikiget:main"
+
+[tool.hatch.version]
+path = "src/wikiget/version.py"
+
+[tool.pytest.ini_options]
+addopts = [
+ "--import-mode=importlib",
+]
+testpaths = ["tests"]
+
+[tool.hatch.build.targets.sdist]
+exclude = [
+ "/.github",
+]
+
+[tool.hatch.envs.default]
+dependencies = [
+ "coverage[toml]>=6.5",
+ "pytest",
+]
+[tool.hatch.envs.default.scripts]
+test = "python -m pytest {args}"
+test-cov = "coverage run -m pytest {args}"
+cov-report = [
+ "- coverage combine",
+ "coverage report",
+]
+cov = [
+ "test-cov",
+ "cov-report",
+]
+
+[[tool.hatch.envs.all.matrix]]
+python = ["3.7", "3.8", "3.9", "3.10", "3.11"]
+
+[tool.hatch.envs.lint]
+detached = true
+dependencies = [
+ "black",
+ "mypy",
+ "ruff",
+]
+[tool.hatch.envs.lint.scripts]
+typing = "mypy --install-types --non-interactive {args:src/wikiget tests}"
+style = [
+ "ruff {args:.}",
+ "black --check --diff {args:.}",
+]
+fmt = [
+ "black {args:.}",
+ "ruff --fix {args:.}",
+ "style",
+]
+all = [
+ "style",
+ "typing",
+]
+
+[tool.black]
+target-version = ["py37"]
+line-length = 88
+
+[tool.ruff]
+target-version = "py37"
+line-length = 88
+select = [
+ "A",
+ "ARG",
+ "B",
+ "C",
+ "DTZ",
+ "E",
+ "EM",
+ "F",
+ "FBT",
+ "I",
+ "ICN",
+ "ISC",
+ "N",
+ "PLC",
+ "PLE",
+ "PLR",
+ "PLW",
+ "Q",
+ "RUF",
+ "S",
+ "T",
+ "TID",
+ "UP",
+ "W",
+ "YTT",
+]
+ignore = [
+ # Allow non-abstract empty methods in abstract base classes
+ "B027",
+ # Allow boolean positional values in function calls, like `dict.get(... True)`
+ "FBT003",
+ # Ignore checks for possible passwords
+ "S105", "S106", "S107",
+ # Ignore complexity
+ "C901", "PLR0911", "PLR0912", "PLR0913", "PLR0915",
+ # FIXME: temporarily ignore usage of `print()`
+ "T201",
+]
+unfixable = [
+ # Don't touch unused imports
+ "F401",
+]
+
+[tool.ruff.isort]
+known-first-party = ["wikiget"]
+
+[tool.ruff.flake8-tidy-imports]
+ban-relative-imports = "all"
+
+[tool.ruff.per-file-ignores]
+# Tests can use magic values, assertions, and relative imports
+"tests/**/*" = ["PLR2004", "S101", "TID252"]
+
+[tool.coverage.run]
+source_pkgs = ["wikiget"]
+branch = true
+parallel = true
+
+[tool.coverage.paths]
+wikiget = ["wikiget"]
+tests = ["tests"]
+
+[tool.coverage.report]
+exclude_lines = [
+ "no cov",
+ "if __name__ == .__main__.:",
+ "if TYPE_CHECKING:",
+]
+
+[[tool.mypy.overrides]]
+module = ["mwclient"]
+ignore_missing_imports = true
diff --git a/setup.cfg b/setup.cfg
index 1a5c40a..044e9b4 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,9 +1,4 @@
-[aliases]
-test = pytest
-
-[tool:pytest]
-addopts = --cov=wikiget --verbose
-testpaths = test
-
[flake8]
-exclude = .eggs,.git,__pycache__,build,dist,venv
+exclude = .eggs,.git,__pycache__,build,dist,venv,.venv
+max-line-length = 88
+extend-ignore = E203
diff --git a/setup.py b/setup.py
index a10c111..6068493 100644
--- a/setup.py
+++ b/setup.py
@@ -1,78 +1,3 @@
-# wikiget - CLI tool for downloading files from Wikimedia sites
-# Copyright (C) 2018-2021 Cody Logan
-# SPDX-License-Identifier: GPL-3.0-or-later
-#
-# Wikiget is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# Wikiget is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with Wikiget. If not, see <https://www.gnu.org/licenses/>.
+from setuptools import setup
-"""Python setuptools metadata and dependencies."""
-
-from io import open
-from os import path
-
-from setuptools import setup, find_packages
-
-here = path.abspath(path.dirname(__file__))
-with open(path.join(here, "README.md"), "r") as fr:
- long_description = fr.read()
-
-version_file = {}
-with open(path.join(here, "wikiget", "version.py"), "r") as fv:
- exec(fv.read(), version_file)
-
-setup(
- name="wikiget",
- version=version_file["__version__"],
- author="Cody Logan",
- author_email="clpo13@gmail.com",
- description="CLI tool for downloading files from MediaWiki sites",
- long_description=long_description,
- long_description_content_type="text/markdown",
- url="https://github.com/clpo13/wikiget",
- keywords="commons download mediawiki wikimedia wikipedia",
- packages=find_packages(),
- classifiers=[
- "Development Status :: 4 - Beta",
- "Environment :: Console",
- "Intended Audience :: End Users/Desktop",
- "License :: OSI Approved :: GNU General Public License v3 or later "
- "(GPLv3+)",
- "Operating System :: OS Independent",
- "Programming Language :: Python",
- "Programming Language :: Python :: 3",
- "Programming Language :: Python :: 3 :: Only",
- "Programming Language :: Python :: 3.6",
- "Programming Language :: Python :: 3.7",
- "Programming Language :: Python :: 3.8",
- "Programming Language :: Python :: 3.9",
- "Topic :: Internet",
- "Topic :: Internet :: WWW/HTTP",
- "Topic :: Multimedia",
- "Topic :: Multimedia :: Graphics",
- "Topic :: Multimedia :: Sound/Audio",
- "Topic :: Multimedia :: Video",
- "Topic :: Utilities",
- ],
- python_requires=">=3.6",
- install_requires=["mwclient>=0.10.0", "requests", "tqdm"],
- setup_requires=["pytest-runner"],
- tests_require=["pytest", "pytest-cov"],
- project_urls={
- "Bug Reports": "https://github.com/clpo13/wikiget/issues",
- },
- entry_points={
- "console_scripts": [
- "wikiget=wikiget.wikiget:main",
- ],
- },
-)
+setup()
diff --git a/src/wikiget/__init__.py b/src/wikiget/__init__.py
index 4adcae3..20ea620 100644
--- a/src/wikiget/__init__.py
+++ b/src/wikiget/__init__.py
@@ -17,12 +17,15 @@
from mwclient import __version__ as mwclient_version
-from .version import __version__ as wikiget_version
+from wikiget.version import __version__ as wikiget_version
# set some global constants
BLOCKSIZE = 65536
CHUNKSIZE = 1024
DEFAULT_SITE = "commons.wikimedia.org"
DEFAULT_PATH = "/w/"
-USER_AGENT = (f"wikiget/{wikiget_version} (https://github.com/clpo13/wikiget) "
- f"mwclient/{mwclient_version}")
+USER_AGENT = "wikiget/{} (https://github.com/clpo13/wikiget) mwclient/{}".format(
+ wikiget_version, mwclient_version
+)
+STD_VERBOSE = 1
+VERY_VERBOSE = 2
diff --git a/src/wikiget/dl.py b/src/wikiget/dl.py
index 8f32218..9850ce8 100644
--- a/src/wikiget/dl.py
+++ b/src/wikiget/dl.py
@@ -24,8 +24,8 @@ from mwclient import APIError, InvalidResponse, LoginError, Site
from requests import ConnectionError, HTTPError
from tqdm import tqdm
-from . import CHUNKSIZE, DEFAULT_SITE, USER_AGENT
-from .validations import valid_file, verify_hash
+import wikiget
+from wikiget.validations import valid_file, verify_hash
def download(dl, args):
@@ -34,7 +34,7 @@ def download(dl, args):
if url.netloc:
filename = url.path
site_name = url.netloc
- if args.site is not DEFAULT_SITE:
+ if args.site is not wikiget.DEFAULT_SITE:
# this will work even if the user specifies 'commons.wikimedia.org'
logging.warning("target is a URL, "
"ignoring site specified with --site")
@@ -57,12 +57,12 @@ def download(dl, args):
dest = args.output or filename
- logging.debug(f"User agent: {USER_AGENT}")
+ logging.debug(f"User agent: {wikiget.USER_AGENT}")
# connect to site and identify ourselves
logging.info(f"Site name: {site_name}")
try:
- site = Site(site_name, path=args.path, clients_useragent=USER_AGENT)
+ site = Site(site_name, path=args.path, clients_useragent=wikiget.USER_AGENT)
if args.username and args.password:
site.login(args.username, args.password)
except ConnectionError as e:
@@ -119,24 +119,28 @@ def download(dl, args):
else:
try:
fd = open(dest, "wb")
- except IOError as e:
+ except OSError as e:
logging.error("File could not be written. "
"The following error was encountered:")
logging.error(e)
sys.exit(1)
else:
# download the file(s)
- if args.verbose >= 1:
+ if args.verbose >= wikiget.STD_VERBOSE:
leave_bars = True
else:
leave_bars = False
- with tqdm(leave=leave_bars, total=file_size,
- unit="B", unit_scale=True,
- unit_divisor=CHUNKSIZE) as progress_bar:
+ with tqdm(
+ leave=leave_bars,
+ total=file_size,
+ unit="B",
+ unit_scale=True,
+ unit_divisor=wikiget.CHUNKSIZE,
+ ) as progress_bar:
with fd:
res = site.connection.get(file_url, stream=True)
progress_bar.set_postfix(file=dest, refresh=False)
- for chunk in res.iter_content(CHUNKSIZE):
+ for chunk in res.iter_content(wikiget.CHUNKSIZE):
fd.write(chunk)
progress_bar.update(len(chunk))
diff --git a/src/wikiget/validations.py b/src/wikiget/validations.py
index bd99570..dc70df4 100644
--- a/src/wikiget/validations.py
+++ b/src/wikiget/validations.py
@@ -18,7 +18,7 @@
import hashlib
import re
-from . import BLOCKSIZE
+from wikiget import BLOCKSIZE
def valid_file(search_string):
@@ -55,7 +55,7 @@ def verify_hash(filename):
:param filename: name of the file to calculate a hash for
:return: hash digest
"""
- hasher = hashlib.sha1()
+ hasher = hashlib.sha1() # noqa: S324
with open(filename, "rb") as dl:
buf = dl.read(BLOCKSIZE)
while len(buf) > 0:
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)
diff --git a/tests/test_validations.py b/tests/test_validations.py
index 8dd4d6d..1abd96a 100644
--- a/tests/test_validations.py
+++ b/tests/test_validations.py
@@ -1,4 +1,3 @@
-# -*- coding: utf-8 -*-
# wikiget - CLI tool for downloading files from Wikimedia sites
# Copyright (C) 2018-2021 Cody Logan
# SPDX-License-Identifier: GPL-3.0-or-later
@@ -23,8 +22,12 @@ def test_invalid_site_input():
"""
Invalid site strings should not return regex match objects.
"""
- invalid_input = ["example.com", "vim.wikia.com",
- "en.wikipedia.com", "en.wikimpedia.org"]
+ invalid_input = [
+ "example.com",
+ "vim.wikia.com",
+ "en.wikipedia.com",
+ "en.wikimpedia.org",
+ ]
for i in invalid_input:
site_match = valid_site(i)
assert site_match is None
@@ -34,8 +37,12 @@ def test_valid_site_input():
"""
Valid site strings should return regex match objects.
"""
- valid_input = ["en.wikipedia.org", "commons.wikimedia.org",
- "de.wikipedia.org", "meta.wikimedia.org"]
+ valid_input = [
+ "en.wikipedia.org",
+ "commons.wikimedia.org",
+ "de.wikipedia.org",
+ "meta.wikimedia.org",
+ ]
for i in valid_input:
site_match = valid_site(i)
assert site_match is not None
@@ -50,16 +57,15 @@ def test_file_regex():
file_match = valid_file(i)
assert file_match is not None
assert file_match.group(0) == "File:Example.jpg" # entire match
- assert file_match.group(1) == "File:" # first group
- assert file_match.group(2) == "Example.jpg" # second group
+ assert file_match.group(1) == "File:" # first group
+ assert file_match.group(2) == "Example.jpg" # second group
def test_invalid_file_input():
"""
Invalid file strings should not return regex match objects.
"""
- invalid_input = ["file:example", "example.jpg", "Foo Bar.gif",
- "Fil:Example.jpg"]
+ invalid_input = ["file:example", "example.jpg", "Foo Bar.gif", "Fil:Example.jpg"]
for i in invalid_input:
file_match = valid_file(i)
assert file_match is None
@@ -69,9 +75,14 @@ def test_valid_file_input():
"""
Valid file strings should return regex match objects.
"""
- valid_input = ["Image:example.jpg", "file:example.jpg",
- "File:example.file-01.jpg", "FILE:FOO.BMP",
- "File:ß handwritten sample.gif", "File:A (1).jpeg"]
+ valid_input = [
+ "Image:example.jpg",
+ "file:example.jpg",
+ "File:example.file-01.jpg",
+ "FILE:FOO.BMP",
+ "File:ß handwritten sample.gif",
+ "File:A (1).jpeg",
+ ]
for i in valid_input:
file_match = valid_file(i)
assert file_match is not None