Skip to content

Commit

Permalink
feat!: remove --verbose flag from xmlupload (DEV-3389) (#869)
Browse files Browse the repository at this point in the history
  • Loading branch information
jnussbaum committed Mar 12, 2024
1 parent c8e8966 commit 1e2e170
Show file tree
Hide file tree
Showing 9 changed files with 6 additions and 30 deletions.
1 change: 0 additions & 1 deletion docs/cli-commands.md
Expand Up @@ -138,7 +138,6 @@ The following options are available:
- `-p` | `--password` (optional, default: `test`): password used for authentication with the DSP-API
- `-i` | `--imgdir` (optional, default: `.`): folder from where the paths in the `<bitstream>` tags are evaluated
- `-V` | `--validate` (optional): validate the XML file without uploading it
- `-v` | `--verbose` (optional): print more information about the progress to the console
- `--interrupt-after=int` (optional): interrupt the upload after `int` resources have been uploaded

Output:
Expand Down
6 changes: 1 addition & 5 deletions src/dsp_tools/cli/call_action.py
Expand Up @@ -18,7 +18,6 @@
from dsp_tools.commands.start_stack import StackConfiguration
from dsp_tools.commands.start_stack import StackHandler
from dsp_tools.commands.template import generate_template_repo
from dsp_tools.commands.xmlupload.upload_config import DiagnosticsConfig
from dsp_tools.commands.xmlupload.upload_config import UploadConfig
from dsp_tools.commands.xmlupload.xmlupload import xmlupload
from dsp_tools.utils.create_logger import get_logger
Expand Down Expand Up @@ -171,10 +170,7 @@ def _call_xmlupload(args: argparse.Namespace) -> bool:
password=args.password,
imgdir=args.imgdir,
sipi=args.sipi_url,
config=UploadConfig(
diagnostics=DiagnosticsConfig(verbose=args.verbose),
interrupt_after=interrupt_after,
),
config=UploadConfig(interrupt_after=interrupt_after),
)


