only rewrite utility files if contents changed
This commit is contained in:
@@ -48,7 +48,7 @@ for action in option.build_parser()._actions:
|
|||||||
opts.append(opt)
|
opts.append(opt)
|
||||||
|
|
||||||
PATH = util.path("data/completion/gallery-dl")
|
PATH = util.path("data/completion/gallery-dl")
|
||||||
with open(PATH, "w", encoding="utf-8") as file:
|
with util.lazy(PATH) as file:
|
||||||
file.write(TEMPLATE % {
|
file.write(TEMPLATE % {
|
||||||
"opts" : " ".join(opts),
|
"opts" : " ".join(opts),
|
||||||
"diropts" : "|".join(diropts),
|
"diropts" : "|".join(diropts),
|
||||||
|
|||||||
@@ -41,5 +41,5 @@ for action in option.build_parser()._actions:
|
|||||||
opts.append(opt)
|
opts.append(opt)
|
||||||
|
|
||||||
PATH = util.path("data/completion/gallery-dl.fish")
|
PATH = util.path("data/completion/gallery-dl.fish")
|
||||||
with open(PATH, "w", encoding="utf-8") as file:
|
with util.lazy(PATH) as file:
|
||||||
file.write(TEMPLATE % {"opts": "\n".join(opts)})
|
file.write(TEMPLATE % {"opts": "\n".join(opts)})
|
||||||
|
|||||||
@@ -46,5 +46,5 @@ for action in option.build_parser()._actions:
|
|||||||
|
|
||||||
|
|
||||||
PATH = util.path("data/completion/_gallery-dl")
|
PATH = util.path("data/completion/_gallery-dl")
|
||||||
with open(PATH, "w", encoding="utf-8") as file:
|
with util.lazy(PATH) as file:
|
||||||
file.write(TEMPLATE % {"opts": " \\\n".join(opts)})
|
file.write(TEMPLATE % {"opts": " \\\n".join(opts)})
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ and https://github.com/mikf/gallery-dl/graphs/contributors
|
|||||||
|
|
||||||
if not path:
|
if not path:
|
||||||
path = util.path("data/man/gallery-dl.1")
|
path = util.path("data/man/gallery-dl.1")
|
||||||
with open(path, "w", encoding="utf-8") as file:
|
with util.lazy(path) 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__,
|
||||||
@@ -218,7 +218,7 @@ and https://github.com/mikf/gallery-dl/graphs/contributors
|
|||||||
|
|
||||||
if not path:
|
if not path:
|
||||||
path = util.path("data/man/gallery-dl.conf.5")
|
path = util.path("data/man/gallery-dl.conf.5")
|
||||||
with open(path, "w", encoding="utf-8") as file:
|
with util.lazy(path) 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__,
|
||||||
|
|||||||
@@ -33,10 +33,10 @@ opts = re.sub(r"(?m)^(\w+.*)", "## \\1", opts) # group names to headings
|
|||||||
opts = opts.replace("\n ", "\n ") # indent by 4
|
opts = opts.replace("\n ", "\n ") # indent by 4
|
||||||
|
|
||||||
|
|
||||||
outfile = sys.argv[1] if len(sys.argv) > 1 else util.path("docs", "options.md")
|
PATH = (sys.argv[1] if len(sys.argv) > 1 else
|
||||||
with open(outfile, "w", encoding="utf-8") as fp:
|
util.path("docs", "options.md"))
|
||||||
|
with util.lazy(PATH) as file:
|
||||||
fp.write(TEMPLATE.format(
|
file.write(TEMPLATE.format(
|
||||||
"/".join(os.path.normpath(__file__).split(os.sep)[-2:]),
|
"/".join(os.path.normpath(__file__).split(os.sep)[-2:]),
|
||||||
opts,
|
opts,
|
||||||
))
|
))
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# This program is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License version 2 as
|
||||||
|
# published by the Free Software Foundation.
|
||||||
|
|
||||||
"""Generate a Markdown document listing all supported sites"""
|
"""Generate a Markdown document listing all supported sites"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
@@ -511,6 +515,7 @@ Consider all sites to be NSFW unless otherwise known.
|
|||||||
|
|
||||||
|
|
||||||
categories, domains = build_extractor_list()
|
categories, domains = build_extractor_list()
|
||||||
outfile = sys.argv[1] if len(sys.argv) > 1 else "supportedsites.md"
|
PATH = (sys.argv[1] if len(sys.argv) > 1 else
|
||||||
with open(util.path("docs", outfile), "w") as fp:
|
util.path("docs", "supportedsites.md"))
|
||||||
fp.write(generate_output(COLUMNS, categories, domains))
|
with util.lazy(PATH) as file:
|
||||||
|
file.write(generate_output(COLUMNS, categories, domains))
|
||||||
|
|||||||
@@ -1,7 +1,12 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# This program is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License version 2 as
|
||||||
|
# published by the Free Software Foundation.
|
||||||
|
|
||||||
|
import os
|
||||||
|
import io
|
||||||
import sys
|
import sys
|
||||||
import os.path
|
|
||||||
|
|
||||||
ROOTDIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
ROOTDIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||||
sys.path.insert(0, os.path.realpath(ROOTDIR))
|
sys.path.insert(0, os.path.realpath(ROOTDIR))
|
||||||
@@ -11,3 +16,32 @@ def path(*segments, join=os.path.join):
|
|||||||
result = join(ROOTDIR, *segments)
|
result = join(ROOTDIR, *segments)
|
||||||
os.makedirs(os.path.dirname(result), exist_ok=True)
|
os.makedirs(os.path.dirname(result), exist_ok=True)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
class lazy():
|
||||||
|
|
||||||
|
def __init__(self, path):
|
||||||
|
self.path = path
|
||||||
|
self.buffer = io.StringIO()
|
||||||
|
|
||||||
|
def __enter__(self):
|
||||||
|
return self.buffer
|
||||||
|
|
||||||
|
def __exit__(self, exc, value, tb):
|
||||||
|
# get content of old file
|
||||||
|
try:
|
||||||
|
with open(self.path, encoding="utf-8") as fp:
|
||||||
|
old = fp.read()
|
||||||
|
except Exception:
|
||||||
|
old = None
|
||||||
|
|
||||||
|
# get new content
|
||||||
|
new = self.buffer.getvalue()
|
||||||
|
|
||||||
|
if new != old:
|
||||||
|
# rewrite entire file
|
||||||
|
with open(self.path, "w", encoding="utf-8") as fp:
|
||||||
|
fp.write(new)
|
||||||
|
else:
|
||||||
|
# only update atime and mtime
|
||||||
|
os.utime(self.path)
|
||||||
|
|||||||
Reference in New Issue
Block a user