- zypper repos --export <FILE|-> added (FATE #301744)
authorJan Kupec <jkupec@suse.cz>
Tue, 14 Aug 2007 17:19:38 +0000 (17:19 +0000)
committerJan Kupec <jkupec@suse.cz>
Tue, 14 Aug 2007 17:19:38 +0000 (17:19 +0000)
doc/zypper.8
src/zypper-sources.cc
src/zypper.cc

index d026a02..a098063 100644 (file)
@@ -251,9 +251,13 @@ Ignore query string in the URI
 .B repos (lr)
 List all defined repositories.
 .IP
-Following data are printed for each source found: Enabled (whether the source is enabled), Refresh (whether autorefresh is enabled for the source), Type (YaST, YUM, ...), Name, and URI.
-.IP
-rug compatibility mode: if \fI-r\fR global option is set, zypper doesn't include 'Enabled' and 'Refresh' columns and prints rug's 'Status' column with values "Active" or "Disabled" instead.
+Following data are printed for each repository found: Enabled (whether the repository is enabled), Refresh (whether autorefresh is enabled for the repository), Type (YaST, YUM, Plaindir), Name, and URI.
+.TP
+.I \-e, \-\-export <FILE|->
+This option causes zypper to write repository definition of all defined
+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
 .B renamerepo (nr) <alias> <new-alias>
@@ -318,7 +322,7 @@ Terse output for machine consumption.
 Specifies table style to use. Table style is identified by an integer number. TODO
 .TP
 .I \-r, \-\-rug\-compatible
-Turns on rug compatibility. See compatibility notes next to affected commands.
+Turns on rug compatibility. See section COMPATIBILITY WITH RUG for details.
 .TP
 .I \-n, \-\-non\-interactive
 Switches to non-interactive mode. In this mode zypper doesn't ask user to type answers to various prompts, but uses default answers automatically. The behaviour of this option is somewhat different than that of options like '--yes', since zypper can answer different answers to different questions. The answers also depend on other options like '--no-gpg-checks'.
@@ -381,8 +385,9 @@ Returned after a successfull installation of a patch which requires restart of t
 .SH "COMPATIBILITY WITH RUG"
 .LP
 zypper is designed to be compatible with rug, which is a command\-line interface to the ZENworks Linux Management (ZLM) agent. Compared to rug, zypper does not need the ZLM daemon to run, and is intented to provide more and improved functionality. Following is a list of zypper-rug command aliases, supported rug command line options, and compatibility notes. See also compatibility notes in descriptions of zypper commands. 
+.LP
+To enable rug compatible behaviour, use the \-r or \-\-rug\-compatible global option with each command.
 
-.LP 
 .SS Service Management Commands
 .LP
 ZENworks distinguishes services and catalogs. A service is
@@ -403,6 +408,10 @@ zypper removerepo (rr)
 .I rug service-list (sl)
 zypper repos (lr)
 
+.IP
+ zypper doesn't include 'Enabled' and 'Refresh' columns and prints rug's 'Status' column with values "Active" or "Disabled" instead.
+
+
 .SS Package Management Commands
 
 .TP
index be3c58e..9f662e0 100644 (file)
@@ -296,6 +296,18 @@ static void print_repo_list( const std::list<zypp::RepoInfo> &repos )
 
 // ----------------------------------------------------------------------------
 
+void print_repos_to(const std::list<zypp::RepoInfo> &repos, ostream & out)
+{
+  for (std::list<RepoInfo>::const_iterator it = repos.begin();
+       it !=  repos.end(); ++it)
+  {
+    it->dumpRepoOn(out);
+    out << endl;
+  }
+}
+
+// ----------------------------------------------------------------------------
+
 void list_repos()
 {
   RepoManager manager;
@@ -313,7 +325,40 @@ void list_repos()
     exit(ZYPPER_EXIT_ERR_ZYPP);
   }
 
-  print_repo_list(repos);
+  // 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)
+      {
+        cerr << format(_("Can't open %s for writing. Maybe you don't have write permissions?"))
+            % file.asString() << endl;
+        exit(ZYPPER_EXIT_ERR_INVALID_ARGS);
+      }
+      else
+      {
+        print_repos_to(repos, stream);
+        cout << format(
+            _("Repositories have been successfully exported to %s."))
+            % (file.absolute() ? file.asString() : file.asString().substr(2))
+          << endl;
+      }
+    }
+  }
+  // print repo list as table
+  else
+    print_repo_list(repos);
 }
 
 // ----------------------------------------------------------------------------
index 0d6526f..c746d61 100644 (file)
@@ -21,7 +21,6 @@
 #include <boost/logic/tribool.hpp>
 
 #include <zypp/base/Logger.h>
-#include <zypp/zypp_detail/ZYppReadOnlyHack.h>
 #include <zypp/repo/RepoException.h>
 
 #include "zypper.h"
@@ -359,6 +358,7 @@ int one_command(int argc, char **argv)
   }
   else if (command == ZypperCommand::LIST_REPOS) {
     static struct option service_list_options[] = {
+      {"export", required_argument, 0, 'e'},
       {"help", no_argument, 0, 'h'},
       {0, 0, 0, 0}
     };
@@ -368,7 +368,8 @@ int one_command(int argc, char **argv)
       "\n"
       "List all defined repositories.\n"
       "\n"
-      "This command has no additional options.\n"
+      "  Command options:\n"
+      "-e, --export <FILE.repo>  Export all defined repositories as a single local .repo file\n"
     );
   }
   else if (command == ZypperCommand::REMOVE_REPO) {
@@ -713,8 +714,8 @@ int one_command(int argc, char **argv)
 
   // here come commands that need the lock
   try {
-    if (command == ZypperCommand::LIST_REPOS)
-      zypp_readonly_hack::IWantIt (); // #247001
+//    if (command == ZypperCommand::LIST_REPOS)
+//      zypp_readonly_hack::IWantIt (); // #247001
 
     God = zypp::getZYpp();
   }