Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 43 additions & 38 deletions sos/upload/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,45 +278,50 @@ def pre_work(self):
self.policy._configure_low_priority()

def execute(self):
self.pre_work()
if self.from_cmdline:
self.intro()
self.archive = self.opts.upload_file
self.caseid = self.policy.prompt_for_case_id(
cmdline_opts=self.opts
)
cmdline_target = self.opts.upload_target
if cmdline_target and cmdline_target != 'local':
self.upload_target = self.upload_targets[cmdline_target]
else:
self.determine_upload_target()
if not self.upload_target:
# There was no upload target set, so we'll throw
# an error here and exit
self.ui_log.error(
"No upload target set via command line options or"
" autodetected.\n"
"Please specify one using the option --upload-target.\n"
"Exiting."
)
sys.exit(1)
self.upload_target.pre_work(self.get_commons())
try:
if os.stat(self.archive).st_size > 0:
if os.path.isfile(self.archive):
try:
self.upload_target.upload_archive(self.archive)
self.ui_log.info(
_(f"File {self.archive} uploaded successfully")
)
except Exception as err:
self.ui_log.error(_(f"Upload attempt failed: {err}"))
sys.exit(1)
else:
self.ui_log.error(_(f"{self.archive} is not a file."))
self.pre_work()
if self.from_cmdline:
self.intro()
self.archive = self.opts.upload_file
self.caseid = self.policy.prompt_for_case_id(
cmdline_opts=self.opts
)
cmdline_target = self.opts.upload_target
if cmdline_target and cmdline_target != 'local':
self.upload_target = self.upload_targets[cmdline_target]
else:
self.ui_log.error(_(f"File {self.archive} is empty."))
except Exception as e:
self.ui_log.error(_(f"Cannot upload {self.archive}: {e} "))
self.determine_upload_target()
if not self.upload_target:
# There was no upload target set, so we'll throw
# an error here and exit
self.ui_log.error(
"No upload target set via command line options or"
" autodetected.\n"
"Please specify one using the option --upload-target.\n"
"Exiting."
)
sys.exit(1)
self.upload_target.pre_work(self.get_commons())
try:
if os.stat(self.archive).st_size > 0:
if os.path.isfile(self.archive):
try:
self.upload_target.upload_archive(self.archive)
self.ui_log.info(
_(f"File {self.archive} uploaded successfully")
)
except Exception as err:
self.ui_log.error(_(
f"Upload attempt failed: {err}"))
sys.exit(1)
else:
self.ui_log.error(_(f"{self.archive} is not a file."))
else:
self.ui_log.error(_(f"File {self.archive} is empty."))
except Exception as e:
self.ui_log.error(_(f"Cannot upload {self.archive}: {e} "))
except KeyboardInterrupt:
self._exit("Exiting on user cancel", 130)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I was thinking about adding a general exception after KeyboardInterrupt to capture any other uncatched exceptions. Any thoughts on this?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Might as well, of there is a chance for another issue to happen?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I've tried to come up with possible ways to trigger other exceptions, but haven't found a way to get one yet. Rather, I thought I could add them generally after being explicit with the KeyboardInterrupt one, and if we capture one we can refine it later on (i.e. add a new explicit one before the general one).


# vim: set et ts=4 sw=4 :
Loading