mirror of
https://github.com/qpdf/qpdf.git
synced 2024-12-22 19:08:59 +00:00
generate_auto_job: don't replace files that are unchanged
This commit is contained in:
parent
f60526aff9
commit
965e473a01
@ -6,6 +6,8 @@ import hashlib
|
|||||||
import re
|
import re
|
||||||
import yaml
|
import yaml
|
||||||
import json
|
import json
|
||||||
|
import filecmp
|
||||||
|
from contextlib import contextmanager
|
||||||
|
|
||||||
whoami = os.path.basename(sys.argv[0])
|
whoami = os.path.basename(sys.argv[0])
|
||||||
BANNER = f'''//
|
BANNER = f'''//
|
||||||
@ -19,6 +21,17 @@ def warn(*args, **kwargs):
|
|||||||
print(*args, file=sys.stderr, **kwargs)
|
print(*args, file=sys.stderr, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
@contextmanager
|
||||||
|
def write_file(filename):
|
||||||
|
tmpfile = filename + '.tmp'
|
||||||
|
with open(tmpfile, 'w') as f:
|
||||||
|
yield f
|
||||||
|
if os.path.exists(filename) and filecmp.cmp(filename, tmpfile, False):
|
||||||
|
os.unlink(tmpfile)
|
||||||
|
else:
|
||||||
|
os.rename(tmpfile, filename)
|
||||||
|
|
||||||
|
|
||||||
# QXXXQ
|
# QXXXQ
|
||||||
# These need manual handlers.
|
# These need manual handlers.
|
||||||
complex = set([
|
complex = set([
|
||||||
@ -105,8 +118,10 @@ class Main:
|
|||||||
return parser.parse_args(args)
|
return parser.parse_args(args)
|
||||||
|
|
||||||
def top(self, options):
|
def top(self, options):
|
||||||
if options.check:
|
if self.check_hashes():
|
||||||
self.check()
|
exit(0)
|
||||||
|
elif options.check:
|
||||||
|
exit(f'{whoami}: auto job inputs have changed')
|
||||||
elif options.generate:
|
elif options.generate:
|
||||||
self.generate()
|
self.generate()
|
||||||
else:
|
else:
|
||||||
@ -124,7 +139,7 @@ class Main:
|
|||||||
pass
|
pass
|
||||||
return hashes
|
return hashes
|
||||||
|
|
||||||
def check(self):
|
def check_hashes(self):
|
||||||
hashes = self.get_hashes()
|
hashes = self.get_hashes()
|
||||||
match = False
|
match = False
|
||||||
try:
|
try:
|
||||||
@ -137,8 +152,7 @@ class Main:
|
|||||||
match = old_hashes == hashes
|
match = old_hashes == hashes
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
if not match:
|
return match
|
||||||
exit(f'{whoami}: auto job inputs have changed')
|
|
||||||
|
|
||||||
def update_hashes(self):
|
def update_hashes(self):
|
||||||
hashes = self.get_hashes()
|
hashes = self.get_hashes()
|
||||||
@ -279,7 +293,6 @@ class Main:
|
|||||||
|
|
||||||
def generate(self):
|
def generate(self):
|
||||||
warn(f'{whoami}: regenerating auto job files')
|
warn(f'{whoami}: regenerating auto job files')
|
||||||
|
|
||||||
with open('job.yml', 'r') as f:
|
with open('job.yml', 'r') as f:
|
||||||
data = yaml.safe_load(f.read())
|
data = yaml.safe_load(f.read())
|
||||||
self.validate(data)
|
self.validate(data)
|
||||||
@ -290,20 +303,20 @@ class Main:
|
|||||||
)
|
)
|
||||||
self.options_without_help = set(self.help_options)
|
self.options_without_help = set(self.help_options)
|
||||||
self.prepare(data)
|
self.prepare(data)
|
||||||
with open(self.DESTS['decl'], 'w') as f:
|
with write_file(self.DESTS['decl']) as f:
|
||||||
print(BANNER, file=f)
|
print(BANNER, file=f)
|
||||||
for i in self.decls:
|
for i in self.decls:
|
||||||
print(i, file=f)
|
print(i, file=f)
|
||||||
with open(self.DESTS['init'], 'w') as f:
|
with write_file(self.DESTS['init']) as f:
|
||||||
print(BANNER, file=f)
|
print(BANNER, file=f)
|
||||||
for i in self.init:
|
for i in self.init:
|
||||||
print(i, file=f)
|
print(i, file=f)
|
||||||
with open(self.DESTS['help'], 'w') as f:
|
with write_file(self.DESTS['help']) as f:
|
||||||
with open('manual/cli.rst', 'r') as df:
|
with open('manual/cli.rst', 'r') as df:
|
||||||
print(BANNER, file=f)
|
print(BANNER, file=f)
|
||||||
self.generate_doc(df, f)
|
self.generate_doc(df, f)
|
||||||
self.generate_schema(data)
|
self.generate_schema(data)
|
||||||
with open(self.DESTS['schema'], 'w') as f:
|
with write_file(self.DESTS['schema']) as f:
|
||||||
print('static constexpr char const* JOB_SCHEMA_DATA = R"(' +
|
print('static constexpr char const* JOB_SCHEMA_DATA = R"(' +
|
||||||
json.dumps(self.schema, indent=2, separators=(',', ': ')) +
|
json.dumps(self.schema, indent=2, separators=(',', ': ')) +
|
||||||
')";', file=f)
|
')";', file=f)
|
||||||
|
2
job.sums
2
job.sums
@ -1,5 +1,5 @@
|
|||||||
# Generated by generate_auto_job
|
# Generated by generate_auto_job
|
||||||
generate_auto_job ea845318af6d4226761f7534c489e4abe0c5f4864b2fee10c8a16f11034b4d34
|
generate_auto_job ab9b8cdb8ccf47417d265eebcf562c51bf4d5bff6abaf0920931b972f6c7b80b
|
||||||
job.yml 2752b11028530f127b06e9731834dc3ae4c3b13d0161608e3b258cd2a79767d7
|
job.yml 2752b11028530f127b06e9731834dc3ae4c3b13d0161608e3b258cd2a79767d7
|
||||||
libqpdf/qpdf/auto_job_decl.hh db95ca0864e7495532095cd193be1ff0c15797b9ccaf252024c1154bae57b365
|
libqpdf/qpdf/auto_job_decl.hh db95ca0864e7495532095cd193be1ff0c15797b9ccaf252024c1154bae57b365
|
||||||
libqpdf/qpdf/auto_job_help.hh 383eea80e2c185ef5295fc126246457a7ceeffea759fdb90bb2e6727532ea538
|
libqpdf/qpdf/auto_job_help.hh 383eea80e2c185ef5295fc126246457a7ceeffea759fdb90bb2e6727532ea538
|
||||||
|
Loading…
Reference in New Issue
Block a user