2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-05-31 17:30:54 +00:00

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.
This commit is contained in:
Jay Berkenbilt 2022-01-31 13:07:19 -05:00
parent 1a3ed1ee85
commit caa00556cf
11 changed files with 72 additions and 68 deletions

View File

@ -495,7 +495,11 @@ class Main:
def build_schema(self, j, path, flag, expected, options_seen): def build_schema(self, j, path, flag, expected, options_seen):
if flag in expected: if flag in expected:
options_seen.add(flag) options_seen.add(flag)
elif not (flag == '' or flag.startswith('_') or isinstance(j, str)): elif isinstance(j, str):
if not flag.startswith('_'):
raise Exception(f'json: {flag} has a description'
' but doesn\'t start with _')
elif not (flag == '' or flag.startswith('_')):
raise Exception(f'json: unknown key {flag}') raise Exception(f'json: unknown key {flag}')
if isinstance(j, dict): if isinstance(j, dict):

View File

@ -190,7 +190,7 @@ class QPDFJob
QPDF_DLL QPDF_DLL
Config* endAddAttachment(); Config* endAddAttachment();
QPDF_DLL QPDF_DLL
AttConfig* path(char const* parameter); AttConfig* file(char const* parameter);
# include <qpdf/auto_job_c_att.hh> # include <qpdf/auto_job_c_att.hh>
@ -210,7 +210,7 @@ class QPDFJob
QPDF_DLL QPDF_DLL
Config* endCopyAttachmentsFrom(); Config* endCopyAttachmentsFrom();
QPDF_DLL QPDF_DLL
CopyAttConfig* path(char const* parameter); CopyAttConfig* file(char const* parameter);
# include <qpdf/auto_job_c_copy_att.hh> # include <qpdf/auto_job_c_copy_att.hh>
@ -251,7 +251,7 @@ class QPDFJob
QPDF_DLL QPDF_DLL
Config* endUnderlayOverlay(); Config* endUnderlayOverlay();
QPDF_DLL QPDF_DLL
UOConfig* path(char const* parameter); UOConfig* file(char const* parameter);
# include <qpdf/auto_job_c_uo.hh> # include <qpdf/auto_job_c_uo.hh>
@ -270,7 +270,7 @@ class QPDFJob
QPDF_DLL QPDF_DLL
Config* endEncrypt(); Config* endEncrypt();
QPDF_DLL QPDF_DLL
EncConfig* path(char const* parameter); EncConfig* file(char const* parameter);
# include <qpdf/auto_job_c_enc.hh> # include <qpdf/auto_job_c_enc.hh>

View File

