Commit caa00556cfd0f6d45c49eb3d546f41b5c69900eb

Authored by Jay Berkenbilt
1 parent 1a3ed1ee

Change filename or path to file in json and QPDFJob

Use "file" consistently for specifying a file path. We use "filename"
when adding attachments for a completely different purpose.
generate_auto_job
... ... @@ -495,7 +495,11 @@ class Main:
495 495 def build_schema(self, j, path, flag, expected, options_seen):
496 496 if flag in expected:
497 497 options_seen.add(flag)
498   - elif not (flag == '' or flag.startswith('_') or isinstance(j, str)):
  498 + elif isinstance(j, str):
  499 + if not flag.startswith('_'):
  500 + raise Exception(f'json: {flag} has a description'
  501 + ' but doesn\'t start with _')
  502 + elif not (flag == '' or flag.startswith('_')):
499 503 raise Exception(f'json: unknown key {flag}')
500 504  
501 505 if isinstance(j, dict):
... ...
include/qpdf/QPDFJob.hh
... ... @@ -190,7 +190,7 @@ class QPDFJob
190 190 QPDF_DLL
191 191 Config* endAddAttachment();
192 192 QPDF_DLL
193   - AttConfig* path(char const* parameter);
  193 + AttConfig* file(char const* parameter);
194 194  
195 195 # include <qpdf/auto_job_c_att.hh>
196 196  
... ... @@ -210,7 +210,7 @@ class QPDFJob
210 210 QPDF_DLL
211 211 Config* endCopyAttachmentsFrom();
212 212 QPDF_DLL
213   - CopyAttConfig* path(char const* parameter);
  213 + CopyAttConfig* file(char const* parameter);
214 214  
215 215 # include <qpdf/auto_job_c_copy_att.hh>
216 216  
... ... @@ -251,7 +251,7 @@ class QPDFJob
251 251 QPDF_DLL
252 252 Config* endUnderlayOverlay();
253 253 QPDF_DLL
254   - UOConfig* path(char const* parameter);
  254 + UOConfig* file(char const* parameter);
255 255  
256 256 # include <qpdf/auto_job_c_uo.hh>
257 257  
... ... @@ -270,7 +270,7 @@ class QPDFJob
270 270 QPDF_DLL
271 271 Config* endEncrypt();
272 272 QPDF_DLL
273   - EncConfig* path(char const* parameter);
  273 + EncConfig* file(char const* parameter);
274 274  
275 275 # include <qpdf/auto_job_c_enc.hh>
276 276  
... ...
job.sums
1 1 # Generated by generate_auto_job
2   -generate_auto_job e28f3fb4938f6307bb4c23c084c239832dbee3bbaedf19a22fb19215312b30b0
  2 +generate_auto_job ef1b438aeebed7ca0afcbe4d1f9c54d3acf899aec8410ebc69cd15ec673dd158
3 3 include/qpdf/auto_job_c_att.hh 7ad43bb374c1370ef32ebdcdcb7b73a61d281f7f4e3f12755585872ab30fb60e
4 4 include/qpdf/auto_job_c_copy_att.hh 32275d03cdc69b703dd7e02ba0bbe15756e714e9ad185484773a6178dc09e1ee
5 5 include/qpdf/auto_job_c_enc.hh 72e138c7b96ed5aacdce78c1dec04b1c20d361faec4f8faf52f64c1d6be99265
6 6 include/qpdf/auto_job_c_main.hh 516adb23cc7e44e614e436880be870d0574e4ebbc706cd855a1360000eed31bb
7 7 include/qpdf/auto_job_c_pages.hh 931840b329a36ca0e41401190e04537b47f2867671a6643bfd8da74014202671
8 8 include/qpdf/auto_job_c_uo.hh 0585b7de459fa479d9e51a45fa92de0ff6dee748efc9ec1cedd0dde6cee1ad50
9   -job.yml 2ccc58ef74b875524505d7f00561b2df27ec2000846a549ac21a1fdd2f74c096
  9 +job.yml fe299f5fe022bd79884b3c66a8134386d8bf5ad42c32bdef37fc7044e5f003b9
10 10 libqpdf/qpdf/auto_job_decl.hh 9f79396ec459f191be4c5fe34cf88c265cf47355a1a945fa39169d1c94cf04f6
11 11 libqpdf/qpdf/auto_job_help.hh 23c79f1d2c02bda28f64aace17f69487205c797e7ae2234892cbbabab49d6d47
12 12 libqpdf/qpdf/auto_job_init.hh 8e9e31b6099a662497339b27f6e2d7f779f35011e88a834bee8811c33405a0fe
13   -libqpdf/qpdf/auto_job_json_decl.hh 4846055075dcb7365c56c02150e955979b522d14f4329ce7a8a302ccd1d7aa2a
14   -libqpdf/qpdf/auto_job_json_init.hh 8ccfcfe06339c69631da2167cd1a77844a3cc9031e4090998113ef70b96bcb70
15   -libqpdf/qpdf/auto_job_schema.hh 27cadf4f0c99dd27c569ec6d870a51d2abb51c8daaad94a55c42b6e86cf7726a
  13 +libqpdf/qpdf/auto_job_json_decl.hh 741a44106f7850b6cbc8af264b5b77bb605475c8d8dd8cd87011d5debbee6269
  14 +libqpdf/qpdf/auto_job_json_init.hh 886dd8ed7ae7691eaa97a0e5b3f1445f4cccab88ed372f530a8524d198c8f1d9
  15 +libqpdf/qpdf/auto_job_schema.hh a764050cc99f1cc95645fd1ea2f020c4b778957abc64fbc55c12eac3a369dc92
16 16 manual/_ext/qpdf.py e9ac9d6c70642a3d29281ee5ad92ae2422dee8be9306fb8a0bc9dba0ed5e28f3
17 17 manual/cli.rst 79140e023faa0cb77afe0b1dc512dd120ee5617f4db82f842596e4f239f93882
... ...
... ... @@ -249,23 +249,23 @@ no-json:
249 249 - is-encrypted
250 250 json:
251 251 # The structure of this section defines what the json input to
252   - # QPDFJob looks like. If a key starts with underscore or has a value
253   - # that is a string, it does not map to a command-line argument. If
254   - # value is null, its properties and help come from other information
255   - # known by generate_auto_job. Otherwise, it has to match a
256   - # command-line option. This information is used to construct a
257   - # "schema" (as in JSON.hh) for the json input to QPDFJob. The
258   - # leading underscore is removed. *NOTE*: all keys are converted to
259   - # camelCase for the schema and must be appear that way in the
260   - # user-supplied json. This makes it more convenient to populate JSON
261   - # objects in some languages.
  252 + # QPDFJob looks like. If a key starts with underscore, it does not
  253 + # map to a command-line argument. If the value is a string, that is
  254 + # the help information. Otherwise, if the value is null, it has to
  255 + # match a command-line option, and its properties and help come from
  256 + # other information known by generate_auto_job. This information is
  257 + # used to construct a "schema" (as in JSON.hh) for the json input to
  258 + # QPDFJob. The leading underscore is removed. *NOTE*: all keys are
  259 + # converted to camelCase for the schema and must be appear that way
  260 + # in the user-supplied json. This makes it more convenient to
  261 + # populate JSON objects in some languages.
262 262 _input:
263   - _filename: "input filename"
  263 + _file: "input filename"
264 264 main.password:
265 265 password-file:
266 266 empty:
267 267 _output:
268   - _filename: "output filename"
  268 + _file: "output filename"
269 269 _replace-input: "set to true to replace input"
270 270 _options:
271 271 qdf:
... ... @@ -291,8 +291,8 @@ json:
291 291 progress:
292 292 split-pages:
293 293 encrypt:
294   - user-password: "user password"
295   - owner-password: "owner password"
  294 + _user-password: "user password"
  295 + _owner-password: "owner password"
296 296 _40bit:
297 297 Enc40.annotate:
298 298 Enc40.extract:
... ... @@ -359,7 +359,7 @@ json:
359 359 ii-min-bytes:
360 360 remove-unreferenced-resources:
361 361 add-attachment:
362   - - path: "attachment to add"
  362 + - _file: "attachment to add"
363 363 creationdate:
364 364 description:
365 365 filename:
... ... @@ -369,7 +369,7 @@ json:
369 369 replace:
370 370 remove-attachment:
371 371 copy-attachments-from:
372   - - path: "attachment source filename"
  372 + - _file: "attachment source filename"
