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
Conversation
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) |
There was a problem hiding this comment.
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 = {} |
There was a problem hiding this comment.
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
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this 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
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 = "." |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree
There was a problem hiding this comment.
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!
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) |
There was a problem hiding this comment.
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
There was a problem hiding this 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..?
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 = "." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree
Co-authored-by: irinaschubert <irina.schubert@dasch.swiss>
resolves DEV-1481