commit: ccfa1c152556ee6080731e2d1d51d92e5cd0b278 Author: Fabian Groffen <grobian <AT> gentoo <DOT> org> AuthorDate: Sun Jul 14 10:17:20 2019 +0000 Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org> CommitDate: Sun Jul 14 10:17:20 2019 +0000 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=ccfa1c15
qlop: add -F argument Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org> man/qlop.1 | 3 +++ qlop.c | 43 ++++++++++++++++++++++++++----------------- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/man/qlop.1 b/man/qlop.1 index 3fb9c7a..10eaa27 100644 --- a/man/qlop.1 +++ b/man/qlop.1 @@ -109,6 +109,9 @@ Read emerge logfile instead of $EMERGE_LOG_DIR/emerge.log. \fB\-w\fR \fI<arg>\fR, \fB\-\-atoms\fR \fI<arg>\fR Read package atoms to report from file. .TP +\fB\-F\fR \fI<arg>\fR, \fB\-\-format\fR \fI<arg>\fR +Print matched atom using given format string. +.TP \fB\-\-root\fR \fI<arg>\fR Set the ROOT env var. .TP diff --git a/qlop.c b/qlop.c index bd16018..e20c97b 100644 --- a/qlop.c +++ b/qlop.c @@ -24,7 +24,7 @@ #define QLOP_DEFAULT_LOGFILE "emerge.log" -#define QLOP_FLAGS "ctaHMmuUslerd:f:w:" COMMON_FLAGS +#define QLOP_FLAGS "ctaHMmuUslerd:f:w:F:" COMMON_FLAGS static struct option const qlop_long_opts[] = { {"summary", no_argument, NULL, 'c'}, {"time", no_argument, NULL, 't'}, @@ -41,6 +41,7 @@ static struct option const qlop_long_opts[] = { {"lastmerge", no_argument, NULL, 'l'}, {"logfile", a_argument, NULL, 'f'}, {"atoms", a_argument, NULL, 'w'}, + {"format", a_argument, NULL, 'F'}, COMMON_LONG_OPTS }; static const char * const qlop_opts_help[] = { @@ -59,6 +60,7 @@ static const char * const qlop_opts_help[] = { "Limit selection to last Portage emerge action", "Read emerge logfile instead of $EMERGE_LOG_DIR/" QLOP_DEFAULT_LOGFILE, "Read package atoms to report from file", + "Print matched atom using given format string", COMMON_OPTS_HELP }; static const char qlop_desc[] = @@ -83,6 +85,7 @@ struct qlop_mode { char do_machine:1; char do_endtime:1; char show_lastmerge:1; + const char *fmt; }; static bool @@ -347,10 +350,6 @@ static int do_emerge_log( }; struct pkg_match *pkg; struct pkg_match *pkgw; - const char *afmt = "%[CATEGORY]%[PN]"; - - if (verbose) - afmt = "%[CATEGORY]%[PF]"; if ((fp = fopen(log, "r")) == NULL) { warnp("Could not open logfile '%s'", log); @@ -621,19 +620,19 @@ static int do_emerge_log( } if (quiet && !flags->do_average) { printf("%s%s%s\n", - atom_format(afmt, pkgw->atom), + atom_format(flags->fmt, pkgw->atom), flags->do_time ? ": " : "", flags->do_time ? fmt_elapsedtime(flags, elapsed) : ""); } else if (flags->do_time) { printf("%s >>> %s: %s\n", fmt_date(flags, pkgw->tbegin, tstart), - atom_format(afmt, pkgw->atom), + atom_format(flags->fmt, pkgw->atom), fmt_elapsedtime(flags, elapsed)); } else if (!flags->do_average) { printf("%s >>> %s\n", fmt_date(flags, pkgw->tbegin, tstart), - atom_format(afmt, pkgw->atom)); + atom_format(flags->fmt, pkgw->atom)); } atom_implode(pkgw->atom); xarraydelete(merge_matches, i); @@ -726,19 +725,19 @@ static int do_emerge_log( } if (quiet && !flags->do_average) { printf("%s%s%s\n", - atom_format(afmt, pkgw->atom), + atom_format(flags->fmt, pkgw->atom), flags->do_time ? ": " : "", flags->do_time ? fmt_elapsedtime(flags, elapsed) : ""); } else if (flags->do_time) { printf("%s <<< %s: %s\n", fmt_date(flags, pkgw->tbegin, tstart), - atom_format(afmt, pkgw->atom), + atom_format(flags->fmt, pkgw->atom), fmt_elapsedtime(flags, elapsed)); } else if (!flags->do_average) { printf("%s <<< %s\n", fmt_date(flags, pkgw->tbegin, tstart), - atom_format(afmt, pkgw->atom)); + atom_format(flags->fmt, pkgw->atom)); } atom_implode(pkgw->atom); xarraydelete(unmerge_matches, i); @@ -800,7 +799,7 @@ static int do_emerge_log( if (flags->do_time) { printf("%s >>> %s: %s...%s ETA: %s\n", fmt_date(flags, pkgw->tbegin, 0), - atom_format(afmt, pkgw->atom), + atom_format(flags->fmt, pkgw->atom), fmt_elapsedtime(flags, elapsed), p == NULL ? "" : p, maxtime == 0 ? "unknown" : @@ -808,7 +807,7 @@ static int do_emerge_log( } else { printf("%s >>> %s...%s ETA: %s\n", fmt_date(flags, pkgw->tbegin, 0), - atom_format(afmt, pkgw->atom), + atom_format(flags->fmt, pkgw->atom), p == NULL ? "" : p, maxtime == 0 ? "unknown" : fmt_elapsedtime(flags, maxtime - elapsed)); @@ -833,14 +832,14 @@ static int do_emerge_log( if (flags->do_time) { printf("%s <<< %s: %s... ETA: %s\n", fmt_date(flags, pkgw->tbegin, 0), - atom_format(afmt, pkgw->atom), + atom_format(flags->fmt, pkgw->atom), fmt_elapsedtime(flags, elapsed), maxtime == 0 ? "unknown" : fmt_elapsedtime(flags, maxtime - elapsed)); } else { printf("%s <<< %s... ETA: %s\n", fmt_date(flags, pkgw->tbegin, 0), - atom_format(afmt, pkgw->atom), + atom_format(flags->fmt, pkgw->atom), maxtime == 0 ? "unknown" : fmt_elapsedtime(flags, maxtime - elapsed)); } @@ -852,7 +851,7 @@ static int do_emerge_log( array_for_each(merge_averages, i, pkg) { printf("%s: %s average for %s%zd%s merge%s\n", - atom_format(afmt, pkg->atom), + atom_format(flags->fmt, pkg->atom), fmt_elapsedtime(flags, pkg->time / pkg->cnt), GREEN, pkg->cnt, NORM, pkg->cnt == 1 ? "" : "s"); total_merges += pkg->cnt; @@ -860,7 +859,7 @@ static int do_emerge_log( } array_for_each(unmerge_averages, i, pkg) { printf("%s: %s average for %s%zd%s unmerge%s\n", - atom_format(afmt, pkg->atom), + atom_format(flags->fmt, pkg->atom), fmt_elapsedtime(flags, pkg->time / pkg->cnt), GREEN, pkg->cnt, NORM, pkg->cnt == 1 ? "" : "s"); total_unmerges += pkg->cnt; @@ -922,6 +921,7 @@ int qlop_main(int argc, char **argv) m.do_machine = 0; m.do_endtime = 0; m.show_lastmerge = 0; + m.fmt = NULL; while ((ret = GETOPT_LONG(QLOP, qlop, "")) != -1) { switch (ret) { @@ -939,6 +939,7 @@ int qlop_main(int argc, char **argv) case 'M': m.do_machine = 1; break; case 'e': m.do_endtime = 1; break; case 'l': m.show_lastmerge = 1; break; + case 'F': m.fmt = optarg; break; case 'd': if (start_time == 0) { if (!parse_date(optarg, &start_time)) @@ -1059,6 +1060,14 @@ int qlop_main(int argc, char **argv) m.do_sync = 1; } + /* set format if none given */ + if (m.fmt == NULL) { + if (verbose) + m.fmt = "%[CATEGORY]%[PF]"; + else + m.fmt = "%[CATEGORY]%[PN]"; + } + do_emerge_log(logfile, &m, atoms, start_time, end_time); array_for_each(atoms, i, atom)