373 373 CopyAtt.password:
374 374 prefix:
375 375 collate:
... ... @@ -382,19 +382,19 @@ json:
382 382 oi-min-width:
383 383 optimize-images:
384 384 pages:
385   - - file: "source for for pages"
  385 + - _file: "source for for pages"
386 386 Pages.password:
387   - range: "page range"
  387 + _range: "page range"
388 388 remove-page-labels:
389 389 rotate:
390 390 overlay:
391   - file: "source file for overlay"
  391 + _file: "source file for overlay"
392 392 UO.password:
393 393 from:
394 394 repeat:
395 395 to:
396 396 underlay:
397   - file: "source file for underlay"
  397 + _file: "source file for underlay"
398 398 UO.password:
399 399 from:
400 400 repeat:
... ...
libqpdf/QPDFJob_argv.cc
... ... @@ -426,7 +426,7 @@ ArgParser::argEnd256BitEncryption()
426 426 void
427 427 ArgParser::argUOPositional(char* arg)
428 428 {
429   - c_uo->path(arg);
  429 + c_uo->file(arg);
430 430 }
431 431  
432 432 void
... ... @@ -439,7 +439,7 @@ ArgParser::argEndUnderlayOverlay()
439 439 void
440 440 ArgParser::argAttPositional(char* arg)
441 441 {
442   - c_att->path(arg);
  442 + c_att->file(arg);
443 443 }
444 444  
445 445 void
... ... @@ -452,7 +452,7 @@ ArgParser::argEndAttachment()
452 452 void
453 453 ArgParser::argCopyAttPositional(char* arg)
454 454 {
455   - c_copy_att->path(arg);
  455 + c_copy_att->file(arg);
456 456 }
457 457  
458 458 void
... ...
libqpdf/QPDFJob_config.cc
... ... @@ -761,7 +761,7 @@ QPDFJob::CopyAttConfig::CopyAttConfig(Config* c) :
761 761 }
762 762  
763 763 QPDFJob::CopyAttConfig*
764   -QPDFJob::CopyAttConfig::path(char const* parameter)
  764 +QPDFJob::CopyAttConfig::file(char const* parameter)