Expand Down
1 change: 0 additions & 1 deletion src/dsp_tools/cli/create_parsers.py
Expand Up @@ -214,7 +214,6 @@ def _add_xmlupload(
subparser.add_argument(
"-V", "--validate-only", action="store_true", help="validate the XML file without uploading it"
)
subparser.add_argument("-v", "--verbose", action="store_true", help=verbose_text)
subparser.add_argument("--interrupt-after", type=int, default=-1, help="interrupt after this number of resources")
subparser.add_argument("xmlfile", help="path to the XML file containing the data")

Expand Down
Expand Up @@ -14,7 +14,6 @@


def upload_stashed_resptr_props(
verbose: bool,
iri_resolver: IriResolver,
con: Connection,
stashed_resptr_props: LinkValueStash,
Expand All @@ -24,7 +23,6 @@ def upload_stashed_resptr_props(
After all resources are uploaded, the stashed resptr props must be applied to their resources in DSP.
Args:
verbose: bool
iri_resolver: resolver with a mapping of ids from the XML file to IRIs in DSP
con: connection to DSP
stashed_resptr_props: all resptr props that have been stashed
Expand All @@ -44,8 +42,7 @@ def upload_stashed_resptr_props(
# no action necessary: this resource will remain in nonapplied_resptr_props,
# which will be handled by the caller
continue
if verbose:
print(f"{datetime.now()}: Upload resptrs of resource '{res_id}''...")
print(f"{datetime.now()}: Upload resptrs of resource '{res_id}''...")
logger.info(f" Upload resptrs of resource '{res_id}'...")
for stash_item in stash_items:
target_iri = iri_resolver.get(stash_item.target_id)
Expand Down
Expand Up @@ -95,7 +95,6 @@ def _create_XMLResource_json_object_to_update(


def upload_stashed_xml_texts(
verbose: bool,
iri_resolver: IriResolver,
con: Connection,
stashed_xml_texts: StandoffStash,
Expand All @@ -104,7 +103,6 @@ def upload_stashed_xml_texts(
After all resources are uploaded, the stashed xml texts must be applied to their resources in DSP.
Args:
verbose: bool
iri_resolver: resolver to map ids from the XML file to IRIs in DSP
con: connection to DSP
stashed_xml_texts: all xml texts that have been stashed
Expand All @@ -128,8 +126,7 @@ def upload_stashed_xml_texts(
except BaseError as err:
_log_unable_to_retrieve_resource(resource=res_id, received_error=err)
continue
if verbose:
print(f"{datetime.now()}: Upload XML text(s) of resource '{res_id}'...")
print(f"{datetime.now()}: Upload XML text(s) of resource '{res_id}'...")
logger.info(f" Upload XML text(s) of resource '{res_id}'...")
context = resource_in_triplestore["@context"]
for stash_item in stash_items:
Expand Down
1 change: 0 additions & 1 deletion src/dsp_tools/commands/xmlupload/upload_config.py
Expand Up @@ -38,7 +38,6 @@ def _transform_server_url_to_foldername(server: str) -> str:
class DiagnosticsConfig:
"""Configures all diagnostics for a given upload."""

verbose: bool = False
server_as_foldername: str = "unknown"
save_location: Path = field(default=Path.home() / ".dsp-tools" / "xmluploads")

Expand Down
12 changes: 2 additions & 10 deletions src/dsp_tools/commands/xmlupload/xmlupload.py
Expand Up @@ -102,7 +102,6 @@ def xmlupload(
root=root,
con=con,
default_ontology=default_ontology,
verbose=config.diagnostics.verbose,
)

project_client: ProjectClient = ProjectClientLive(con, config.shortcode)
Expand Down Expand Up @@ -169,11 +168,9 @@ def _prepare_upload(
root: etree._Element,
con: Connection,
default_ontology: str,
verbose: bool,
) -> tuple[list[XMLResource], dict[str, Permissions], Stash | None]:
logger.info("Checking resources for circular references...")
if verbose:
print(f"{datetime.now()}: Checking resources for circular references...")
print(f"{datetime.now()}: Checking resources for circular references...")
stash_lookup, upload_order = identify_circular_references(root)
logger.info("Get data from XML...")
resources, permissions_lookup = _get_data_from_xml(
Expand All @@ -184,8 +181,7 @@ def _prepare_upload(
sorting_lookup = {res.res_id: res for res in resources}
resources = [sorting_lookup[res_id] for res_id in upload_order]
logger.info("Stashing circular references...")
if verbose:
print(f"{datetime.now()}: Stashing circular references...")
print(f"{datetime.now()}: Stashing circular references...")
stash = stash_circular_references(resources, stash_lookup, permissions_lookup)
return resources, permissions_lookup, stash

Expand Down Expand Up @@ -257,7 +253,6 @@ def upload_resources(
stash=stash,
iri_resolver=iri_resolver,
con=con,
verbose=config.diagnostics.verbose,
project_client=project_client,
)
if stash
Expand Down Expand Up @@ -294,12 +289,10 @@ def _upload_stash(
stash: Stash,
iri_resolver: IriResolver,
con: Connection,
verbose: bool,
project_client: ProjectClient,
) -> Stash | None:
if stash.standoff_stash:
nonapplied_standoff = upload_stashed_xml_texts(
verbose=verbose,
iri_resolver=iri_resolver,
con=con,
stashed_xml_texts=stash.standoff_stash,
Expand All @@ -309,7 +302,6 @@ def _upload_stash(
context = get_json_ld_context_for_project(project_client.get_ontology_name_dict())
if stash.link_value_stash:
nonapplied_resptr_props = upload_stashed_resptr_props(
verbose=verbose,
iri_resolver=iri_resolver,
con=con,
stashed_resptr_props=stash.link_value_stash,
Expand Down
2 changes: 1 addition & 1 deletion test/distribution/test_cli.py
Expand Up @@ -66,7 +66,7 @@ def test_validate_project(self) -> None:

def test_xml_upload(self) -> None:
"""Test if the resource file 'src/dsp_tools/resources/schema/data.xsd' can be accessed."""
self._make_cli_call(["xmlupload", "-v", "--validate-only", str(self.test_data_minimal_file.absolute())])
self._make_cli_call(["xmlupload", "--validate-only", str(self.test_data_minimal_file.absolute())])

def _make_cli_call(self, args: list[str]) -> None:
"""
Expand Down
Expand Up @@ -91,7 +91,6 @@ def test_upload_link_value_stash(self) -> None:
stash=stash,
iri_resolver=iri_resolver,
con=con,
verbose=False,
project_client=ProjectClientStub(),
)
assert nonapplied is None
Expand Down Expand Up @@ -141,7 +140,6 @@ def test_upload_text_value_stash(self) -> None:
stash=stash,
iri_resolver=iri_resolver,
con=con,
verbose=False,
project_client=ProjectClientStub(),
)
assert nonapplied is None
Expand Down Expand Up @@ -188,7 +186,6 @@ def test_not_upload_text_value_stash_if_uuid_not_on_value(self) -> None:
stash=stash,
iri_resolver=iri_resolver,
con=con,
verbose=False,
project_client=ProjectClientStub(),
)
assert nonapplied == stash

0 comments on commit 1e2e170

Please sign in to comment.