Mailinglist Archive: zypp-commit (223 mails)

< Previous Next >
[zypp-commit] r10670 - in /trunk/zypper/src: Command.cc Command.h Zypper.cc repos.cc repos.h utils/messages.cc utils/messages.h utils/misc.h
  • From: jkupec@xxxxxxxxxxxxxxxx
  • Date: Sun, 27 Jul 2008 12:30:52 -0000
  • Message-id: <20080727123052.EFA232A121@xxxxxxxxxxxxxxxx>
Author: jkupec
Date: Sun Jul 27 14:30:52 2008
New Revision: 10670

URL: http://svn.opensuse.org/viewcvs/zypp?rev=10670&view=rev
Log:
- initial support for NU repo index services
- addservice, removeservice, refres-services, services added
- TODO services xmlout, rug compatibility, integration with the rest of
zypper, tune
- TODO modifyservice (low priority, maybe after 11.1)
- feedback/ideas welcome

Modified:
trunk/zypper/src/Command.cc
trunk/zypper/src/Command.h
trunk/zypper/src/Zypper.cc
trunk/zypper/src/repos.cc
trunk/zypper/src/repos.h
trunk/zypper/src/utils/messages.cc
trunk/zypper/src/utils/messages.h
trunk/zypper/src/utils/misc.h

Modified: trunk/zypper/src/Command.cc
URL:
http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/Command.cc?rev=10670&r1=10669&r2=10670&view=diff
==============================================================================
--- trunk/zypper/src/Command.cc (original)
+++ trunk/zypper/src/Command.cc Sun Jul 27 14:30:52 2008
@@ -1,3 +1,10 @@
+/*---------------------------------------------------------------------------*\
+ ____ _ _ __ _ __ ___ _ _
+ |_ / || | '_ \ '_ \/ -_) '_|
+ /__|\_, | .__/ .__/\___|_|
+ |__/|_| |_|
+\*---------------------------------------------------------------------------*/
+
#include <map>

#include "zypp/base/Exception.h"
@@ -15,6 +22,11 @@

static std::map<std::string,ZypperCommand::Command> _table;

