Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Co-authored-by: Balduin Landolt <33053745+BalduinLandolt@users.noreply.github.com>
- Loading branch information
1 parent
914acd8
commit 4acf841
Showing
16 changed files
with
398 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
66 changes: 66 additions & 0 deletions
66
src/dsp_tools/commands/resume_xmlupload/resume_xmlupload.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import pickle | ||
|
||
from dsp_tools.commands.xmlupload.iri_resolver import IriResolver | ||
from dsp_tools.commands.xmlupload.list_client import ListClient | ||
from dsp_tools.commands.xmlupload.list_client import ListClientLive | ||
from dsp_tools.commands.xmlupload.models.sipi import Sipi | ||
from dsp_tools.commands.xmlupload.models.upload_state import UploadState | ||
from dsp_tools.commands.xmlupload.project_client import ProjectClient | ||
from dsp_tools.commands.xmlupload.project_client import ProjectClientLive | ||
from dsp_tools.commands.xmlupload.upload_config import UploadConfig | ||
from dsp_tools.commands.xmlupload.xmlupload import cleanup_upload | ||
from dsp_tools.commands.xmlupload.xmlupload import upload_resources | ||
from dsp_tools.utils.connection_live import ConnectionLive | ||
|
||
|
||
def resume_xmlupload( | ||
server: str, | ||
user: str, | ||
password: str, | ||
sipi: str, | ||
) -> bool: | ||
""" | ||
Resume an interrupted xmlupload. | ||
Args: | ||
server: the DSP server where the data should be imported | ||
user: the user (e-mail) with which the data should be imported | ||
password: the password of the user with which the data should be imported | ||
sipi: the sipi instance to be used | ||
Returns: | ||
True if all resources could be uploaded without errors; False if one of the resources could not be | ||
uploaded because there is an error in it | ||
""" | ||
upload_state = _read_upload_state_from_disk(server) | ||
|
||
con = ConnectionLive(server) | ||
con.login(user, password) | ||
sipi_con = ConnectionLive(sipi, token=con.get_token()) | ||
sipi_server = Sipi(sipi_con) | ||
|
||
project_client: ProjectClient = ProjectClientLive(con, upload_state.config.shortcode) | ||
list_client: ListClient = ListClientLive(con, project_client.get_project_iri()) | ||
|
||
iri_resolver, failed_uploads, nonapplied_stash = upload_resources( | ||
resources=upload_state.pending_resources, | ||
failed_uploads=upload_state.failed_uploads, | ||
imgdir=".", | ||
sipi_server=sipi_server, | ||
permissions_lookup=upload_state.permissions_lookup, | ||
con=con, | ||
stash=upload_state.pending_stash, | ||
config=upload_state.config, | ||
project_client=project_client, | ||
list_client=list_client, | ||
iri_resolver=IriResolver(upload_state.iri_resolver_lookup), | ||
) | ||
|
||
return cleanup_upload(iri_resolver, upload_state.config, failed_uploads, nonapplied_stash) | ||
|
||
|
||
def _read_upload_state_from_disk(server: str) -> UploadState: | ||
save_location = UploadConfig().with_server_info(server, "foo").diagnostics.save_location | ||
with open(save_location, "rb") as f: | ||
saved_state: UploadState = pickle.load(f) # noqa: S301 (deserialization of untrusted data) | ||
return saved_state |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from dataclasses import dataclass | ||
|
||
from dsp_tools.commands.xmlupload.models.permission import Permissions | ||
from dsp_tools.commands.xmlupload.models.xmlresource import XMLResource | ||
from dsp_tools.commands.xmlupload.stash.stash_models import Stash | ||
from dsp_tools.commands.xmlupload.upload_config import UploadConfig | ||
|
||
|
||
@dataclass(frozen=True) | ||
class UploadState: | ||
""" | ||
Save the state of an xmlupload, so that after an interruption, it can be resumed. | ||
""" | ||
|
||
pending_resources: list[XMLResource] | ||
failed_uploads: list[str] | ||
iri_resolver_lookup: dict[str, str] | ||
pending_stash: Stash | None | ||
config: UploadConfig | ||
permissions_lookup: dict[str, Permissions] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.