diff --git a/scripts/bash_completion.py b/scripts/bash_completion.py index 9108cdc7..69e6a79c 100755 --- a/scripts/bash_completion.py +++ b/scripts/bash_completion.py @@ -7,13 +7,10 @@ # it under the terms of the GNU General Public License version 2 as # published by the Free Software Foundation. -import sys -import os.path +"""Generate bash completion script from gallery-dl's argument parser""" -ROOTDIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) -sys.path.insert(0, os.path.realpath(ROOTDIR)) - -from gallery_dl import option # noqa +import util +from gallery_dl import option TEMPLATE = """_gallery_dl() @@ -50,8 +47,7 @@ for action in option.build_parser()._actions: if opt.startswith("--"): opts.append(opt) - -PATH = os.path.join(ROOTDIR, "gallery-dl.bash_completion") +PATH = util.path("gallery-dl.bash_completion") with open(PATH, "w", encoding="utf-8") as file: file.write(TEMPLATE % { "opts" : " ".join(opts), diff --git a/scripts/build_testresult_db.py b/scripts/build_testresult_db.py index f1eca505..fda9f64c 100755 --- a/scripts/build_testresult_db.py +++ b/scripts/build_testresult_db.py @@ -1,12 +1,13 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +"""Collect results of extractor unit tests""" import sys import os.path import datetime -ROOTDIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) -sys.path.insert(0, os.path.realpath(ROOTDIR)) - +import util from gallery_dl import extractor, job, config from test.test_results import setup_test_config @@ -27,7 +28,7 @@ tests = [ # setup target directory -path = os.path.join(ROOTDIR, "archive/testdb", str(datetime.date.today())) +path = util.path("archive", "testdb", str(datetime.date.today())) os.makedirs(path, exist_ok=True) diff --git a/scripts/create_test_data.py b/scripts/create_test_data.py index 685e39f7..14ab0c0a 100755 --- a/scripts/create_test_data.py +++ b/scripts/create_test_data.py @@ -9,13 +9,9 @@ """Create testdata for extractor tests""" -import sys -import os.path import argparse -ROOTDIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) -sys.path.insert(0, os.path.realpath(ROOTDIR)) - +import util # noqa from gallery_dl import extractor from test.test_results import ResultJob, setup_test_config diff --git a/scripts/man.py b/scripts/man.py index b191faab..91608a3e 100755 --- a/scripts/man.py +++ b/scripts/man.py @@ -7,16 +7,14 @@ # it under the terms of the GNU General Public License version 2 as # published by the Free Software Foundation. +"""Generate man pages""" + import re -import sys -import os.path import datetime -ROOTDIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) -sys.path.insert(0, os.path.realpath(ROOTDIR)) - -import gallery_dl.option # noqa -import gallery_dl.version # noqa +import util +import gallery_dl.option +import gallery_dl.version def build_gallery_dl_1(path=None): @@ -24,7 +22,7 @@ def build_gallery_dl_1(path=None): OPTS_FMT = """.TP\n.B "{}" {}\n{}""" TEMPLATE = r""" -.TH "GALLERY-DL" "1" "$(date)s" "$(version)s" "gallery-dl Manual" +.TH "GALLERY-DL" "1" "%(date)s" "%(version)s" "gallery-dl Manual" .\" disable hyphenation .nh @@ -101,19 +99,19 @@ and https://github.com/mikf/gallery-dl/graphs/contributors )) if not path: - path = os.path.join(ROOTDIR, "gallery-dl.1") + path = util.path("gallery-dl.1") with open(path, "w", encoding="utf-8") as file: file.write(TEMPLATE.lstrip() % { "options": "\n".join(options), "version": gallery_dl.version.__version__, - "date" : datetime.datetime.now(), + "date" : datetime.datetime.now().strftime("%Y-%m-%d"), }) def build_gallery_dl_conf_5(path=None): TEMPLATE = r""" -.TH "GALLERY-DL.CONF" "5" "$(date)s" "$(version)s" "gallery-dl Manual" +.TH "GALLERY-DL.CONF" "5" "%(date)s" "%(version)s" "gallery-dl Manual" .\" disable hyphenation .nh .\" disable justification (adjust text to left margin only) @@ -219,18 +217,18 @@ and https://github.com/mikf/gallery-dl/graphs/contributors content.append(strip_rst(text, field != "Example")) if not path: - path = os.path.join(ROOTDIR, "gallery-dl.conf.5") + path = util.path("gallery-dl.conf.5") with open(path, "w", encoding="utf-8") as file: file.write(TEMPLATE.lstrip() % { "options": "\n".join(content), "version": gallery_dl.version.__version__, - "date" : datetime.datetime.now(), + "date" : datetime.datetime.now().strftime("%Y-%m-%d"), }) def parse_docs_configuration(): - doc_path = os.path.join(ROOTDIR, "docs", "configuration.rst") + doc_path = util.path("docs", "configuration.rst") with open(doc_path, encoding="utf-8") as file: doc_lines = file.readlines() diff --git a/scripts/supportedsites.py b/scripts/supportedsites.py index c032154f..9194ea46 100755 --- a/scripts/supportedsites.py +++ b/scripts/supportedsites.py @@ -1,12 +1,13 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +"""Generate a reStructuredText document with all supported sites""" import sys -import os.path import collections -ROOTDIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) -sys.path.insert(0, os.path.realpath(ROOTDIR)) -from gallery_dl import extractor # noqa +import util +from gallery_dl import extractor CATEGORY_MAP = { @@ -254,5 +255,5 @@ def write_output(fobj, columns, extractors): outfile = sys.argv[1] if len(sys.argv) > 1 else "supportedsites.rst" -with open(os.path.join(ROOTDIR, "docs", outfile), "w") as file: +with open(util.path("docs", outfile), "w") as file: write_output(file, COLUMNS, build_extractor_list()) diff --git a/scripts/util.py b/scripts/util.py new file mode 100644 index 00000000..bfbd6cbf --- /dev/null +++ b/scripts/util.py @@ -0,0 +1,11 @@ +# -*- coding: utf-8 -*- + +import sys +import os.path + +ROOTDIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +sys.path.insert(0, os.path.realpath(ROOTDIR)) + + +def path(*segments, join=os.path.join): + return join(ROOTDIR, *segments)