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

Return 0 on help message #15

Merged
merged 1 commit into from
Feb 11, 2020
Merged
Show file tree
Hide file tree
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
39 changes: 23 additions & 16 deletions convert2rhel/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,28 +92,25 @@ def main():
# restart system if required
utils.restart_system()

except:
traceback_str = utils.get_traceback_str()
if toolopts.tool_opts.debug:
# Print the traceback to the user when debug option used
loggerinst.debug(traceback_str)
else:
# Print the traceback to the log file in any way
loggerinst.file(traceback_str)
except (Exception, SystemExit, KeyboardInterrupt), err:
# Catching the three exception types separately due to python 2.4
# (RHEL 5) - 2.7 (RHEL 7) compatibility.

utils.log_traceback(toolopts.tool_opts.debug)

print("\n")
if process_phase == ConversionPhase.POST_CLI:
if is_help_msg_exit(process_phase, err):
return 0
elif process_phase in (ConversionPhase.INIT, ConversionPhase.POST_CLI):
print("No changes were made to the system.")
elif process_phase == ConversionPhase.PRE_PONR_CHANGES:
rollback_changes()
elif process_phase == ConversionPhase.POST_PONR_CHANGES:
"""
After the process of subscription is done and the mass update of
packages is started convert2rhel will not be able to guarantee a
system rollback without user intervation. If a proper rollback
solution is necessary it will need to be future implemented here
or with the use of other backup tools.
"""
# After the process of subscription is done and the mass update of
# packages is started convert2rhel will not be able to guarantee a
# system rollback without user intervation. If a proper rollback
# solution is necessary it will need to be future implemented here
# or with the use of other backup tools.
print("Conversion process interrupted and manual user intervation"
" will be necessary.")

Expand Down Expand Up @@ -194,6 +191,16 @@ def post_ponr_conversion():
return


def is_help_msg_exit(process_phase, err):
"""After printing the help message, optparse within the toolopts.CLI()
call terminates the process with sys.exit(0).
"""
if process_phase == ConversionPhase.INIT and \
isinstance(err, SystemExit) and err.args[0] == 0:
return True
return False


def rollback_changes():
"""Perform a rollback of changes made during conversion."""
loggerinst = logging.getLogger(__name__)
Expand Down
14 changes: 14 additions & 0 deletions convert2rhel/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,20 @@ def prompt_user(question, password=False):
return response


def log_traceback(debug):
"""Log a traceback either to both a file and stdout, or just file, based
on the debug parameter.
"""
loggerinst = logging.getLogger(__name__)
traceback_str = get_traceback_str()
if debug:
# Print the traceback to the user when debug option used
loggerinst.debug(traceback_str)
else:
# Print the traceback to the log file in any way
loggerinst.file(traceback_str)


def get_traceback_str():
"""Get a traceback of an exception as a string."""
exc_type, exc_value, exc_traceback = sys.exc_info()
Expand Down