mirror of
https://github.com/qpdf/qpdf.git
synced 2024-12-22 02:49:00 +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 yaml
|
||||
import json
|
||||
import filecmp
|
||||
from contextlib import contextmanager
|
||||
|
||||
whoami = os.path.basename(sys.argv[0])
|
||||
BANNER = f'''//
|
||||
@ -19,6 +21,17 @@ def warn(*args, **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
|
||||
# These need manual handlers.
|
||||
complex = set([
|
||||
@ -105,8 +118,10 @@ class Main:
|
||||
return parser.parse_args(args)
|
||||
|
||||
def top(self, options):
|
||||
if options.check:
|
||||
self.check()
|
||||
if self.check_hashes():
|
||||
exit(0)
|
||||
elif options.check:
|
||||
exit(f'{whoami}: auto job inputs have changed')
|
||||
elif options.generate:
|
||||
self.generate()
|
||||
else:
|
||||
@ -124,7 +139,7 @@ class Main:
|
||||
pass
|
||||
return hashes
|
||||
|
||||
def check(self):
|
||||
def check_hashes(self):
|
||||
hashes = self.get_hashes()
|
||||
match = False
|
||||
try:
|
||||
@ -137,8 +152,7 @@ class Main:
|
||||
match = old_hashes == hashes
|
||||
except Exception:
|
||||
pass
|
||||
if not match:
|
||||
exit(f'{whoami}: auto job inputs have changed')
|
||||
return match
|
||||
|
||||
def update_hashes(self):
|
||||
hashes = self.get_hashes()
|
||||
@ -279,7 +293,6 @@ class Main:
|
||||
|
||||
def generate(self):
|
||||
warn(f'{whoami}: regenerating auto job files')
|
||||
|
||||
with open('job.yml', 'r') as f:
|
||||
data = yaml.safe_load(f.read())
|
||||
self.validate(data)
|
||||
@ -290,20 +303,20 @@ class Main:
|
||||
)
|
||||
self.options_without_help = set(self.help_options)
|
||||
self.prepare(data)
|
||||
with open(self.DESTS['decl'], 'w') as f:
|
||||
with write_file(self.DESTS['decl']) as f:
|
||||
print(BANNER, file=f)
|
||||
for i in self.decls:
|
||||
print(i, file=f)
|
||||
with open(self.DESTS['init'], 'w') as f:
|
||||
with write_file(self.DESTS['init']) as f:
|
||||
print(BANNER, file=f)
|
||||
for i in self.init:
|
||||
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:
|
||||
print(BANNER, file=f)
|
||||
self.generate_doc(df, f)
|
||||
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"(' +
|
||||
json.dumps(self.schema, indent=2, separators=(',', ': ')) +
|
||||
')";', file=f)
|
||||
|
2
job.sums
2
job.sums
@ -1,5 +1,5 @@
|
||||
# Generated by generate_auto_job
|
||||
generate_auto_job ea845318af6d4226761f7534c489e4abe0c5f4864b2fee10c8a16f11034b4d34
|
||||
generate_auto_job ab9b8cdb8ccf47417d265eebcf562c51bf4d5bff6abaf0920931b972f6c7b80b
|
||||
job.yml 2752b11028530f127b06e9731834dc3ae4c3b13d0161608e3b258cd2a79767d7
|
||||
libqpdf/qpdf/auto_job_decl.hh db95ca0864e7495532095cd193be1ff0c15797b9ccaf252024c1154bae57b365
|
||||
libqpdf/qpdf/auto_job_help.hh 383eea80e2c185ef5295fc126246457a7ceeffea759fdb90bb2e6727532ea538
|
||||
|
Loading…
Reference in New Issue
Block a user