765 765 {
766 766 this->caf.path = parameter;
767 767 return this;
... ... @@ -786,7 +786,7 @@ QPDFJob::CopyAttConfig::endCopyAttachmentsFrom()
786 786 {
787 787 if (this->caf.path.empty())
788 788 {
789   - usage("copy attachments: no path specified");
  789 + usage("copy attachments: no file specified");
790 790 }
791 791 this->config->o.m->attachments_to_copy.push_back(this->caf);
792 792 return this->config;
... ... @@ -804,7 +804,7 @@ QPDFJob::Config::addAttachment()
804 804 }
805 805  
806 806 QPDFJob::AttConfig*
807   -QPDFJob::AttConfig::path(char const* parameter)
  807 +QPDFJob::AttConfig::file(char const* parameter)
808 808 {
809 809 this->att.path = parameter;
810 810 return this;
... ... @@ -878,12 +878,12 @@ QPDFJob::AttConfig::endAddAttachment()
878 878 QUtil::get_current_qpdf_time());
879 879 if (this->att.path.empty())
880 880 {
881   - usage("add attachment: no path specified");
  881 + usage("add attachment: no file specified");
882 882 }
883 883 std::string last_element = QUtil::path_basename(this->att.path);
884 884 if (last_element.empty())
885 885 {
886   - usage("path for --add-attachment may not be empty");
  886 + usage("file for --add-attachment may not be empty");
887 887 }
888 888 if (this->att.filename.empty())
889 889 {
... ... @@ -972,7 +972,7 @@ QPDFJob::UOConfig::endUnderlayOverlay()
972 972 }
973 973  
974 974 QPDFJob::UOConfig*
975   -QPDFJob::UOConfig::path(char const* parameter)
  975 +QPDFJob::UOConfig::file(char const* parameter)
976 976 {
977 977 if (! config->o.m->under_overlay->filename.empty())
978 978 {
... ...
libqpdf/QPDFJob_json.cc
... ... @@ -228,7 +228,7 @@ Handlers::endInput()
228 228 }
229 229  
230 230 void
231   -Handlers::setupInputFilename()
  231 +Handlers::setupInputFile()
232 232 {
233 233 addParameter([this](char const* p) {
234 234 c_main->inputFile(p);
... ... @@ -264,7 +264,7 @@ Handlers::endOutput()
264 264 }
265 265  
266 266 void
267   -Handlers::setupOutputFilename()
  267 +Handlers::setupOutputFile()
268 268 {
269 269 addParameter([this](char const* p) {
270 270 c_main->outputFile(p);
... ... @@ -465,10 +465,10 @@ Handlers::endOptionsAddAttachment()
465 465 }
466 466  
467 467 void
468   -Handlers::setupOptionsAddAttachmentPath()
  468 +Handlers::setupOptionsAddAttachmentFile()
469 469 {
470 470 addParameter([this](char const* p) {
471   - c_att->path(p);
  471 + c_att->file(p);
472 472 });
473 473 }
474 474  
... ... @@ -498,10 +498,10 @@ Handlers::endOptionsCopyAttachmentsFrom()
498 498 }
499 499  
500 500 void
501   -Handlers::setupOptionsCopyAttachmentsFromPath()
  501 +Handlers::setupOptionsCopyAttachmentsFromFile()
502 502 {
503 503 addParameter([this](char const* p) {
504   - c_copy_att->path(p);
  504 + c_copy_att->file(p);
505 505 });
506 506 }
507 507  
... ... @@ -600,7 +600,7 @@ void
600 600 Handlers::setupOptionsOverlayFile()
601 601 {
602 602 addParameter([this](char const* p) {
603   - c_uo->path(p);
  603 + c_uo->file(p);
604 604 });
605 605 }
606 606  
... ... @@ -629,7 +629,7 @@ void
629 629 Handlers::setupOptionsUnderlayFile()
630 630 {
631 631 addParameter([this](char const* p) {
632   - c_uo->path(p);
  632 + c_uo->file(p);
633 633 });
634 634 }
635 635  
... ...
libqpdf/qpdf/auto_job_json_decl.hh
... ... @@ -5,12 +5,12 @@
5 5 //
6 6 void beginInput(JSON);
7 7 void endInput();
8   -void setupInputFilename();
  8 +void setupInputFile();
9 9 void setupInputPassword();
10 10 void setupInputEmpty();
11 11 void beginOutput(JSON);
12 12 void endOutput();
13   -void setupOutputFilename();
  13 +void setupOutputFile();
14 14 void setupOutputReplaceInput();
15 15 void beginOutputOptions(JSON);
16 16 void endOutputOptions();
... ... @@ -36,12 +36,12 @@ void beginOptionsAddAttachmentArray(JSON);
36 36 void endOptionsAddAttachmentArray();
37 37 void beginOptionsAddAttachment(JSON);
38 38 void endOptionsAddAttachment();
39   -void setupOptionsAddAttachmentPath();
  39 +void setupOptionsAddAttachmentFile();
40 40 void beginOptionsCopyAttachmentsFromArray(JSON);
41 41 void endOptionsCopyAttachmentsFromArray();
42 42 void beginOptionsCopyAttachmentsFrom(JSON);
43 43 void endOptionsCopyAttachmentsFrom();
44   -void setupOptionsCopyAttachmentsFromPath();
  44 +void setupOptionsCopyAttachmentsFromFile();
45 45 void setupOptionsCopyAttachmentsFromPassword();
46 46 void beginOptionsPagesArray(JSON);
47 47 void endOptionsPagesArray();
... ...
libqpdf/qpdf/auto_job_json_init.hh
... ... @@ -16,9 +16,9 @@ static char const* modify128_choices[] = {&quot;all&quot;, &quot;annotate&quot;, &quot;form&quot;, &quot;assembly&quot;,
16 16  
17 17 pushKey("input");
18 18 beginDict(bindJSON(&Handlers::beginInput), bindBare(&Handlers::endInput)); // .input
19   -pushKey("filename");
20   -setupInputFilename();
21   -popHandler(); // key: filename
  19 +pushKey("file");
  20 +setupInputFile();
  21 +popHandler(); // key: file
22 22 pushKey("password");
23 23 setupInputPassword();
24 24 popHandler(); // key: password
... ... @@ -31,9 +31,9 @@ popHandler(); // key: empty
31 31 popHandler(); // key: input
32 32 pushKey("output");
33 33 beginDict(bindJSON(&Handlers::beginOutput), bindBare(&Handlers::endOutput)); // .output
34   -pushKey("filename");
35   -setupOutputFilename();
36   -popHandler(); // key: filename
  34 +pushKey("file");
  35 +setupOutputFile();
  36 +popHandler(); // key: file
37 37 pushKey("replaceInput");
38 38 setupOutputReplaceInput();
39 39 popHandler(); // key: replaceInput
... ... @@ -311,9 +311,9 @@ popHandler(); // key: removeUnreferencedResources
311 311 pushKey("addAttachment");
312 312 beginArray(bindJSON(&Handlers::beginOptionsAddAttachmentArray), bindBare(&Handlers::endOptionsAddAttachmentArray)); // .options.addAttachment[]
313 313 beginDict(bindJSON(&Handlers::beginOptionsAddAttachment), bindBare(&Handlers::endOptionsAddAttachment)); // .options.addAttachment
314   -pushKey("path");
315   -setupOptionsAddAttachmentPath();
316   -popHandler(); // key: path
  314 +pushKey("file");
  315 +setupOptionsAddAttachmentFile();
  316 +popHandler(); // key: file
317 317 pushKey("creationdate");
318 318 addParameter([this](char const* p) { c_att->creationdate(p); });
319 319 popHandler(); // key: creationdate
... ... @@ -343,9 +343,9 @@ popHandler(); // key: removeAttachment
343 343 pushKey("copyAttachmentsFrom");
344 344 beginArray(bindJSON(&Handlers::beginOptionsCopyAttachmentsFromArray), bindBare(&Handlers::endOptionsCopyAttachmentsFromArray)); // .options.copyAttachmentsFrom[]
345 345 beginDict(bindJSON(&Handlers::beginOptionsCopyAttachmentsFrom), bindBare(&Handlers::endOptionsCopyAttachmentsFrom)); // .options.copyAttachmentsFrom
346   -pushKey("path");
347   -setupOptionsCopyAttachmentsFromPath();
348   -popHandler(); // key: path
  346 +pushKey("file");
  347 +setupOptionsCopyAttachmentsFromFile();
  348 +popHandler(); // key: file
349 349 pushKey("password");
350 350 setupOptionsCopyAttachmentsFromPassword();
351 351 popHandler(); // key: password
... ...
libqpdf/qpdf/auto_job_schema.hh
1 1 static constexpr char const* JOB_SCHEMA_DATA = R"({
2 2 "input": {
3   - "filename": "input filename",
  3 + "file": "input filename",
4 4 "password": "specify password",
5 5 "passwordFile": "read password from a file",
6 6 "empty": "empty input file"
7 7 },
8 8 "output": {
9   - "filename": "output filename",
  9 + "file": "output filename",
10 10 "replaceInput": "set to true to replace input",
11 11 "options": {
12 12 "qdf": "enable viewing PDF code in a text editor",
... ... @@ -110,7 +110,7 @@ static constexpr char const* JOB_SCHEMA_DATA = R&quot;({
110 110 "removeUnreferencedResources": "remove unreferenced page resources",
111 111 "addAttachment": [
112 112 {
113   - "path": "attachment to add",
  113 + "file": "attachment to add",
114 114 "creationdate": "set attachment's creation date",
115 115 "description": "set attachment's description",
116 116 "filename": "set attachment's displayed filename",
... ... @@ -123,7 +123,7 @@ static constexpr char const* JOB_SCHEMA_DATA = R&quot;({
123 123 "removeAttachment": "remove an embedded file",
124 124 "copyAttachmentsFrom": [
125 125 {
126   - "path": "attachment source filename",
  126 + "file": "attachment source filename",
127 127 "password": "specify password",
128 128 "prefix": "key prefix for copying attachments"
129 129 }
... ...
qpdf/qtest/qpdf.test
... ... @@ -668,7 +668,7 @@ $td-&gt;runtest(&quot;add attachment: bad mod date&quot;,
668 668 $td->runtest("add attachment: trailing slash",
669 669 {$td->COMMAND => "qpdf minimal.pdf a.pdf" .
670 670 " --add-attachment --"},
671   - {$td->REGEXP => ".*add attachment: no path specified.*",
  671 + {$td->REGEXP => ".*add attachment: no file specified.*",
672 672 $td->EXIT_STATUS => 2},
673 673 $td->NORMALIZE_NEWLINES);
674 674  
... ...