diff --git a/docs/cli-commands.md b/docs/cli-commands.md index e90287e63..480166cbd 100644 --- a/docs/cli-commands.md +++ b/docs/cli-commands.md @@ -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: @@ -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: diff --git a/src/dsp_tools/cli.py b/src/dsp_tools/cli.py index acd9eca56..4bb4656ee 100644 --- a/src/dsp_tools/cli.py +++ b/src/dsp_tools/cli.py @@ -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 @@ -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 @@ -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: @@ -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, ) diff --git a/src/dsp_tools/utils/project_get.py b/src/dsp_tools/utils/project_get.py index 056e4d1a4..92e3a1218 100644 --- a/src/dsp_tools/utils/project_get.py +++ b/src/dsp_tools/utils/project_get.py @@ -19,17 +19,19 @@ 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 @@ -37,7 +39,7 @@ def get_project( 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) @@ -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( diff --git a/src/dsp_tools/utils/xml_upload.py b/src/dsp_tools/utils/xml_upload.py index d2d251dfb..e2363cf91 100644 --- a/src/dsp_tools/utils/xml_upload.py +++ b/src/dsp_tools/utils/xml_upload.py @@ -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: @@ -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 @@ -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