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
|
# it under the terms of the GNU General Public License version 2 as
|
||||||
# published by the Free Software Foundation.
|
# published by the Free Software Foundation.
|
||||||
|
|
||||||
import sys
|
"""Generate bash completion script from gallery-dl's argument parser"""
|
||||||
import os.path
|
|
||||||
|
|
||||||
ROOTDIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
import util
|
||||||
sys.path.insert(0, os.path.realpath(ROOTDIR))
|
from gallery_dl import option
|
||||||
|
|
||||||
from gallery_dl import option # noqa
|
|
||||||
|
|
||||||
|
|
||||||
TEMPLATE = """_gallery_dl()
|
TEMPLATE = """_gallery_dl()
|
||||||
@@ -50,8 +47,7 @@ for action in option.build_parser()._actions:
|
|||||||
if opt.startswith("--"):
|
if opt.startswith("--"):
|
||||||
opts.append(opt)
|
opts.append(opt)
|
||||||
|
|
||||||
|
PATH = util.path("gallery-dl.bash_completion")
|
||||||
PATH = os.path.join(ROOTDIR, "gallery-dl.bash_completion")
|
|
||||||
with open(PATH, "w", encoding="utf-8") as file:
|
with open(PATH, "w", encoding="utf-8") as file:
|
||||||
file.write(TEMPLATE % {
|
file.write(TEMPLATE % {
|
||||||
"opts" : " ".join(opts),
|
"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 sys
|
||||||
import os.path
|
import os.path
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
ROOTDIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
import util
|
||||||
sys.path.insert(0, os.path.realpath(ROOTDIR))
|
|
||||||
|
|
||||||
from gallery_dl import extractor, job, config
|
from gallery_dl import extractor, job, config
|
||||||
from test.test_results import setup_test_config
|
from test.test_results import setup_test_config
|
||||||
|
|
||||||
@@ -27,7 +28,7 @@ tests = [
|
|||||||
|
|
||||||
# setup target directory
|
# 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)
|
os.makedirs(path, exist_ok=True)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -9,13 +9,9 @@
|
|||||||
|
|
||||||
"""Create testdata for extractor tests"""
|
"""Create testdata for extractor tests"""
|
||||||
|
|
||||||
import sys
|
|
||||||
import os.path
|
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
ROOTDIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
import util # noqa
|
||||||
sys.path.insert(0, os.path.realpath(ROOTDIR))
|
|
||||||
|
|
||||||
from gallery_dl import extractor
|
from gallery_dl import extractor
|
||||||
from test.test_results import ResultJob, setup_test_config
|
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
|
# it under the terms of the GNU General Public License version 2 as
|
||||||
# published by the Free Software Foundation.
|
# published by the Free Software Foundation.
|
||||||
|
|
||||||
|
"""Generate man pages"""
|
||||||
|
|
||||||
import re
|
import re
|
||||||
import sys
|
|
||||||
import os.path
|
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
ROOTDIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
import util
|
||||||
sys.path.insert(0, os.path.realpath(ROOTDIR))
|
import gallery_dl.option
|
||||||
|
import gallery_dl.version
|
||||||
import gallery_dl.option # noqa
|
|
||||||
import gallery_dl.version # noqa
|
|
||||||
|
|
||||||
|
|
||||||
def build_gallery_dl_1(path=None):
|
def build_gallery_dl_1(path=None):
|
||||||
@@ -24,7 +22,7 @@ def build_gallery_dl_1(path=None):
|
|||||||
OPTS_FMT = """.TP\n.B "{}" {}\n{}"""
|
OPTS_FMT = """.TP\n.B "{}" {}\n{}"""
|
||||||
|
|
||||||
TEMPLATE = r"""
|
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
|
.\" disable hyphenation
|
||||||
.nh
|
.nh
|
||||||
|
|
||||||
@@ -101,19 +99,19 @@ and https://github.com/mikf/gallery-dl/graphs/contributors
|
|||||||
))
|
))
|
||||||
|
|
||||||
if not path:
|
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:
|
with open(path, "w", encoding="utf-8") as file:
|
||||||
file.write(TEMPLATE.lstrip() % {
|
file.write(TEMPLATE.lstrip() % {
|
||||||
"options": "\n".join(options),
|
"options": "\n".join(options),
|
||||||
"version": gallery_dl.version.__version__,
|
"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):
|
def build_gallery_dl_conf_5(path=None):
|
||||||
|
|
||||||
TEMPLATE = r"""
|
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
|
.\" disable hyphenation
|
||||||
.nh
|
.nh
|
||||||
.\" disable justification (adjust text to left margin only)
|
.\" 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"))
|
content.append(strip_rst(text, field != "Example"))
|
||||||
|
|
||||||
if not path:
|
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:
|
with open(path, "w", encoding="utf-8") as file:
|
||||||
file.write(TEMPLATE.lstrip() % {
|
file.write(TEMPLATE.lstrip() % {
|
||||||
"options": "\n".join(content),
|
"options": "\n".join(content),
|
||||||
"version": gallery_dl.version.__version__,
|
"version": gallery_dl.version.__version__,
|
||||||
"date" : datetime.datetime.now(),
|
"date" : datetime.datetime.now().strftime("%Y-%m-%d"),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
def parse_docs_configuration():
|
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:
|
with open(doc_path, encoding="utf-8") as file:
|
||||||
doc_lines = file.readlines()
|
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 sys
|
||||||
import os.path
|
|
||||||
import collections
|
import collections
|
||||||
|
|
||||||
ROOTDIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
import util
|
||||||
sys.path.insert(0, os.path.realpath(ROOTDIR))
|
from gallery_dl import extractor
|
||||||
from gallery_dl import extractor # noqa
|
|
||||||
|
|
||||||
|
|
||||||
CATEGORY_MAP = {
|
CATEGORY_MAP = {
|
||||||
@@ -254,5 +255,5 @@ def write_output(fobj, columns, extractors):
|
|||||||
|
|
||||||
|
|
||||||
outfile = sys.argv[1] if len(sys.argv) > 1 else "supportedsites.rst"
|
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())
|
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