@ -1,17 +1,17 @@
# Generated by generate_auto_job # Generated by generate_auto_job
generate_auto_job e28f3fb4938f6307bb4c23c084c239832dbee3bbaedf19a22fb19215312b30b0 generate_auto_job ef1b438aeebed7ca0afcbe4d1f9c54d3acf899aec8410ebc69cd15ec673dd158
include/qpdf/auto_job_c_att.hh 7ad43bb374c1370ef32ebdcdcb7b73a61d281f7f4e3f12755585872ab30fb60e include/qpdf/auto_job_c_att.hh 7ad43bb374c1370ef32ebdcdcb7b73a61d281f7f4e3f12755585872ab30fb60e
include/qpdf/auto_job_c_copy_att.hh 32275d03cdc69b703dd7e02ba0bbe15756e714e9ad185484773a6178dc09e1ee include/qpdf/auto_job_c_copy_att.hh 32275d03cdc69b703dd7e02ba0bbe15756e714e9ad185484773a6178dc09e1ee
include/qpdf/auto_job_c_enc.hh 72e138c7b96ed5aacdce78c1dec04b1c20d361faec4f8faf52f64c1d6be99265 include/qpdf/auto_job_c_enc.hh 72e138c7b96ed5aacdce78c1dec04b1c20d361faec4f8faf52f64c1d6be99265
include/qpdf/auto_job_c_main.hh 516adb23cc7e44e614e436880be870d0574e4ebbc706cd855a1360000eed31bb include/qpdf/auto_job_c_main.hh 516adb23cc7e44e614e436880be870d0574e4ebbc706cd855a1360000eed31bb
include/qpdf/auto_job_c_pages.hh 931840b329a36ca0e41401190e04537b47f2867671a6643bfd8da74014202671 include/qpdf/auto_job_c_pages.hh 931840b329a36ca0e41401190e04537b47f2867671a6643bfd8da74014202671
include/qpdf/auto_job_c_uo.hh 0585b7de459fa479d9e51a45fa92de0ff6dee748efc9ec1cedd0dde6cee1ad50 include/qpdf/auto_job_c_uo.hh 0585b7de459fa479d9e51a45fa92de0ff6dee748efc9ec1cedd0dde6cee1ad50
job.yml 2ccc58ef74b875524505d7f00561b2df27ec2000846a549ac21a1fdd2f74c096 job.yml fe299f5fe022bd79884b3c66a8134386d8bf5ad42c32bdef37fc7044e5f003b9
libqpdf/qpdf/auto_job_decl.hh 9f79396ec459f191be4c5fe34cf88c265cf47355a1a945fa39169d1c94cf04f6 libqpdf/qpdf/auto_job_decl.hh 9f79396ec459f191be4c5fe34cf88c265cf47355a1a945fa39169d1c94cf04f6
libqpdf/qpdf/auto_job_help.hh 23c79f1d2c02bda28f64aace17f69487205c797e7ae2234892cbbabab49d6d47 libqpdf/qpdf/auto_job_help.hh 23c79f1d2c02bda28f64aace17f69487205c797e7ae2234892cbbabab49d6d47
libqpdf/qpdf/auto_job_init.hh 8e9e31b6099a662497339b27f6e2d7f779f35011e88a834bee8811c33405a0fe libqpdf/qpdf/auto_job_init.hh 8e9e31b6099a662497339b27f6e2d7f779f35011e88a834bee8811c33405a0fe
libqpdf/qpdf/auto_job_json_decl.hh 4846055075dcb7365c56c02150e955979b522d14f4329ce7a8a302ccd1d7aa2a libqpdf/qpdf/auto_job_json_decl.hh 741a44106f7850b6cbc8af264b5b77bb605475c8d8dd8cd87011d5debbee6269
libqpdf/qpdf/auto_job_json_init.hh 8ccfcfe06339c69631da2167cd1a77844a3cc9031e4090998113ef70b96bcb70 libqpdf/qpdf/auto_job_json_init.hh 886dd8ed7ae7691eaa97a0e5b3f1445f4cccab88ed372f530a8524d198c8f1d9
libqpdf/qpdf/auto_job_schema.hh 27cadf4f0c99dd27c569ec6d870a51d2abb51c8daaad94a55c42b6e86cf7726a libqpdf/qpdf/auto_job_schema.hh a764050cc99f1cc95645fd1ea2f020c4b778957abc64fbc55c12eac3a369dc92
manual/_ext/qpdf.py e9ac9d6c70642a3d29281ee5ad92ae2422dee8be9306fb8a0bc9dba0ed5e28f3 manual/_ext/qpdf.py e9ac9d6c70642a3d29281ee5ad92ae2422dee8be9306fb8a0bc9dba0ed5e28f3
manual/cli.rst 79140e023faa0cb77afe0b1dc512dd120ee5617f4db82f842596e4f239f93882 manual/cli.rst 79140e023faa0cb77afe0b1dc512dd120ee5617f4db82f842596e4f239f93882

40
job.yml
View File

