Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(xmlupload): handling of upload errors (DEV-1505) #250

Merged
merged 11 commits into from Nov 22, 2022

Conversation

jnussbaum
Copy link
Collaborator

resolves DEV-1481

@jnussbaum jnussbaum self-assigned this Nov 4, 2022
if len(stashed_xml_texts) > 0:
try:
nonapplied_xml_texts = _upload_stashed_xml_texts(verbose, id2iri_mapping, con, stashed_xml_texts)
nonapplied_xml_texts = _purge_stashed_xml_texts(nonapplied_xml_texts, id2iri_mapping)
Copy link
Collaborator Author

@jnussbaum jnussbaum Nov 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is redundant, because _upload_stashed_xml_texts() already returns the xml texts in a purged form.


# update the resources with the stashed XML texts
nonapplied_xml_texts = {}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not necessary any more to create an empty nonapplied_xml_texts, because the case cannot happen any more that nonapplied_xml_texts is used before being instantiated

Comment on lines -377 to -382
if len(nonapplied_xml_texts) > 0:
_write_stashed_xml_texts(nonapplied_xml_texts, timestamp_str)
success = False
if len(nonapplied_resptr_props) > 0:
_write_stashed_resptr_props(nonapplied_resptr_props, timestamp_str)
success = False
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This case cannot happen any more. If one of them is > 0, this part of the code is not reached.

@jnussbaum jnussbaum changed the title feat: make it easier to resume an aborted xmlupload (DEV-1481) chore: preliminary refactorings to: make it easier to resume an aborted xmlupload (DEV-1505) Nov 17, 2022
Copy link
Collaborator

@BalduinLandolt BalduinLandolt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only cosmetics from my side. I generally like pathlib and would avoid writing paths as strings. But that is by no means pressing or important

Comment on lines +308 to +313
if sys.platform.startswith("darwin") or sys.platform.startswith("linux"):
save_location = f"{os.path.expanduser('~')}/.dsp-tools"
elif sys.platform.startswith("win"):
save_location = "."
else:
save_location = "."
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pathlib has a home directory that works OS independently. And generally I would not use any os.path code anymore, but use Pathlib instead

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, it's noted with a TODO comment. For the moment, reading through the docs of Pathlib would be too time consuming. I want to take the time to do the transition to Pathlib properly, in order to really understand (and use) its advantages.

In the current case, Pathlib wouldn't change anything, because I use the home directory only on Macs. On Windows, it' an entirely different story to obtain an app data storage location from the OS.

But thanks for gently pushing me into using good libraries, I appreciate this endeavour!

Comment on lines +786 to +790
if save_location == ".":
save_location_full = f"xmluploads/{server}/{proj_shortcode}/{onto_name}"
else:
save_location_full = f"{save_location}/xmluploads/{server}/{proj_shortcode}/{onto_name}"
os.makedirs(save_location_full, exist_ok=True)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again, a Path object would make this much nicer (plus, if you can eliminate the . case, this will get simpler

knora/dsplib/utils/xml_upload.py Outdated Show resolved Hide resolved
Copy link

@irinaschubert irinaschubert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, have you thought about restricting the file size of the log file? If the file gets too large, some editors can't open it anymore, so it is usually an important use case - but at this point maybe not relevant to us..?

knora/dsplib/utils/xml_upload.py Outdated Show resolved Hide resolved
knora/dsplib/utils/xml_upload.py Outdated Show resolved Hide resolved
knora/dsplib/utils/xml_upload.py Outdated Show resolved Hide resolved
knora/dsplib/utils/xml_upload.py Outdated Show resolved Hide resolved
Comment on lines +308 to +313
if sys.platform.startswith("darwin") or sys.platform.startswith("linux"):
save_location = f"{os.path.expanduser('~')}/.dsp-tools"
elif sys.platform.startswith("win"):
save_location = "."
else:
save_location = "."

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree

jnussbaum and others added 2 commits November 22, 2022 16:04
Co-authored-by: irinaschubert <irina.schubert@dasch.swiss>
@jnussbaum jnussbaum changed the title chore: preliminary refactorings to: make it easier to resume an aborted xmlupload (DEV-1505) refactor: handling of upload errors (DEV-1505) Nov 22, 2022
@jnussbaum jnussbaum changed the title refactor: handling of upload errors (DEV-1505) refactor(xmlupload): handling of upload errors (DEV-1505) Nov 22, 2022
@jnussbaum jnussbaum merged commit 1507b21 into main Nov 22, 2022
@jnussbaum jnussbaum deleted the wip/dev-1481-resume-aborted-xmlupload branch November 22, 2022 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants