Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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
34 changes: 26 additions & 8 deletions leapp/cli/upgrade/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ def archive_logfiles():
""" Archive log files from a previous run of Leapp """
cfg = get_config()

if not os.path.isdir(cfg.get('logs', 'dir')):
os.makedirs(cfg.get('logs', 'dir'))
if not os.path.isdir(cfg.get('files_to_archive', 'dir')):
os.makedirs(cfg.get('files_to_archive', 'dir'))

files_to_archive = [os.path.join(cfg.get('logs', 'dir'), f)
for f in cfg.get('logs', 'files').split(',')
if os.path.isfile(os.path.join(cfg.get('logs', 'dir'), f))]
files_to_archive = [os.path.join(cfg.get('files_to_archive', 'dir'), f)
for f in cfg.get('files_to_archive', 'files').split(',')
if os.path.isfile(os.path.join(cfg.get('files_to_archive', 'dir'), f))]

if not os.path.isdir(cfg.get('archive', 'dir')):
os.makedirs(cfg.get('archive', 'dir'))
Expand Down Expand Up @@ -118,6 +118,18 @@ def generate_report_files(context):
generate_report_file(messages, context, report_txt)


def get_cfg_files(section, cfg, must_exist=True):
"""
Provide files from particular config section
"""
files = []
for file_ in cfg.get(section, 'files').split(','):
file_path = os.path.join(cfg.get(section, 'dir'), file_)
if not must_exist or must_exist and os.path.isfile(file_path):
files.append(file_path)
return files


def warn_if_unsupported(configuration):
env = os.environ
if env.get('LEAPP_UNSUPPORTED', '0') == '1':
Expand Down Expand Up @@ -220,6 +232,12 @@ def upgrade(args):
report_errors(workflow.errors)
generate_report_files(context)

cfg = get_config()

report_files = get_cfg_files('report', cfg)
log_files = get_cfg_files('logs', cfg)
report_info(report_files, log_files, fail=workflow.failure)

if workflow.failure:
sys.exit(1)

Expand Down Expand Up @@ -261,9 +279,9 @@ def preupgrade(args):
workflow.save_answerfile(answerfile_path)
generate_report_files(context)
report_errors(workflow.errors)

report_files = [os.path.join(cfg.get('report', 'dir'), r) for r in cfg.get('report', 'files').split(',')]
report_info([rf for rf in report_files if os.path.isfile(rf)], fail=workflow.failure)
report_files = get_cfg_files('report', cfg)
log_files = get_cfg_files('logs', cfg)
report_info(report_files, log_files, fail=workflow.failure)
if workflow.failure:
sys.exit(1)

Expand Down
32 changes: 20 additions & 12 deletions leapp/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,24 @@


_LEAPP_CONFIG = None
# files that will go into the leapp-logs.tar.gz archive and get deleted each time a run is started
_FILES_TO_ARCHIVE = [
'dnf-plugin-data.txt',

# files that will get reported at the end of a preupgrade/upgrade run if they were created/modified during it
_REPORTS = [
'leapp-report.json',
'leapp-report.txt',
'leapp-preupgrade.log',
'leapp-upgrade.log',
]
# files that will get reported at the end of a preupgrade run if they were created/modified during it
_FILES_TO_REPORT = [
'leapp-report.json',
'leapp-report.txt',
'leapp-preupgrade.log',

# debug logs that will get reported at the end of a preupgrade/upgrade run if they were created/modified during it
_LOGS = [
'leapp-upgrade.log',
'leapp-preupgrade.log'
Copy link
Contributor

Choose a reason for hiding this comment

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

These two files could be sorted, although that's just a tiny nitpick.

]

# files that will go into the leapp-logs.tar.gz archive and get deleted each time a run is started
_FILES_TO_ARCHIVE = [
'dnf-plugin-data.txt',
] + _REPORTS + _LOGS

_CONFIG_DEFAULTS = {
'archive': {
'dir': '/var/log/leapp/archive/',
Expand All @@ -32,13 +36,17 @@
'debug': {
'dir': '/var/log/leapp/dnf-debugdata/',
},
'logs': {
'files_to_archive': {
'dir': '/var/log/leapp/',
'files': ','.join(_FILES_TO_ARCHIVE),
},
'logs': {
'dir': '/var/log/leapp/',
'files': ','.join(_LOGS),
},
'report': {
'dir': '/var/log/leapp/',
'files': ','.join(_FILES_TO_REPORT),
'files': ','.join(_REPORTS),
'answerfile': '/var/log/leapp/answerfile',
},
'repositories': {
Expand Down
16 changes: 12 additions & 4 deletions leapp/utils/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,22 @@ def report_errors(errors):
sys.stdout.write(pretty_block("END OF ERRORS", color=Color.red))


def report_info(path, fail=False):
paths = [path] if not isinstance(path, list) else path
if paths:
def report_info(report_paths, log_paths, fail=False):
report_paths = [report_paths] if not isinstance(report_paths, list) else report_paths
log_paths = [log_paths] if not isinstance(report_paths, list) else log_paths

if log_paths:
sys.stdout.write("\n")
for log_path in log_paths:
sys.stdout.write("Debug output written to {path}\n".format(path=log_path))

if report_paths:
sys.stdout.write(pretty_block("REPORT", color=Color.bold if fail else Color.green))
sys.stdout.write("\n")
for report_path in paths:
for report_path in report_paths:
sys.stdout.write("A report has been generated at {path}\n".format(path=report_path))
sys.stdout.write(pretty_block("END OF REPORT", color=Color.bold if fail else Color.green))
sys.stdout.write("\n")


def report_unsupported(devel_vars, experimental):
Expand Down