Skip to content

Commit

Permalink
feat: add --dump flag to "xmlupload" and "get" commands (DEV-2534) (#502
Browse files Browse the repository at this point in the history
)
  • Loading branch information
jnussbaum committed Sep 1, 2023
1 parent a9caf98 commit d9aeba9
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
2 changes: 2 additions & 0 deletions docs/cli-commands.md
Expand Up @@ -101,6 +101,7 @@ The following options are available:
- `-p` | `--password` (optional, default: `test`): password used for authentication with the DSP-API
- `-P` | `--project` (mandatory): shortcode, shortname or IRI of the project
- `-v` | `--verbose` (optional): print more information about the progress to the console
- `-d` | `--dump` (optional): write every request to DSP-API into a file

The defaults are intended for local testing:

Expand Down Expand Up @@ -138,6 +139,7 @@ The following options are available:
- `-V` | `--validate` (optional): validate the XML file without uploading it
- `-v` | `--verbose` (optional): print more information about the progress to the console
- `-m` | `--metrics` (optional): write metrics into a 'metrics' folder
- `-d` | `--dump` (optional): write every request to DSP-API/SIPI into a file

Output:

Expand Down
6 changes: 6 additions & 0 deletions src/dsp_tools/cli.py
Expand Up @@ -99,6 +99,7 @@ def _make_parser(
parser_get.add_argument("-p", "--password", default=root_user_pw, help=password_text)
parser_get.add_argument("-P", "--project", help="shortcode, shortname or IRI of the project", required=True)
parser_get.add_argument("-v", "--verbose", action="store_true", help=verbose_text)
parser_get.add_argument("-d", "--dump", action="store_true", help="write every request to DSP-API into a file")
parser_get.add_argument("project_definition", help="path to the file the project should be written to")

# xmlupload
Expand All @@ -117,6 +118,9 @@ def _make_parser(
)
parser_upload.add_argument("-v", "--verbose", action="store_true", help=verbose_text)
parser_upload.add_argument("-m", "--metrics", action="store_true", help="write metrics into a 'metrics' folder")
parser_upload.add_argument(
"-d", "--dump", action="store_true", help="write every request to DSP-API/SIPI into a file"
)
parser_upload.add_argument("xmlfile", help="path to the XML file containing the data")

# process-files
Expand Down Expand Up @@ -447,6 +451,7 @@ def _call_requested_action(args: argparse.Namespace) -> bool:
user=args.user,
password=args.password,
verbose=args.verbose,
dump=args.dump,
)
elif args.action == "xmlupload":
if args.validate_only:
Expand All @@ -460,6 +465,7 @@ def _call_requested_action(args: argparse.Namespace) -> bool:
imgdir=args.imgdir,
sipi=args.sipi_url,
verbose=args.verbose,
dump=args.dump,
save_metrics=args.metrics,
preprocessing_done=False,
)
Expand Down
21 changes: 13 additions & 8 deletions src/dsp_tools/utils/project_get.py
Expand Up @@ -19,25 +19,27 @@ def get_project(
user: str,
password: str,
verbose: bool = False,
dump: bool = False,
) -> bool:
"""
This function writes a project from a DSP server into a JSON file.
Args:
project_identifier : the project identifier, either shortcode, shortname or IRI of the project
outfile_path : the output file the JSON content should be written to
server : the DSP server where the data should be read from
user : the user (e-mail) who sends the request
password : the password of the user who sends the request
verbose : verbose option for the command, if used more output is given to the user
project_identifier: the project identifier, either shortcode, shortname or IRI of the project
outfile_path: the output file the JSON content should be written to
server: the DSP server where the data should be read from
user: the user (e-mail) who sends the request
password: the password of the user who sends the request
verbose: verbose option for the command, if used more output is given to the user
dump: if True, write every request to DSP-API into a file
Raises:
BaseError: if something went wrong
Returns:
True if the process finishes without errors
"""
con = Connection(server)
con = Connection(server=server, dump=dump)
if user and password:
con.login(user, password)

Expand Down Expand Up @@ -72,7 +74,10 @@ def get_project(
if verbose:
print("Getting users...")
users_obj: list[dict[str, Any]] = []
users = User.getAllUsersForProject(con=con, proj_shortcode=str(project.shortcode))
try:
users = User.getAllUsersForProject(con=con, proj_shortcode=str(project.shortcode))
except BaseError:
users = None
if users:
for usr in users:
users_obj.append(
Expand Down
4 changes: 3 additions & 1 deletion src/dsp_tools/utils/xml_upload.py
Expand Up @@ -519,6 +519,7 @@ def xml_upload(
imgdir: str,
sipi: str,
verbose: bool = False,
dump: bool = False,
save_metrics: bool = False,
preprocessing_done: bool = False,
) -> bool:
Expand All @@ -533,6 +534,7 @@ def xml_upload(
imgdir: the image directory
sipi: the sipi instance to be used
verbose: verbose option for the command, if used more output is given to the user
dump: if true, dumps the XML file to the current working directory
save_metrics: if true, saves time measurements into a "metrics" folder in the current working directory
preprocessing_done: if set, all multimedia files referenced in the XML file must already be on the server
Expand Down Expand Up @@ -566,7 +568,7 @@ def xml_upload(
preparation_start = datetime.now()

# establish connection to DSP server
con = login(server=server, user=user, password=password)
con = login(server=server, user=user, password=password, dump=dump)
sipi_server = Sipi(sipi, con.get_token())

# get the project context
Expand Down

0 comments on commit d9aeba9

Please sign in to comment.