@ -249,23 +249,23 @@ no-json:
- is-encrypted - is-encrypted
json: json:
# The structure of this section defines what the json input to # The structure of this section defines what the json input to
# QPDFJob looks like. If a key starts with underscore or has a value # QPDFJob looks like. If a key starts with underscore, it does not
# that is a string, it does not map to a command-line argument. If # map to a command-line argument. If the value is a string, that is
# value is null, its properties and help come from other information # the help information. Otherwise, if the value is null, it has to
# known by generate_auto_job. Otherwise, it has to match a # match a command-line option, and its properties and help come from
# command-line option. This information is used to construct a # other information known by generate_auto_job. This information is
# "schema" (as in JSON.hh) for the json input to QPDFJob. The # used to construct a "schema" (as in JSON.hh) for the json input to
# leading underscore is removed. *NOTE*: all keys are converted to # QPDFJob. The leading underscore is removed. *NOTE*: all keys are
# camelCase for the schema and must be appear that way in the # converted to camelCase for the schema and must be appear that way
# user-supplied json. This makes it more convenient to populate JSON # in the user-supplied json. This makes it more convenient to
# objects in some languages. # populate JSON objects in some languages.
_input: _input:
_filename: "input filename" _file: "input filename"
main.password: main.password:
password-file: password-file:
empty: empty:
_output: _output:
_filename: "output filename" _file: "output filename"
_replace-input: "set to true to replace input" _replace-input: "set to true to replace input"
_options: _options:
qdf: qdf:
@ -291,8 +291,8 @@ json:
progress: progress:
split-pages: split-pages:
encrypt: encrypt:
user-password: "user password" _user-password: "user password"
owner-password: "owner password" _owner-password: "owner password"
_40bit: _40bit:
Enc40.annotate: Enc40.annotate:
Enc40.extract: Enc40.extract:
@ -359,7 +359,7 @@ json:
ii-min-bytes: ii-min-bytes:
remove-unreferenced-resources: remove-unreferenced-resources:
add-attachment: add-attachment:
- path: "attachment to add" - _file: "attachment to add"
creationdate: creationdate:
description: description:
filename: filename:
@ -369,7 +369,7 @@ json:
replace: replace:
remove-attachment: remove-attachment:
copy-attachments-from: copy-attachments-from:
- path: "attachment source filename" - _file: "attachment source filename"
CopyAtt.password: CopyAtt.password:
prefix: prefix:
collate: collate:
@ -382,19 +382,19 @@ json:
oi-min-width: oi-min-width:
optimize-images: optimize-images:
pages: pages:
- file: "source for for pages" - _file: "source for for pages"
Pages.password: Pages.password:
range: "page range" _range: "page range"
remove-page-labels: remove-page-labels:
rotate: rotate:
overlay: overlay:
file: "source file for overlay" _file: "source file for overlay"
UO.password: UO.password:
from: from:
repeat: repeat:
to: to:
underlay: underlay:
file: "source file for underlay" _file: "source file for underlay"
UO.password: UO.password:
from: from:
repeat: repeat:

View File

@ -426,7 +426,7 @@ ArgParser::argEnd256BitEncryption()
void void
ArgParser::argUOPositional(char* arg) ArgParser::argUOPositional(char* arg)
{ {
c_uo->path(arg); c_uo->file(arg);
} }
void void
@ -439,7 +439,7 @@ ArgParser::argEndUnderlayOverlay()
void void
ArgParser::argAttPositional(char* arg) ArgParser::argAttPositional(char* arg)
{ {
c_att->path(arg); c_att->file(arg);
} }
void void
@ -452,7 +452,7 @@ ArgParser::argEndAttachment()
void void
ArgParser::argCopyAttPositional(char* arg) ArgParser::argCopyAttPositional(char* arg)
{ {
c_copy_att->path(arg); c_copy_att->file(arg);
} }
void void

View File

