Skip to content

Commit 65aa0a0

Browse files
authored
Merge pull request #1258 from liangxin1300/20231007_crm_history_tarball_crmsh45
[crmsh-4.5] Fix: report: Pick up tarball suffix dynamically (bsc#1215438)
2 parents 7e00632 + 9107110 commit 65aa0a0

File tree

2 files changed

+25
-17
lines changed

2 files changed

+25
-17
lines changed

crmsh/history.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from . import logparser
1616
from . import utils
1717
from . import log
18+
from crmsh.report import utillib
1819

1920

2021
logger = log.setup_logger(__name__)
@@ -106,7 +107,11 @@ def mkarchive(idir):
106107
if not home:
107108
logger.error("no home directory, nowhere to pack report")
108109
return False
109-
archive = '%s.tar.bz2' % os.path.join(home, os.path.basename(idir))
110+
_, ext = utillib.pick_first_compress()
111+
if not ext:
112+
return False
113+
name = os.path.join(home, os.path.basename(idir))
114+
archive = f'{name}.tar{ext}'
110115
cmd = "tar -C '%s/..' -cj -f '%s' %s" % \
111116
(idir, archive, os.path.basename(idir))
112117
if utils.pipe_cmd_nosudo(cmd) != 0:
@@ -464,7 +469,10 @@ def new_live_report(self):
464469
if not utils.is_path_sane(d):
465470
return None
466471
utils.rmdir_r(d)
467-
tarball = "%s.tar.bz2" % d
472+
_, ext = utillib.pick_first_compress()
473+
if not ext:
474+
return None
475+
tarball = f"{d}.tar{ext}"
468476
to_option = ""
469477
if self.to_dt:
470478
to_option = "-t '%s'" % logtime.human_date(self.to_dt)

crmsh/report/utillib.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,25 +1126,25 @@ def pe_to_dot(pe_file):
11261126

11271127

11281128
def pick_compress():
1129-
constants.COMPRESS_PROG = pick_first(["gzip", "bzip2", "xz"])
1130-
if constants.COMPRESS_PROG:
1131-
if constants.COMPRESS_PROG == "xz":
1132-
constants.COMPRESS_EXT = ".xz"
1133-
elif constants.COMPRESS_PROG == "bzip2":
1134-
constants.COMPRESS_EXT = ".bz2"
1135-
else:
1136-
constants.COMPRESS_EXT = ".gz"
1129+
prog, ext = pick_first_compress()
1130+
if prog:
1131+
constants.COMPRESS_PROG, constants.COMPRESS_EXT = prog, ext
11371132
else:
1138-
logger.warning("could not find a compression program; \
1139-
the resulting tarball may be huge")
1133+
logger.warning("the resulting tarball may be huge")
11401134
constants.COMPRESS_PROG = "cat"
11411135

11421136

1143-
def pick_first(choice):
1144-
for tmp in choice:
1145-
if crmutils.is_program(tmp):
1146-
return tmp
1147-
return None
1137+
def pick_first_compress():
1138+
compress_prog_suffix_dict = {
1139+
"gzip": ".gz",
1140+
"bzip2": ".bz2",
1141+
"xz": ".xz"
1142+
}
1143+
for cmd, suffix in compress_prog_suffix_dict.items():
1144+
if shutil.which(cmd):
1145+
return cmd, suffix
1146+
logger.warning("Could not find a compression program")
1147+
return None, None
11481148

11491149

11501150
def pkg_ver_deb(packages):

0 commit comments

Comments
 (0)