2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-12-22 10:58:58 +00:00

generate_auto_job: break out build_schema for refactor

This commit is contained in:
Jay Berkenbilt 2022-01-30 14:54:18 -05:00
parent 1355d95d08
commit d9e00e8e5b
2 changed files with 84 additions and 82 deletions

View File

@ -484,36 +484,10 @@ class Main:
self.json_init.append(
f'doSetup("{key}", bindSetup(&Handlers::{method}));')
def generate_schema(self, data):
# Check to make sure that every command-line option is
# represented either in data['json'] or data['no-json'].
# Build a list of options that we expect. If an option appears
# once, we just expect to see it once. If it appears in more
# than one options table, we need to see a separate version of
# it for each option table. It is represented in job.yml
# prepended with the table prefix. The table prefix is removed
# in the schema.
expected = {}
for k, v in self.jdata.items():
tables = v['tables']
if len(tables) == 1:
expected[k] = {**v}
else:
for t in sorted(tables):
expected[f'{t}.{k}'] = {**v}
options_seen = set(data['no-json'])
self.schema = {}
def option_to_json_key(s):
def option_to_json_key(self, s):
return self.to_identifier(s, '', False)
# Walk through the json information building the schema as we
# go. This verifies consistency between command-line options
# and the json section of the data and builds up a schema by
# populating with help information as available.
def build_schema(j, s, flag, path):
def build_schema(self, j, s, flag, path, expected, options_seen):
if flag:
identifier = self.to_identifier(path, '', False)
self.json_decls.append(f'void begin{identifier}(JSON);')
@ -541,7 +515,7 @@ class Main:
schema_key = k[1:]
else:
schema_key = re.sub(r'[^\.]+\.', '', k)
schema_key = option_to_json_key(schema_key)
schema_key = self.option_to_json_key(schema_key)
schema_value = v
is_dict = False
if k in expected:
@ -549,13 +523,14 @@ class Main:
if v is None:
schema_value = re.sub(
r'--(\S+)',
lambda x: option_to_json_key(x.group(1)),
lambda x: self.option_to_json_key(x.group(1)),
expected[k]['help'])
if (isinstance(v, dict)):
is_dict = True
schema_value = {}
build_schema(v, schema_value,
schema_key, f'{path}.{schema_key}')
self.build_schema(v, schema_value,
schema_key, f'{path}.{schema_key}',
expected, options_seen)
elif (isinstance(v, list)):
if len(v) != 1:
raise Exception('json contains array with length != 1')
@ -573,8 +548,9 @@ class Main:
f' bindJSON(&Handlers::begin{identifier}Array),'
f' bindBare(&Handlers::end{identifier}Array));'
f' // {subpath}[]')
build_schema(v[0], schema_value[0],
schema_key, subpath)
self.build_schema(v[0], schema_value[0],
schema_key, subpath,
expected, options_seen)
self.json_init.append(
f'endContainer(); // {subpath}[]')
elif schema_value is None:
@ -588,7 +564,33 @@ class Main:
if flag:
self.json_init.append(f'endContainer(); // {path}')
build_schema(data['json'], self.schema, '', '')
def generate_schema(self, data):
# Check to make sure that every command-line option is
# represented either in data['json'] or data['no-json'].
# Build a list of options that we expect. If an option appears
# once, we just expect to see it once. If it appears in more
# than one options table, we need to see a separate version of
# it for each option table. It is represented in job.yml
# prepended with the table prefix. The table prefix is removed
# in the schema.
expected = {}
for k, v in self.jdata.items():
tables = v['tables']
if len(tables) == 1:
expected[k] = {**v}
else:
for t in sorted(tables):
expected[f'{t}.{k}'] = {**v}
options_seen = set(data['no-json'])
# Walk through the json information building the schema as we
# go. This verifies consistency between command-line options
# and the json section of the data and builds up a schema by
# populating with help information as available.
self.schema = {}
self.build_schema(data['json'], self.schema, '', '',
expected, options_seen)
if options_seen != set(expected.keys()):
raise Exception('missing from json: ' +
str(set(expected.keys()) - options_seen))

View File

@ -1,5 +1,5 @@
# Generated by generate_auto_job
generate_auto_job 68c39a9f6d1f10c1b9cf9af539036621589d6b0bbf3d05a2e1ddd1c9919d7383
generate_auto_job 8c88accfa988c8d6035c3e7e012bbde3da0c76fdfaba8e1460112bf344dc7b4f
include/qpdf/auto_job_c_att.hh 7ad43bb374c1370ef32ebdcdcb7b73a61d281f7f4e3f12755585872ab30fb60e
include/qpdf/auto_job_c_copy_att.hh 32275d03cdc69b703dd7e02ba0bbe15756e714e9ad185484773a6178dc09e1ee
include/qpdf/auto_job_c_enc.hh 72e138c7b96ed5aacdce78c1dec04b1c20d361faec4f8faf52f64c1d6be99265