Skip to content

Commit 2d1a4a2

Browse files
authored
Merge pull request #85 from vmezzela/verbose
Add verbose global option
2 parents 356a7c5 + 0d033a2 commit 2d1a4a2

File tree

5 files changed

+26
-15
lines changed

5 files changed

+26
-15
lines changed

klp-build.1

+3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ Generic options available for all commands:
2424
.B "-h, --help"
2525
Show command's help message and exit.
2626
.TP
27+
.B "-v, --verbose"
28+
Produce more verbose output.
29+
.TP
2730
.BI "-n, --name" " NAME"
2831
The livepatch name. This will be the directory name of the resulting
2932
livepatches.

klpbuild/klplib/cmd.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,16 @@ def add_arg_lp_filter(parentparser, mandatory=False):
3030

3131

3232
def create_parser() -> argparse.ArgumentParser:
33-
parentparser = argparse.ArgumentParser(add_help=False)
33+
parentparser = argparse.ArgumentParser(add_help=True)
3434
sub = parentparser.add_subparsers(dest="cmd")
3535

36+
parentparser.add_argument(
37+
"-v",
38+
"--verbose",
39+
action="store_true",
40+
help="Produce more verbose output"
41+
)
42+
3643
register_plugins_argparser(sub)
3744

3845
# NOTE: all the code below should be gone when all the module will be

klpbuild/klplib/config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def __load_user_conf():
152152
logging.warning("Warning: user configuration file not found")
153153
__setup_user_env(Path.home()/"klp")
154154

155-
logging.info("Loading user configuration from '%s'", user_conf_file)
155+
logging.debug("Loading user configuration from '%s'", user_conf_file)
156156
_config.read(user_conf_file)
157157

158158
# Check mandatory fields

klpbuild/klplib/ksrc.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def format_patches(self, lp_name, version):
8181

8282
# Filter only the branches related to this BSC
8383
for branch in utils.get_lp_branches(lp_name, kgr_patches):
84-
print(branch)
84+
logging.info(branch)
8585
bname = branch.replace(lp_name + "_", "")
8686
bs = " ".join(bname.split("_"))
8787
bsc = lp_name.replace("bsc", "bsc#")
@@ -206,7 +206,7 @@ def get_commits(self, cve, savedir=None):
206206

207207
self.fetch_kernel_branches()
208208

209-
print("Getting SUSE fixes for upstream commits per CVE branch. It can take some time...")
209+
logging.info("Getting SUSE fixes for upstream commits per CVE branch. It can take some time...")
210210

211211
# Store all commits from each branch and upstream
212212
commits = {}
@@ -309,7 +309,7 @@ def get_commits(self, cve, savedir=None):
309309
stderr=subprocess.STDOUT,
310310
).decode("ISO-8859-1")
311311
except subprocess.CalledProcessError:
312-
print(
312+
logging.warn(
313313
f"File {fname} doesn't exists {mbranch}. It could "
314314
" be removed, so the branch is not affected by the issue."
315315
)
@@ -360,16 +360,16 @@ def get_commits(self, cve, savedir=None):
360360
for d, c, msg in ucommits_sort:
361361
commits["upstream"]["commits"].append(f'{c} ("{msg}")')
362362

363-
print("")
363+
logging.info("")
364364

365365
for key, val in commits.items():
366-
print(f"{key}")
366+
logging.info(f"{key}")
367367
branch_commits = val["commits"]
368368
if not branch_commits:
369-
print("None")
369+
logging.info("None")
370370
for c in branch_commits:
371-
print(c)
372-
print("")
371+
logging.info(c)
372+
logging.info("")
373373

374374
return commits
375375

@@ -451,7 +451,7 @@ def get_patched_kernels(self, codestreams, commits, cve):
451451
logging.info("No CVE informed, skipping the processing of getting the patched kernels.")
452452
return []
453453

454-
print("Searching for already patched codestreams...")
454+
logging.info("Searching for already patched codestreams...")
455455

456456
kernels = []
457457

@@ -475,17 +475,17 @@ def get_patched_kernels(self, codestreams, commits, cve):
475475
if not patched and kernel not in suse_tags:
476476
continue
477477

478-
print(f"\n{cs.name()} ({kernel}):")
478+
logging.debug(f"\n{cs.name()} ({kernel}):")
479479

480480
# If no patches/commits were found for this kernel, fallback to
481481
# the commits in the main SLE branch. In either case, we can
482482
# assume that this kernel is already patched.
483483
for c in kern_commits if patched else suse_commits:
484-
print(f"{c}")
484+
logging.debug(f"{c}")
485485

486486
kernels.append(kernel)
487487

488-
print("")
488+
logging.debug("")
489489

490490
# remove duplicates
491491
return natsorted(list(set(kernels)))

klpbuild/main.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
def main():
2121
args = create_parser().parse_args(sys.argv[1:])
2222

23-
logging.basicConfig(level=logging.INFO, format="%(message)s")
23+
logging_level = logging.DEBUG if args.verbose else logging.INFO
24+
logging.basicConfig(level=logging_level, format="%(message)s")
2425

2526
if hasattr(args, 'name'):
2627
load_codestreams(args.name)

0 commit comments

Comments
 (0)