+const ZypperCommand ZypperCommand::ADD_SERVICE(ZypperCommand::ADD_SERVICE_e);
+const ZypperCommand
ZypperCommand::REMOVE_SERVICE(ZypperCommand::REMOVE_SERVICE_e);
+const ZypperCommand
ZypperCommand::LIST_SERVICES(ZypperCommand::LIST_SERVICES_e);
+const ZypperCommand
ZypperCommand::REFRESH_SERVICES(ZypperCommand::REFRESH_SERVICES_e);
+
const ZypperCommand ZypperCommand::ADD_REPO(ZypperCommand::ADD_REPO_e);
const ZypperCommand ZypperCommand::REMOVE_REPO(ZypperCommand::REMOVE_REPO_e);
const ZypperCommand ZypperCommand::RENAME_REPO(ZypperCommand::RENAME_REPO_e);
@@ -77,11 +89,16 @@
if (_table.empty())
{
// initialize it
- _table["addrepo"] = _table["ar"] = _table["service-add"] = _table["sa"] =
ZypperCommand::ADD_REPO_e;
- _table["removerepo"] = _table["rr"] = _table["service-delete"] =
_table["sd"] = ZypperCommand::REMOVE_REPO_e;
- _table["renamerepo"]= _table["nr"] = _table["service-rename"] =
_table["sr"] = ZypperCommand::RENAME_REPO_e;
- _table["modifyrepo"]= _table["mr"] = _table["service-modify"] =
_table["sm"] = ZypperCommand::MODIFY_REPO_e;
- _table["repos"] = _table["lr"] = _table["service-list"] = _table["sl"] =
ZypperCommand::LIST_REPOS_e;
+ _table["addservice"] = _table["as"] = _table["service-add"] = _table["sa"]
= ZypperCommand::ADD_SERVICE_e;
+ _table["removeservice"] = _table["rs"] = _table["service-delete"] =
_table["sd"] = ZypperCommand::REMOVE_SERVICE_e;
+ _table["services"] = _table["ls"] = _table["service-list"] = _table["sl"]
= ZypperCommand::LIST_SERVICES_e;
+ _table["refresh-services"] = _table["refs"] =
ZypperCommand::REFRESH_SERVICES_e;
+
+ _table["addrepo"] = _table["ar"] = ZypperCommand::ADD_REPO_e;
+ _table["removerepo"] = _table["rr"] = ZypperCommand::REMOVE_REPO_e;
+ _table["renamerepo"]= _table["nr"] = ZypperCommand::RENAME_REPO_e;
+ _table["modifyrepo"]= _table["mr"] = ZypperCommand::MODIFY_REPO_e;
+ _table["repos"] = _table["lr"] = _table["catalogs"] = _table["ca"] =
ZypperCommand::LIST_REPOS_e;
_table["refresh"] = _table["ref"] = ZypperCommand::REFRESH_e;
_table["clean"] = _table["clean-cache"] = _table["cc"] =
_table["you-clean-cache"] = _table["yc"] = ZypperCommand::CLEAN_e;


Modified: trunk/zypper/src/Command.h
URL:
http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/Command.h?rev=10670&r1=10669&r2=10670&view=diff
==============================================================================
--- trunk/zypper/src/Command.h (original)
+++ trunk/zypper/src/Command.h Sun Jul 27 14:30:52 2008
@@ -1,3 +1,10 @@
+/*---------------------------------------------------------------------------*\
+ ____ _ _ __ _ __ ___ _ _
+ |_ / || | '_ \ '_ \/ -_) '_|
+ /__|\_, | .__/ .__/\___|_|
+ |__/|_| |_|
+\*---------------------------------------------------------------------------*/
+
#ifndef ZYPPERCOMMAND_H_
#define ZYPPERCOMMAND_H_

@@ -10,6 +17,11 @@
*/
struct ZypperCommand
{
+ static const ZypperCommand ADD_SERVICE;
+ static const ZypperCommand REMOVE_SERVICE;
+ static const ZypperCommand LIST_SERVICES;
+ static const ZypperCommand REFRESH_SERVICES;
+
static const ZypperCommand ADD_REPO;
static const ZypperCommand REMOVE_REPO;
static const ZypperCommand RENAME_REPO;
@@ -68,6 +80,11 @@

enum Command
{
+ ADD_SERVICE_e,
+ REMOVE_SERVICE_e,
+ LIST_SERVICES_e,
+ REFRESH_SERVICES_e,
+
ADD_REPO_e,
REMOVE_REPO_e,
RENAME_REPO_e,

Modified: trunk/zypper/src/Zypper.cc
URL:
http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/Zypper.cc?rev=10670&r1=10669&r2=10670&view=diff
==============================================================================
--- trunk/zypper/src/Zypper.cc (original)
+++ trunk/zypper/src/Zypper.cc Sun Jul 27 14:30:52 2008
@@ -195,6 +195,13 @@
"\tclean\t\t\tClean local caches.\n"
);

+ static string help_service_commands = _("\tService Handling:\n"
+ "\tservices, ls\t\tList all defined services.\n"
+ "\taddservice, as\t\tAdd a new service.\n"
+ "\tremoveservice, rs\tRemove specified service.\n"
+ "\trefreshservice, refs\tRefresh all services.\n"
+ );
+
static string help_package_commands = _("\tSoftware Management:\n"
"\tinstall, in\t\tInstall packages.\n"
"\tremove, rm\t\tRemove packages.\n"
@@ -238,6 +245,7 @@
zypper.out().info(help_global_target_options, Out::QUIET);
zypper.out().info(help_commands, Out::QUIET);
zypper.out().info(help_repo_commands, Out::QUIET);
+ zypper.out().info(help_service_commands, Out::QUIET);
zypper.out().info(help_package_commands, Out::QUIET);
zypper.out().info(help_query_commands, Out::QUIET);
zypper.out().info(help_lock_commands, Out::QUIET);
@@ -968,6 +976,97 @@
break;
}

+ //! \todo
+ case ZypperCommand::ADD_SERVICE_e:
+ {
+ static struct option service_add_options[] = {
+ {"type", required_argument, 0, 't'},
+ {"disable", no_argument, 0, 'd'},
+ {"name", required_argument, 0, 'n'},
+ {"help", no_argument, 0, 'h'},
+ {0, 0, 0, 0}
+ };
+ specific_options = service_add_options;
+ _command_help = str::form(_(
+ // TranslatorExplanation the %s = "yast2, rpm-md, plaindir"
+ "addservice (as) [options] <URI> <alias>\n"
+ "\n"
+ "Add a repository index service to the system.\n"
+ "\n"
+ " Command options:\n"
+ "-t, --type <TYPE> Type of repository (%s).\n"
+ "-d, --disable Add the service as disabled.\n"
+ "-n, --name Specify descriptive name for the service.\n"
+ ), "yast2, rpm-md, plaindir");
+ break;
+ }
+
+ case ZypperCommand::REMOVE_SERVICE_e:
+ {
+ static struct option options[] = {
+ {"help", no_argument, 0, 'h'},
+ {0, 0, 0, 0}
+ };
+ specific_options = options;
+ _command_help = _(
+ // TranslatorExplanation the %s = "yast2, rpm-md, plaindir"
+ // TODO
+ "removeservice (rs) [options] <alias|#|URI>\n"
+ "\n"
+ "Remove specified repository index service from the sytem..\n"
+ "\n"
+ " Command options:\n"
+ " --loose-auth Ignore user authentication data in the URI.\n"
+ " --loose-query Ignore query string in the URI.\n"
+ );
+ break;
+ }
+
+ case ZypperCommand::LIST_SERVICES_e:
+ {
+ static struct option options[] = {
+ {"help", no_argument, 0, 'h'},
+ {"uri", no_argument, 0, 'u'},
+ {"url", no_argument, 0, 'u'},
+ {"details", no_argument, 0, 'd'},
+ {"sort-by-uri", no_argument, 0, 'U'},
+ {"sort-by-name", no_argument, 0, 'N'},
+ {0, 0, 0, 0}
+ };
+ specific_options = options;
+ _command_help = _(
+ "services (ls) [options]\n"
+ "\n"
+ "List defined services.\n"
+ "\n"
+ " Command options:\n"
+ "-u, --uri Show also base URI of repositories.\n"
+ "-d, --details Show more information like URI, priority,
type.\n"
+ "-U, --sort-by-uri Sort the list by URI.\n"
+ "-N, --sort-by-name Sort the list by name.\n"
+ );
+ break;
+ }
+
+ case ZypperCommand::REFRESH_SERVICES_e:
+ {
+ static struct option options[] = {
+ {"help", no_argument, 0, 'h'},
+ {"repos", no_argument, 0, 'r'},
+ {0, 0, 0, 0}
+ };
+ specific_options = options;
+ _command_help = _(
+ "refresh-services (refs) [options]\n"
+ "\n"
+ "Refresh defined repository index services.\n"
+ "\n"
+ " Command options:\n"
+ "-r, --repos Refresh also repositories of the services.\n"
+ );
+ break;
+ }
+
case ZypperCommand::ADD_REPO_e:
{
static struct option service_add_options[] = {
@@ -1017,6 +1116,7 @@
{"sort-by-uri", no_argument, 0, 'U'},
{"sort-by-alias", no_argument, 0, 'A'},
{"sort-by-name", no_argument, 0, 'N'},
+ {"service", no_argument, 0, 's'}, //! \todo document
{"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
};
@@ -1951,15 +2051,158 @@
break;
}

+ // --------------------------( service list )-------------------------------
+
+ case ZypperCommand::LIST_SERVICES_e:
+ {
+ if (runningHelp()) { out().info(_command_help, Out::QUIET); return; }
+
+ list_services(*this);
+
+ break;
+ }
+
+ // --------------------------( service refresh )-----------------------------
+
+ case ZypperCommand::REFRESH_SERVICES_e:
+ {
+ if (runningHelp()) { out().info(_command_help, Out::QUIET); return; }
+
+ // check root user
+ if (geteuid() != 0 && !globalOpts().changedRoot)
+ {
+ out().error(
+ _("Root privileges are required for refreshing services."));
+ setExitCode(ZYPPER_EXIT_ERR_PRIVILEGES);
+ return;
+ }
+
+ refresh_services(*this);
+
+ // refresh also repos
+ if (copts.count("repos"))
+ refresh_repos(*this);
+
+ break;
+ }
+
+ // --------------------------( add service )---------------------------------
+
+ case ZypperCommand::ADD_SERVICE_e:
+ {
+ if (runningHelp()) { out().info(_command_help, Out::QUIET); return; }
+
+ // check root user
+ if (geteuid() != 0 && !globalOpts().changedRoot)
+ {
+ out().error(
+ _("Root privileges are required for modifying system services."));
+ setExitCode(ZYPPER_EXIT_ERR_PRIVILEGES);
+ return;
+ }
+
+ // too many arguments
+ if (_arguments.size() > 2)
+ {
+ report_too_many_arguments(_command_help);
+ setExitCode(ZYPPER_EXIT_ERR_INVALID_ARGS);
+ return;
+ }
+
+ // missing arguments
+ if (_arguments.size() < 2)
+ {
+ report_required_arg_missing(out(), _command_help);
+ setExitCode(ZYPPER_EXIT_ERR_INVALID_ARGS);
+ return;
+ }
+
+ // indeterminate indicates the user has not specified the values
+ tribool enabled(indeterminate);
+
+ if (copts.count("disable") || copts.count("disabled"))
+ enabled = false;
+
+ Url url = make_url (_arguments[0]);
+ if (!url.isValid())
+ {
+ setExitCode(ZYPPER_EXIT_ERR_INVALID_ARGS);
+ return;
+ }
+
+ // by default, enable the service
+ if (indeterminate(enabled)) enabled = true;
+
+ warn_if_zmd();
+
+ add_service_by_url(*this, url, _arguments[1], "" /** \todo type */,
enabled);
+
+ break;
+ }
+
+ // --------------------------( remove service )------------------------------
+
+ case ZypperCommand::REMOVE_SERVICE_e:
+ {
+ if (runningHelp()) { out().info(_command_help, Out::QUIET); return; }
+
+ // check root user
+ if (geteuid() != 0 && !globalOpts().changedRoot)
+ {
+ out().error(
+ _("Root privileges are required for modifying system services."));
+ setExitCode(ZYPPER_EXIT_ERR_PRIVILEGES);
+ return;
+ }
+
+ if (_arguments.size() < 1)
+ {
+ out().error(_("Required argument missing."));
+ ERR << "Required argument missing." << endl;
+ print_usage(out(), _command_help);
+ setExitCode(ZYPPER_EXIT_ERR_INVALID_ARGS);
+ return;
+ }
+
+ warn_if_zmd();
+
+ set<Service, ServiceAliasComparator> to_remove;
+ for (vector<string>::const_iterator it = _arguments.begin();
+ it != _arguments.end(); ++it)
+ {
+ Service s;
+ if (match_service(*this, *it, &s))
+ {
+ to_remove.insert(s);
+ }
+ else
+ {
+ MIL << "Service not found by given alias, number or URI." << endl;
+ out().error(boost::str(format(
+ // translators: %s is the supplied command line argument which
+ // for which no service counterpart was found
+ _("Service '%s' not found by alias, number or URI.")) % *it));
+ }
+ }
+
+ for_ (it, to_remove.begin(), to_remove.end())
+ {
+ remove_service(*this, *it);
+ }
+
+ break;
+ }
+
// --------------------------( repo list )----------------------------------

case ZypperCommand::LIST_REPOS_e:
{
if (runningHelp()) { out().info(_command_help, Out::QUIET); return; }

- if (_gopts.is_rug_compatible)
- rug_list_resolvables(*this);
- else
+ //! \todo this conflicts with other 'lr' aliases
+ //if (_gopts.is_rug_compatible)
+ // rug_list_resolvables(*this);
+ //else
list_repos(*this);

break;
@@ -2120,20 +2363,18 @@
{
out().error(_("Required argument missing."));
ERR << "Required argument missing." << endl;
- ostringstream s;
- s << _("Usage") << ':' << endl;
- s << _command_help;
- out().info(s.str());
+ print_usage(out(), _command_help);
setExitCode(ZYPPER_EXIT_ERR_INVALID_ARGS);
return;
}

warn_if_zmd ();

- //must store repository before remove to ensure correct match number
+ // must store repository before remove to ensure correct match number
set<RepoInfo,RepoInfoAliasComparator> repo_to_remove;
for (vector<string>::const_iterator it = _arguments.begin();
- it!= _arguments.end();++it){
+ it != _arguments.end(); ++it)
+ {
RepoInfo repo;
if (match_repo(*this,*it,&repo))
{
@@ -2143,10 +2384,9 @@
{
MIL << "Repository not found by given alias, number or URI." << endl;
out().error(boost::str(format(
- //TranslatorExplanation %s is string which was not found (can be url,
- //alias or the repo number)
- _("Repository %s not found by alias, number or URI."))
- % *it));
+ // translators: %s is the supplied command line argument which
+ // for which no repository counterpart was found
+ _("Repository '%s' not found by alias, number or URI.")) % *it));
}
}

@@ -2227,12 +2467,6 @@
return;
}

- //! \todo drop before 11.1
- if (_copts.count("enable-autorefresh"))
- out().warning(str::form(_("'%s' option is deprecated and will be dropped
soon."), "enable-autorefresh"));
- if (_copts.count("disable-autorefresh"))
- out().warning(str::form(_("'%s' option is deprecated and will be dropped
soon."), "disable-autorefresh"));
-
bool non_alias = copts.count("all") || copts.count("local") ||
copts.count("remote") || copts.count("medium-type");

@@ -2297,6 +2531,7 @@
_("The '%s' global option has no effect here."))
% "--no-refresh"));

+ refresh_services(*this);
refresh_repos(*this);
break;
}

Modified: trunk/zypper/src/repos.cc
URL:
http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/repos.cc?rev=10670&r1=10669&r2=10670&view=diff
==============================================================================
--- trunk/zypper/src/repos.cc (original)
+++ trunk/zypper/src/repos.cc Sun Jul 27 14:30:52 2008
@@ -1,3 +1,10 @@
+/*---------------------------------------------------------------------------*\
+ ____ _ _ __ _ __ ___ _ _
+ |_ / || | '_ \ '_ \/ -_) '_|
+ /__|\_, | .__/ .__/\___|_|
+ |__/|_| |_|
+\*---------------------------------------------------------------------------*/
+
#include <iostream>
#include <fstream>
#include <boost/format.hpp>
@@ -12,13 +19,11 @@
#include "zypp/base/String.h"

#include "zypp/RepoManager.h"
-#include "zypp/RepoInfo.h"
#include "zypp/repo/RepoException.h"
#include "zypp/parser/ParseException.h"
#include "zypp/media/MediaException.h"
#include "zypp/media/MediaAccess.h"

-#include "Zypper.h"
#include "output/Out.h"
#include "main.h"
#include "getopt.h"
@@ -260,11 +265,14 @@
return false; // no error
}

+// ---------------------------------------------------------------------------
+
bool match_repo(Zypper & zypper, string str, RepoInfo *repo)
{
RepoManager manager(zypper.globalOpts().rm_options);
- list<RepoInfo> known = manager.knownRepositories();
- bool founded = false;
+ list<RepoInfo> known;
+ known.insert(known.end(), manager.repoBegin(), manager.repoEnd());
+ bool found = false;

unsigned int number = 1; // repo number
for (list<RepoInfo>::const_iterator known_it = known.begin();
@@ -281,7 +289,7 @@
!= known_it->baseUrlsEnd())
{
*repo = *known_it;
- founded = true;
+ found = true;
break;
}
}
@@ -289,7 +297,7 @@

} // END for all known repos

- return founded;
+ return found;
}

// ---------------------------------------------------------------------------
@@ -409,7 +417,7 @@

// if no repository was specified on the command line, use all known repos
if (gData.repos.empty())
- gData.repos = manager.knownRepositories();
+ gData.repos.insert(gData.repos.end(), manager.repoBegin(),
manager.repoEnd());

// additional repositories (--plus-repo)
if (!gData.additional_repos.empty())
@@ -614,6 +622,7 @@
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");
+ bool showservice = zypper.cOpts().count("service");

// header
TableHeader th;
@@ -632,6 +641,8 @@
th << _("Type");
if (all || showuri)
th << _("URI");
+ if (all || showservice)
+ th << _("Service");
tbl << th;

int i = 1;
@@ -667,6 +678,9 @@
if (all || showuri)
tr << (*repo.baseUrlsBegin()).asString();

+ if (all || showservice)
+ tr << repo.service();
+
tbl << tr;
i++;
}
@@ -762,7 +776,7 @@

try
{
- repos = manager.knownRepositories();
+ repos.insert(repos.end(), manager.repoBegin(), manager.repoEnd());
}
catch ( const Exception &e )
{
@@ -825,6 +839,7 @@

void refresh_repos(Zypper & zypper)
{
+ MIL << "going to refresh repositories" << endl;
// need gpg keys when downloading (#304672)
init_target(zypper);
RepoManager manager(zypper.globalOpts().rm_options);
@@ -832,7 +847,7 @@
list<RepoInfo> repos;
try
{
- repos = manager.knownRepositories();
+ repos.insert(repos.end(), manager.repoBegin(), manager.repoEnd());
}
catch ( const Exception &e )
{
@@ -952,6 +967,7 @@

// ----------------------------------------------------------------------------

+/** \return false on success, true on error */
bool refresh_repo(Zypper & zypper, const zypp::RepoInfo & repo)
{
// raw metadata refresh
@@ -999,7 +1015,7 @@
list<RepoInfo> repos;
try
{
- repos = manager.knownRepositories();
+ repos.insert(repos.end(), manager.repoBegin(), manager.repoEnd());
}
catch ( const Exception &e )
{
@@ -1467,8 +1483,9 @@
void modify_repos_by_option( Zypper & zypper )
{
RepoManager manager(zypper.globalOpts().rm_options);
- const std::list<RepoInfo>& repos = manager.knownRepositories();
- std::set<std::string> toModify;
+ list<RepoInfo> repos;
+ repos.insert(repos.end(), manager.repoBegin(), manager.repoEnd());
+ set<string> toModify;

if ( copts.count("all") )
{
@@ -1563,9 +1580,9 @@

// autorefresh
tribool autoref = indeterminate;
- if (copts.count("refresh") || copts.count("enable-autorefresh"))
+ if (copts.count("refresh"))
autoref = true;
- if (copts.count("no-refresh") || copts.count("disable-autorefresh"))
+ if (copts.count("no-refresh"))
{
if (autoref)
{
@@ -1728,6 +1745,326 @@
}

// ---------------------------------------------------------------------------
+// Service Handling
+// ---------------------------------------------------------------------------
+
+static void print_service_list(Zypper & zypper,
+ const list<Service> & services)
+{
+ 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");
+
+ // 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
+ if (all || showprio)
+ // translators: repository priority (in zypper repos -p or -d)
+ th << _("Priority");
+ if (all)
+ th << _("Type");
+ if (all || showuri)
+ th << _("URI");
+ tbl << th;
+
+ int i = 1;
+
+ for (list<Service>::const_iterator it = services.begin();
+ it != services.end(); ++it)
+ {
+ Service service = *it;
+ TableRow tr(all ? 8 : showprio || showuri ? 7 : 6);
+
+ // number
+ tr << str::numstring (i);
+ // alias
+ tr << service.alias();
+ // name
+ tr << service.name();
+ // enabled?
+ tr << (service.enabled() ? _("Yes") : _("No"));
+ // autorefresh?
+ tr << "";
+ // priority
+ if (all || showprio)
+ tr << "";
+ // type
+ if (all)
+ tr << "NU"; // ???
+ // url
+ if (all || showuri)
+ tr << service.url().asString();
+
+ tbl << tr;
+ i++;
+ }
+
+ if (tbl.empty())
+ zypper.out().info(str::form(_(
+ "No services defined. Use the '%s' command to add one or more
services."),
+ "zypper addservice"));
+ 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);
+
+ // print
+ cout << tbl;
+ }
+}
+
+// ---------------------------------------------------------------------------
+
+void list_services(Zypper & zypper)
+{
+ RepoManager manager(zypper.globalOpts().rm_options);
+ list<Service> services;
+
+ try
+ {
+ services.insert(services.end(),
+ manager.serviceBegin(),
+ manager.serviceEnd());
+ }
+ catch ( const Exception &e )
+ {
+ ZYPP_CAUGHT(e);
+ zypper.out().error(e, _("Error reading services:"));
+ exit(ZYPPER_EXIT_ERR_ZYPP);
+ }
+
+ // export to file or stdout in repo file format
+ if (copts.count("export"))
+ {
+ string filename_str = copts["export"].front();
+ if (filename_str == "-")
+ {
+ //print_repos_to(repos, cout);
+ }
+ else
+ {
+ if (filename_str.rfind(".repo") == string::npos)
+ filename_str += ".repo";
+
+ Pathname file(filename_str);
+ std::ofstream stream(file.c_str());
+ if (!stream)
+ {
+ zypper.out().error(boost::str(format(
+ _("Can't open %s for writing."))
+ % file.asString()),
+ _("Maybe you do not have write permissions?"));
+ exit(ZYPPER_EXIT_ERR_INVALID_ARGS);
+ }
+ else
+ {
+ //print_repos_to(repos, stream);
+ zypper.out().info(boost::str(format(
+ _("Repositories have been successfully exported to %s."))
+ % (file.absolute() ? file.asString() : file.asString().substr(2))),
+ Out::QUIET);
+ }
+ }
+ }
+ // print repo list as xml
+ //else if (zypper.out().type() == Out::TYPE_XML)
+ //print_xml_repo_list(zypper, repos);
+ // print repo list the rug's way
+ //else if (zypper.globalOpts().is_rug_compatible)
+ //print_rug_service_list(repos);
+ // print repo list as table
+ else
+ print_service_list(zypper, services);
+}
+
+// ---------------------------------------------------------------------------
+
+void add_service(Zypper & zypper, const Service & service)
+{
+ RepoManager manager(zypper.globalOpts().rm_options);
+
+ try
+ {
+ manager.addService(service);
+ }
+ catch (const RepoAlreadyExistsException & e)
+ {
+ ZYPP_CAUGHT(e);
+ zypper.out().error(boost::str(format(
+ _("Service aliased '%s' already exists. Please use another alias."))
+ % service.alias()));
+ ERR << "Service aliased '" << service.alias() << "' already exists." <<
endl;
+ zypper.setExitCode(ZYPPER_EXIT_ERR_ZYPP);
+ return;
+ }
+ catch (const Exception & e)
+ {
+ ZYPP_CAUGHT(e);
+ zypper.out().error(boost::str(format(
+ _("Error occured while adding service '%s'.")) % service.alias()));
+ zypper.setExitCode(ZYPPER_EXIT_ERR_ZYPP);
+ return;
+ }
+
+ zypper.out().info(boost::str(
+ format(_("Service '%s' has been successfully added.")) % service.name()));
+ MIL << format("Service '%s' has been added.") % service.name() << endl;
+}
+
+// ---------------------------------------------------------------------------
+
+void add_service_by_url( Zypper & zypper,
+ const zypp::Url & url, const string & alias,
+ const string & type, tribool enabled)
+{
+ MIL << "going to add service by url (alias=" << alias << ", url=" << url
+ << ")" << endl;
+
+ Service service;
+
+ //! \todo what about service type? compare to rug. idea: do addrepo if type
is specified and is not NU.
+ //if ( ! type.empty() )
+ // repo.setType(RepoType(type));
+
+ service.setAlias(alias.empty() ? timestamp() : alias);
+ parsed_opts::const_iterator it = zypper.cOpts().find("name");
+ if (it != zypper.cOpts().end())
+ service.setName(it->second.front());
+ service.setUrl(url);
+
+ if ( !indeterminate(enabled) )
+ service.setEnabled((enabled == true));
+
+ add_service(zypper, service);
+}
+
+
+// ---------------------------------------------------------------------------
+
+void remove_service(Zypper & zypper, const Service & service)
+{
+ RepoManager manager(zypper.globalOpts().rm_options);
+
+ manager.removeService(service);
+ zypper.out().info(boost::str(
+ format(_("Service '%s' has been removed.")) % service.name()));
+ MIL << format("Service '%s' has been removed.") % service.name() << endl;
+}
+
+// ---------------------------------------------------------------------------
+
+void refresh_services(Zypper & zypper)
+{
+ MIL << "going to refresh services" << endl;
+
+ RepoManager manager(zypper.globalOpts().rm_options);
+
+ list<Service> services;
+ try
+ {
+ services.insert(services.end(), manager.serviceBegin(),
manager.serviceEnd());
+ }
+ catch (const Exception & e)
+ {
+ ZYPP_CAUGHT(e);
+ zypper.out().error(e, _("Error reading services:"));
+ zypper.setExitCode(ZYPPER_EXIT_ERR_ZYPP);
+ return;
+ }
+
+ for_(sit, services.begin(), services.end())
+ {
+ Service s = *sit;
+
+ try
+ {
+ zypper.out().info(str::form(_("Refreshing service '%s'."),
s.name().c_str()));
+ manager.refreshService(s);
+ }
+ catch (const MediaException & e)
+ {
+ ZYPP_CAUGHT(e);
+ zypper.out().error(e,
+ str::form(
+ _("Problem downloading the repository index file for service '%s':"),
+ s.name().c_str()),
+ _("Check if the URI is valid and accessible."));
+ zypper.setExitCode(ZYPPER_EXIT_ERR_ZYPP);
+ return; //! \todo continue with the next service
+ }
+ }
+}
+
+// ---------------------------------------------------------------------------
+
+bool match_service(Zypper & zypper, string str, Service * service)
+{
+ RepoManager manager(zypper.globalOpts().rm_options);
+ list<Service> known;
+ known.insert(known.end(), manager.serviceBegin(), manager.serviceEnd());
+ bool found = false;
+
+ unsigned int number = 1; // repo number
+ for (list<Service>::const_iterator known_it = known.begin();
+ known_it != known.end(); ++known_it, ++number)
+ {
+ unsigned int tmp = 0;
+ safe_lexical_cast (str, tmp); // try to make an int out of the string
+
+ try
+ {
+ if (known_it->alias() == str ||
+ tmp == number ||
+ known_it->url() == Url(str))
+ {
+ *service = *known_it;
+ found = true;
+ break;
+ }
+ }
+ catch(const url::UrlException &){}
+
+ } // END for all known repos
+
+ return found;
+}
+
+// ---------------------------------------------------------------------------
+
+// ---------------------------------------------------------------------------

void load_resolvables(Zypper & zypper)
{
@@ -1830,74 +2167,6 @@

// ---------------------------------------------------------------------------

-/*
-//! rename a source, identified in any way: alias, url, id
-void rename_source( const std::string& anystring, const std::string& newalias )
-{
- cerr_vv << "Constructing SourceManager" << endl;
- SourceManager_Ptr manager = SourceManager::sourceManager();
- cerr_vv << "Restoring SourceManager" << endl;
- manager->restore (gSettings.root_dir, true use_cache*//*);
-
- Source_Ref src;
-
- SourceManager::SourceId sid = 0;
- safe_lexical_cast (anystring, sid);
- if (sid > 0) {
- try {
- src = manager->findSource (sid);
- }
- catch (const Exception & ex) {
- ZYPP_CAUGHT (ex);
- // boost::format: %s is fine regardless of the actual type :-)
- cerr << format (_("Source %s not found.")) % sid << endl;
- }
- }
- else {
- bool is_url = false;
- if (looks_like_url (anystring)) {
- is_url = true;
- cerr_vv << "Looks like a URI" << endl;
-
- Url url;
- try {
- url = Url (anystring);
- }
- catch ( const Exception & excpt_r ) {
- ZYPP_CAUGHT( excpt_r );
- cerr << _("URI is invalid: ") << excpt_r.asUserString() << endl;
- }
- if (url.isValid ()) {
- try {
- src = manager->findSourceByUrl (url);
- }
- catch (const Exception & ex) {
- ZYPP_CAUGHT (ex);
- cerr << format (_("Source %s not found.")) % url.asString() << endl;
- }
- }
- }
-
- if (!is_url) {
- try {
- src = manager->findSource (anystring);
- }
- catch (const Exception & ex) {
- ZYPP_CAUGHT (ex);
- cerr << format (_("Source %s not found.")) % anystring << endl;
- }
- }
- }
-
- if (src) {
- // getting Source_Ref is useless if we only can use an id
- manager->renameSource (src.numericId (), newalias);
- }
-
- cerr_vv << "Storing source data" << endl;
- manager->store( gSettings.root_dir, true metadata_cache*//* );
-}
-*/
// ----------------------------------------------------------------------------

// #217028

Modified: trunk/zypper/src/repos.h
URL:
http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/repos.h?rev=10670&r1=10669&r2=10670&view=diff
==============================================================================
--- trunk/zypper/src/repos.h (original)
+++ trunk/zypper/src/repos.h Sun Jul 27 14:30:52 2008
@@ -1,21 +1,24 @@
+/*---------------------------------------------------------------------------*\
+ ____ _ _ __ _ __ ___ _ _
+ |_ / || | '_ \ '_ \/ -_) '_|
+ /__|\_, | .__/ .__/\___|_|
+ |__/|_| |_|
+\*---------------------------------------------------------------------------*/
+
#ifndef ZMART_SOURCES_H
#define ZMART_SOURCES_H

-#include <boost/logic/tribool.hpp>
+//#include <boost/logic/tribool.hpp>

#include "zypp/Url.h"
#include "zypp/RepoInfo.h"
+#include "zypp/Service.h"

#include "Zypper.h"

#define TMP_RPM_REPO_ALIAS "_tmpRPMcache_"

/**
- * Initialize rpm database on target, if not already initialized.
- */
-void init_target(Zypper & zypper);
-
-/**
* The same as \ref init_repos(), but allows to specify repos to initialize.
*
* \param zypper The zypper instance.
@@ -134,6 +137,27 @@
*/
void modify_repos_by_option( Zypper & zypper );

+
+void list_services(Zypper & zypper);
+
+void add_service(Zypper & zypper, const zypp::Service & service);
+
+void add_service_by_url( Zypper & zypper,
+ const zypp::Url & url, const std::string & alias,
+ const std::string & type,
+ boost::tribool enabled = boost::indeterminate);
+
+void remove_service(Zypper & zypper, const zypp::Service & service);
+
+void refresh_services(Zypper & zypper);
+
+bool match_service(Zypper & zypper, std::string str, zypp::Service * service);
+
+/**
+ * Initialize rpm database on target, if not already initialized.
+ */
+void init_target(Zypper & zypper);
+
/**
* Load both repository and target resolvables.
*

Modified: trunk/zypper/src/utils/messages.cc
URL:
http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/utils/messages.cc?rev=10670&r1=10669&r2=10670&view=diff
==============================================================================
--- trunk/zypper/src/utils/messages.cc (original)
+++ trunk/zypper/src/utils/messages.cc Sun Jul 27 14:30:52 2008
@@ -59,3 +59,13 @@
out.warning(zypp::str::form(
_("The '--%s' option has currently no effect."), longoption_str.c_str()));
}
+
+// ----------------------------------------------------------------------------
+
+void print_usage(Out & out, const string & command_help)
+{
+ ostringstream s;
+ s << _("Usage") << ':' << endl;
+ s << command_help;
+ out.info(s.str());
+}

Modified: trunk/zypper/src/utils/messages.h
URL:
http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/utils/messages.h?rev=10670&r1=10669&r2=10670&view=diff
==============================================================================
--- trunk/zypper/src/utils/messages.h (original)
+++ trunk/zypper/src/utils/messages.h Sun Jul 27 14:30:52 2008
@@ -24,5 +24,7 @@
/** Say you miss a required argument and print command help */
void report_required_arg_missing(Out & out, const std::string & cmd_help);

+void print_usage(Out & out, const std::string & command_help);
+

#endif /*MESSAGES_H_*/

Modified: trunk/zypper/src/utils/misc.h
URL:
http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/utils/misc.h?rev=10670&r1=10669&r2=10670&view=diff
==============================================================================
--- trunk/zypper/src/utils/misc.h (original)
+++ trunk/zypper/src/utils/misc.h Sun Jul 27 14:30:52 2008
@@ -15,6 +15,7 @@
#include "zypp/Resolvable.h"
#include "zypp/Pathname.h"
#include "zypp/RepoInfo.h"
+#include "zypp/Service.h"

#include "Zypper.h"

@@ -69,15 +70,25 @@
const zypp::ResKind & kind =
zypp::ResKind::nokind);


-//comparator for RepoInfo set
+// comparator for RepoInfo set
class RepoInfoAliasComparator
{
- public: bool operator()(const zypp::RepoInfo &a, const zypp::RepoInfo& b)
+ public: bool operator()(const zypp::RepoInfo & a, const zypp::RepoInfo & b)
{
- return a.alias()<b.alias();
+ return a.alias() < b.alias();
}
};

+// comparator for Service set
+class ServiceAliasComparator
+{
+ public: bool operator()(const zypp::Service & a, const zypp::Service & b)
+ {
+ return a.alias() < b.alias();
+ }
+};
+
+
/**
* checks name for .repo string
*/

--
To unsubscribe, e-mail: zypp-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: zypp-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages