update/cleanup Python dev scripts
- put common code in its own util.py file - same Python3 shebang for all scripts - add file docstrings - fix format string replacement fields in man page template
This commit is contained in:
@@ -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),
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -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())
|
||||
|
||||
11
scripts/util.py
Normal file
11
scripts/util.py
Normal file
@@ -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)
|
||||
Reference in New Issue
Block a user