@ -761,7 +761,7 @@ QPDFJob::CopyAttConfig::CopyAttConfig(Config* c) :
} }
QPDFJob::CopyAttConfig* QPDFJob::CopyAttConfig*
QPDFJob::CopyAttConfig::path(char const* parameter) QPDFJob::CopyAttConfig::file(char const* parameter)
{ {
this->caf.path = parameter; this->caf.path = parameter;
return this; return this;
@ -786,7 +786,7 @@ QPDFJob::CopyAttConfig::endCopyAttachmentsFrom()
{ {
if (this->caf.path.empty()) if (this->caf.path.empty())
{ {
usage("copy attachments: no path specified"); usage("copy attachments: no file specified");
} }
this->config->o.m->attachments_to_copy.push_back(this->caf); this->config->o.m->attachments_to_copy.push_back(this->caf);
return this->config; return this->config;
@ -804,7 +804,7 @@ QPDFJob::Config::addAttachment()
} }
QPDFJob::AttConfig* QPDFJob::AttConfig*
QPDFJob::AttConfig::path(char const* parameter) QPDFJob::AttConfig::file(char const* parameter)
{ {
this->att.path = parameter; this->att.path = parameter;
return this; return this;
@ -878,12 +878,12 @@ QPDFJob::AttConfig::endAddAttachment()
QUtil::get_current_qpdf_time()); QUtil::get_current_qpdf_time());
if (this->att.path.empty()) if (this->att.path.empty())
{ {
usage("add attachment: no path specified"); usage("add attachment: no file specified");
} }
std::string last_element = QUtil::path_basename(this->att.path); std::string last_element = QUtil::path_basename(this->att.path);
if (last_element.empty()) if (last_element.empty())
{ {
usage("path for --add-attachment may not be empty"); usage("file for --add-attachment may not be empty");
} }
if (this->att.filename.empty()) if (this->att.filename.empty())
{ {
@ -972,7 +972,7 @@ QPDFJob::UOConfig::endUnderlayOverlay()
} }
QPDFJob::UOConfig* QPDFJob::UOConfig*
QPDFJob::UOConfig::path(char const* parameter) QPDFJob::UOConfig::file(char const* parameter)
{ {
if (! config->o.m->under_overlay->filename.empty()) if (! config->o.m->under_overlay->filename.empty())
{ {

View File

@ -228,7 +228,7 @@ Handlers::endInput()
} }
void void
Handlers::setupInputFilename() Handlers::setupInputFile()
{ {
addParameter([this](char const* p) { addParameter([this](char const* p) {
c_main->inputFile(p); c_main->inputFile(p);
@ -264,7 +264,7 @@ Handlers::endOutput()
} }
void void
Handlers::setupOutputFilename() Handlers::setupOutputFile()
{ {
addParameter([this](char const* p) { addParameter([this](char const* p) {
c_main->outputFile(p); c_main->outputFile(p);
@ -465,10 +465,10 @@ Handlers::endOptionsAddAttachment()
} }
void void
Handlers::setupOptionsAddAttachmentPath() Handlers::setupOptionsAddAttachmentFile()
{ {
addParameter([this](char const* p) { addParameter([this](char const* p) {
c_att->path(p); c_att->file(p);
}); });
} }
@ -498,10 +498,10 @@ Handlers::endOptionsCopyAttachmentsFrom()
} }
void void
Handlers::setupOptionsCopyAttachmentsFromPath() Handlers::setupOptionsCopyAttachmentsFromFile()
{ {
addParameter([this](char const* p) { addParameter([this](char const* p) {
c_copy_att->path(p); c_copy_att->file(p);
}); });
} }
@ -600,7 +600,7 @@ void
Handlers::setupOptionsOverlayFile() Handlers::setupOptionsOverlayFile()
{ {
addParameter([this](char const* p) { addParameter([this](char const* p) {
c_uo->path(p); c_uo->file(p);
}); });
} }
@ -629,7 +629,7 @@ void
Handlers::setupOptionsUnderlayFile() Handlers::setupOptionsUnderlayFile()
{ {
addParameter([this](char const* p) { addParameter([this](char const* p) {
c_uo->path(p); c_uo->file(p);
}); });
} }

View File

@ -5,12 +5,12 @@
// //
void beginInput(JSON); void beginInput(JSON);
void endInput(); void endInput();
void setupInputFilename(); void setupInputFile();
void setupInputPassword(); void setupInputPassword();
void setupInputEmpty(); void setupInputEmpty();
void beginOutput(JSON); void beginOutput(JSON);
void endOutput(); void endOutput();
void setupOutputFilename(); void setupOutputFile();
void setupOutputReplaceInput(); void setupOutputReplaceInput();
void beginOutputOptions(JSON); void beginOutputOptions(JSON);
void endOutputOptions(); void endOutputOptions();
@ -36,12 +36,12 @@ void beginOptionsAddAttachmentArray(JSON);
void endOptionsAddAttachmentArray(); void endOptionsAddAttachmentArray();
void beginOptionsAddAttachment(JSON); void beginOptionsAddAttachment(JSON);
void endOptionsAddAttachment(); void endOptionsAddAttachment();
void setupOptionsAddAttachmentPath(); void setupOptionsAddAttachmentFile();
void beginOptionsCopyAttachmentsFromArray(JSON); void beginOptionsCopyAttachmentsFromArray(JSON);
void endOptionsCopyAttachmentsFromArray(); void endOptionsCopyAttachmentsFromArray();
void beginOptionsCopyAttachmentsFrom(JSON); void beginOptionsCopyAttachmentsFrom(JSON);
void endOptionsCopyAttachmentsFrom(); void endOptionsCopyAttachmentsFrom();
void setupOptionsCopyAttachmentsFromPath(); void setupOptionsCopyAttachmentsFromFile();
void setupOptionsCopyAttachmentsFromPassword(); void setupOptionsCopyAttachmentsFromPassword();
void beginOptionsPagesArray(JSON); void beginOptionsPagesArray(JSON);
void endOptionsPagesArray(); void endOptionsPagesArray();

View File

@ -16,9 +16,9 @@ static char const* modify128_choices[] = {"all", "annotate", "form", "assembly",
pushKey("input"); pushKey("input");
beginDict(bindJSON(&Handlers::beginInput), bindBare(&Handlers::endInput)); // .input beginDict(bindJSON(&Handlers::beginInput), bindBare(&Handlers::endInput)); // .input
pushKey("filename"); pushKey("file");
setupInputFilename(); setupInputFile();
popHandler(); // key: filename popHandler(); // key: file
pushKey("password"); pushKey("password");
setupInputPassword(); setupInputPassword();
popHandler(); // key: password popHandler(); // key: password
@ -31,9 +31,9 @@ popHandler(); // key: empty
popHandler(); // key: input popHandler(); // key: input
pushKey("output"); pushKey("output");
beginDict(bindJSON(&Handlers::beginOutput), bindBare(&Handlers::endOutput)); // .output beginDict(bindJSON(&Handlers::beginOutput), bindBare(&Handlers::endOutput)); // .output
pushKey("filename"); pushKey("file");
setupOutputFilename(); setupOutputFile();
popHandler(); // key: filename popHandler(); // key: file
pushKey("replaceInput"); pushKey("replaceInput");
setupOutputReplaceInput(); setupOutputReplaceInput();
popHandler(); // key: replaceInput popHandler(); // key: replaceInput
@ -311,9 +311,9 @@ popHandler(); // key: removeUnreferencedResources
pushKey("addAttachment"); pushKey("addAttachment");
beginArray(bindJSON(&Handlers::beginOptionsAddAttachmentArray), bindBare(&Handlers::endOptionsAddAttachmentArray)); // .options.addAttachment[] beginArray(bindJSON(&Handlers::beginOptionsAddAttachmentArray), bindBare(&Handlers::endOptionsAddAttachmentArray)); // .options.addAttachment[]
beginDict(bindJSON(&Handlers::beginOptionsAddAttachment), bindBare(&Handlers::endOptionsAddAttachment)); // .options.addAttachment beginDict(bindJSON(&Handlers::beginOptionsAddAttachment), bindBare(&Handlers::endOptionsAddAttachment)); // .options.addAttachment
pushKey("path"); pushKey("file");
setupOptionsAddAttachmentPath(); setupOptionsAddAttachmentFile();
popHandler(); // key: path popHandler(); // key: file
pushKey("creationdate"); pushKey("creationdate");
addParameter([this](char const* p) { c_att->creationdate(p); }); addParameter([this](char const* p) { c_att->creationdate(p); });
popHandler(); // key: creationdate popHandler(); // key: creationdate
@ -343,9 +343,9 @@ popHandler(); // key: removeAttachment
pushKey("copyAttachmentsFrom"); pushKey("copyAttachmentsFrom");
beginArray(bindJSON(&Handlers::beginOptionsCopyAttachmentsFromArray), bindBare(&Handlers::endOptionsCopyAttachmentsFromArray)); // .options.copyAttachmentsFrom[] beginArray(bindJSON(&Handlers::beginOptionsCopyAttachmentsFromArray), bindBare(&Handlers::endOptionsCopyAttachmentsFromArray)); // .options.copyAttachmentsFrom[]
beginDict(bindJSON(&Handlers::beginOptionsCopyAttachmentsFrom), bindBare(&Handlers::endOptionsCopyAttachmentsFrom)); // .options.copyAttachmentsFrom beginDict(bindJSON(&Handlers::beginOptionsCopyAttachmentsFrom), bindBare(&Handlers::endOptionsCopyAttachmentsFrom)); // .options.copyAttachmentsFrom
pushKey("path"); pushKey("file");
setupOptionsCopyAttachmentsFromPath(); setupOptionsCopyAttachmentsFromFile();
popHandler(); // key: path popHandler(); // key: file
pushKey("password"); pushKey("password");
setupOptionsCopyAttachmentsFromPassword(); setupOptionsCopyAttachmentsFromPassword();
popHandler(); // key: password popHandler(); // key: password

View File

@ -1,12 +1,12 @@
static constexpr char const* JOB_SCHEMA_DATA = R"({ static constexpr char const* JOB_SCHEMA_DATA = R"({
"input": { "input": {
"filename": "input filename", "file": "input filename",
"password": "specify password", "password": "specify password",
"passwordFile": "read password from a file", "passwordFile": "read password from a file",
"empty": "empty input file" "empty": "empty input file"
}, },
"output": { "output": {
"filename": "output filename", "file": "output filename",
"replaceInput": "set to true to replace input", "replaceInput": "set to true to replace input",
"options": { "options": {
"qdf": "enable viewing PDF code in a text editor", "qdf": "enable viewing PDF code in a text editor",
@ -110,7 +110,7 @@ static constexpr char const* JOB_SCHEMA_DATA = R"({
"removeUnreferencedResources": "remove unreferenced page resources", "removeUnreferencedResources": "remove unreferenced page resources",
"addAttachment": [ "addAttachment": [
{ {
"path": "attachment to add", "file": "attachment to add",
"creationdate": "set attachment's creation date", "creationdate": "set attachment's creation date",
"description": "set attachment's description", "description": "set attachment's description",
"filename": "set attachment's displayed filename", "filename": "set attachment's displayed filename",
@ -123,7 +123,7 @@ static constexpr char const* JOB_SCHEMA_DATA = R"({
"removeAttachment": "remove an embedded file", "removeAttachment": "remove an embedded file",
"copyAttachmentsFrom": [ "copyAttachmentsFrom": [
{ {
"path": "attachment source filename", "file": "attachment source filename",
"password": "specify password", "password": "specify password",
"prefix": "key prefix for copying attachments" "prefix": "key prefix for copying attachments"
} }

View File

@ -668,7 +668,7 @@ $td->runtest("add attachment: bad mod date",
$td->runtest("add attachment: trailing slash", $td->runtest("add attachment: trailing slash",
{$td->COMMAND => "qpdf minimal.pdf a.pdf" . {$td->COMMAND => "qpdf minimal.pdf a.pdf" .
" --add-attachment --"}, " --add-attachment --"},
{$td->REGEXP => ".*add attachment: no path specified.*", {$td->REGEXP => ".*add attachment: no file specified.*",
$td->EXIT_STATUS => 2}, $td->EXIT_STATUS => 2},
$td->NORMALIZE_NEWLINES); $td->NORMALIZE_NEWLINES);