From 1587fa63e6bf4f00a07914cf5edabcde2942fffc Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A1n=20Kupec?= Date: Mon, 18 Oct 2010 17:20:41 +0200 Subject: [PATCH] make repo list data configurable (bnc #543510) --- doc/zypper.8 | 24 +++++++--- src/Config.cc | 9 +++- src/Config.h | 5 ++ src/Zypper.cc | 6 +++ src/repos.cc | 150 +++++++++++++++++++++++++++++++++++++++------------------- zypper.conf | 18 +++++++ 6 files changed, 156 insertions(+), 56 deletions(-) diff --git a/doc/zypper.8 b/doc/zypper.8 index e2699e7..d35709f 100644 --- a/doc/zypper.8 +++ b/doc/zypper.8 @@ -1,4 +1,4 @@ -.TH "zypper" "8" "1.5.0" "zypper" "System Tools" +.TH "zypper" "8" "1.5.1" "zypper" "System Tools" .SH "NAME" .LP zypper - Command\-line interface to ZYpp system management library (libzypp) @@ -1003,12 +1003,13 @@ Ignore query string in the URI List all defined repositories or show detailed information about those specified as arguments .IP -If no arguments are given, the following data are printed for each repository -found on the sytem: -# (repository number), Enabled (whether the repository is enabled), Refresh -(whether auto-refresh is enabled for the repository), Type (rpm-md, yast2, -plaindir), Alias (shorthand for Name), and Name. Other columns can be added -using the options listed below. +The following data can be printed for each repository found on the sytem: +# (repository number), Alias (shorthand for Name), Name, Enabled (whether +the repository is enabled), Refresh (whether auto-refresh is enabled for +the repository), Priority, Type (repository meta-data type: rpm-md, yast2, +plaindir). Which of the data is shown is determined by command line +options listed below and the main.repoListColumns setting from zypper.conf. +By default, #, Alias, Name, Enabled, and Refresh is shown. Repository number is a unique identifier of the repository in current set of repositories. If you add, remove or change a repository, the numbers may @@ -1027,12 +1028,21 @@ repositories into a single file in repo file format. If '\-' is specified instead of a file name, the repositories will be written to the standard output. .TP +.I \-a, \-\-alias +Add alias column to the output. +.TP +.I \-n, \-\-name +Add name column to the output. +.TP .I \-u, \-\-uri Add base URI column to the output. .TP .I \-p, \-\-priority Add repository priority column to the output. .TP +.I \-r, \-\-refresh +Add the autorefresh column to the output. +.TP .I \-d, \-\-details Show more information like URI, priority, type, etc. .TP diff --git a/src/Config.cc b/src/Config.cc index f308c79..046fe9e 100644 --- a/src/Config.cc +++ b/src/Config.cc @@ -33,6 +33,7 @@ using namespace zypp; static map _table; static map _table_str; const ConfigOption ConfigOption::MAIN_SHOW_ALIAS(ConfigOption::MAIN_SHOW_ALIAS_e); +const ConfigOption ConfigOption::MAIN_REPO_LIST_COLUMNS(ConfigOption::MAIN_REPO_LIST_COLUMNS_e); const ConfigOption ConfigOption::SOLVER_INSTALL_RECOMMENDS(ConfigOption::SOLVER_INSTALL_RECOMMENDS_e); const ConfigOption ConfigOption::SOLVER_FORCE_RESOLUTION_COMMANDS(ConfigOption::SOLVER_FORCE_RESOLUTION_COMMANDS_e); const ConfigOption ConfigOption::COLOR_USE_COLORS(ConfigOption::COLOR_USE_COLORS_e); @@ -58,7 +59,8 @@ ConfigOption::Option ConfigOption::parse(const std::string & strval_r) if (_table.empty()) { // initialize it - _table["main/showAlias"] = SOLVER_INSTALL_RECOMMENDS_e; + _table["main/showAlias"] = MAIN_SHOW_ALIAS_e; + _table["main/repoListColumns"] = MAIN_REPO_LIST_COLUMNS_e; _table["solver/installRecommends"] = SOLVER_INSTALL_RECOMMENDS_e; _table["solver/forceResolutionCommands"] = SOLVER_FORCE_RESOLUTION_COMMANDS_e; _table["color/useColors"] = COLOR_USE_COLORS_e; @@ -88,6 +90,7 @@ const string ConfigOption::asString() const { // initialize it _table_str[MAIN_SHOW_ALIAS_e] = "main/showAlias"; + _table_str[MAIN_REPO_LIST_COLUMNS_e] = "main/repoListColumns"; _table_str[SOLVER_INSTALL_RECOMMENDS_e] = "solver/installRecommends"; _table_str[SOLVER_FORCE_RESOLUTION_COMMANDS_e] = "solver/forceResolutionCommands"; _table_str[COLOR_USE_COLORS_e] = "color/useColors"; @@ -112,6 +115,7 @@ const string ConfigOption::asString() const Config::Config() : show_alias(false) + , repo_list_columns("anr") , solver_installRecommends(true) , do_colors (false) , color_useColors ("never") @@ -148,6 +152,9 @@ void Config::read(const string & file) ZConfig::instance().repoLabelIsAlias(show_alias); } + s = augeas.getOption(ConfigOption::MAIN_REPO_LIST_COLUMNS.asString()); + if (!s.empty()) // TODO add some validation + repo_list_columns = s; // ---------------[ solver ]------------------------------------------------ diff --git a/src/Config.h b/src/Config.h index baa693d..32b417f 100644 --- a/src/Config.h +++ b/src/Config.h @@ -19,6 +19,7 @@ class ConfigOption { public: static const ConfigOption MAIN_SHOW_ALIAS; + static const ConfigOption MAIN_REPO_LIST_COLUMNS; static const ConfigOption SOLVER_INSTALL_RECOMMENDS; static const ConfigOption SOLVER_FORCE_RESOLUTION_COMMANDS; @@ -41,6 +42,7 @@ public: enum Option { MAIN_SHOW_ALIAS_e, + MAIN_REPO_LIST_COLUMNS_e, SOLVER_INSTALL_RECOMMENDS_e, SOLVER_FORCE_RESOLUTION_COMMANDS_e, @@ -90,6 +92,9 @@ struct Config /** Whether to show repo alias instead of name wherever we need to show repo*/ bool show_alias; + /** Which columns to show in repo list by default (string of short options).*/ + std::string repo_list_columns; + bool solver_installRecommends; std::set solver_forceResolutionCommands; diff --git a/src/Zypper.cc b/src/Zypper.cc index f39411a..fee74a3 100644 --- a/src/Zypper.cc +++ b/src/Zypper.cc @@ -1346,6 +1346,9 @@ void Zypper::processCommandOptions() { static struct option service_list_options[] = { {"export", required_argument, 0, 'e'}, + {"alias", no_argument, 0, 'a'}, + {"name", no_argument, 0, 'n'}, + {"refresh", no_argument, 0, 'r'}, {"uri", no_argument, 0, 'u'}, {"url", no_argument, 0, 'u'}, {"priority", no_argument, 0, 'p'}, @@ -1385,8 +1388,11 @@ void Zypper::processCommandOptions() "\n" " Command options:\n" "-e, --export Export all defined repositories as a single local .repo file.\n" + "-a, --alias Show also repository alias.\n" + "-n, --name Show also repository name.\n" "-u, --uri Show also base URI of repositories.\n" "-p, --priority Show also repository priority.\n" + "-r, --refresh Show also the autorefresh flag.\n" "-d, --details Show more information like URI, priority, type.\n" "-s, --service Show also alias of parent service.\n" "-U, --sort-by-uri Sort the list by URI.\n" diff --git a/src/repos.cc b/src/repos.cc index 71abfe2..6c572a6 100644 --- a/src/repos.cc +++ b/src/repos.cc @@ -789,60 +789,140 @@ static void print_repo_list(Zypper & zypper, { Table tbl; bool all = zypper.cOpts().count("details"); - bool showuri = zypper.cOpts().count("uri") || zypper.cOpts().count("url") || zypper.cOpts().count("sort-by-uri"); - bool showprio = zypper.cOpts().count("priority") || zypper.cOpts().count("sort-by-priority"); + string list_cols = zypper.config().repo_list_columns; + bool showalias = zypper.cOpts().count("alias") + || zypper.cOpts().count("sort-by-alias") + || list_cols.find_first_of("aA") != string::npos; + bool showname = zypper.cOpts().count("name") + || zypper.cOpts().count("sort-by-name") + || list_cols.find_first_of("nN") != string::npos; + bool showrefresh = zypper.cOpts().count("refresh") + || list_cols.find_first_of("rR") != string::npos; + bool showuri = zypper.cOpts().count("uri") || zypper.cOpts().count("url") + || zypper.cOpts().count("sort-by-uri") + || list_cols.find_first_of("uU") != string::npos; + bool showprio = zypper.cOpts().count("priority") + || zypper.cOpts().count("sort-by-priority") + || list_cols.find_first_of("pP") != string::npos; bool showservice = zypper.cOpts().count("service"); + bool sort_override = zypper.cOpts().count("sort-by-uri") + || zypper.cOpts().count("sort-by-priority") + || zypper.cOpts().count("sort-by-alias") + || zypper.cOpts().count("sort-by-name"); // header TableHeader th; - // fixed 'zypper repos' columns - th << "#" - << _("Alias") - << _("Name") - << _("Enabled") - // translators: 'zypper repos' column - whether autorefresh is enabled for the repository - << _("Refresh"); - // optional columns + // keep count of columns so that we know which one to sort + // TODO might be worth to improve Table to allow named columns so this can be avoided + unsigned index = 0; + // number of the column to sort by + unsigned sort_index = 0; + + // repo number + th << "#"; + + // alias + if (all || showalias) + { + th << _("Alias"); + ++index; + // if (zypper.cOpts().count("sort-by-alias") + // || (list_cols.find("A") != string::npos && !sort_override)) + // sort by alias by default + sort_index = index; + } + + // name + if (all || showname) + { + th << _("Name"); + ++index; + if (zypper.cOpts().count("sort-by-name") + || (list_cols.find("N") != string::npos && !sort_override)) + sort_index = index; + } + + // 'enabled' flag + th << _("Enabled"); + ++index; + + // 'autorefresh' flag + if (all || showrefresh) + { + // translators: 'zypper repos' column - whether autorefresh is enabled + // for the repository + th << _("Refresh"); + ++index; + if (list_cols.find("R") != string::npos && !sort_override) + sort_index = index; + } + + // priority if (all || showprio) + { // translators: repository priority (in zypper repos -p or -d) th << _("Priority"); + ++index; + if (zypper.cOpts().count("sort-by-priority") + || (list_cols.find("P") != string::npos && !sort_override)) + sort_index = index; + } + + // type if (all) + { th << _("Type"); + ++index; + } + + // URI if (all || showuri) + { th << _("URI"); + ++index; + if (zypper.cOpts().count("sort-by-uri") + || (list_cols.find("U") != string::npos && !sort_override)) + sort_index = index; + } + + // service alias if (all || showservice) + { th << _("Service"); + ++index; + } + tbl << th; + // table data int i = 1; - - for (std::list::const_iterator it = repos.begin(); + unsigned nindent = repos.size() > 9 ? repos.size() > 99 ? 3 : 2 : 1; + for (list::const_iterator it = repos.begin(); it != repos.end(); ++it) { RepoInfo repo = *it; - TableRow tr(all ? 8 : showprio || showuri ? 7 : 6); + TableRow tr(index); // number - tr << str::numstring (i); + tr << str::numstring (i, nindent); // alias - tr << repo.alias(); + if (all || showalias) tr << repo.alias(); // name - tr << repo.name(); + if (all || showname) tr << repo.name(); // enabled? tr << (repo.enabled() ? _("Yes") : _("No")); // autorefresh? - tr << (repo.autorefresh() ? _("Yes") : _("No")); + if (all || showrefresh) tr << (repo.autorefresh() ? _("Yes") : _("No")); // priority if (all || showprio) - tr << str::numstring (repo.priority(), 4); // output flush right; looks nicer and sorts correctly + // output flush right; looks nicer and sorts correctly + tr << str::numstring (repo.priority(), 4); // type if (all) tr << repo.type().asString(); // url /** - * \todo properly handle multiple baseurls - show "(multiple)" and - * provide zypper lr [#|alias|URI] ... for showing full repo info - * (not in table) + * \todo properly handle multiple baseurls - show "(multiple)" */ if (all || showuri) tr << (*repo.baseUrlsBegin()).asString(); @@ -860,33 +940,7 @@ static void print_repo_list(Zypper & zypper, else { // sort - if (zypper.cOpts().count("sort-by-uri")) - { - cout << "will sort by uri: "; - if (all) - { - tbl.sort(7); - cout << 7; - } - else if (showprio) - { - tbl.sort(6); - cout << 6; - } - else - { - tbl.sort(5); - cout << 5; - } - cout << endl; - } - else if (zypper.cOpts().count("sort-by-alias")) - tbl.sort(1); - else if (zypper.cOpts().count("sort-by-name")) - tbl.sort(2); - else if (zypper.cOpts().count("sort-by-priority")) - tbl.sort(5); - + tbl.sort(sort_index); // print cout << tbl; } diff --git a/zypper.conf b/zypper.conf index 802a1cf..0bcc1f7 100644 --- a/zypper.conf +++ b/zypper.conf @@ -40,6 +40,24 @@ ## # showAlias = false +## Columns to show in repository list printed by repos (lr) command by default. +## +## The # (number) and Enabled column is shown always. The following columns +## can be configured: +## +## a - alias - the shorthand for name and unique identifier +## n - name - full name of the repository +## r - autorefresh? +## u - URL +## p - priority +## +## Valid values: any combination of the above letters; capital letter marks +## column by which the table will be sorted (if multiple +## are used the sorting is undefined). +## Default value: Anr +## +# repoListColumns = Anr + [solver] ## Do not install soft dependencies (recommended packages) -- 2.7.4