aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-04-05 12:18:54 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-04-05 12:18:54 +0000
commitaaf74164232371436e46749da85db5d7320f9cc8 (patch)
tree9cf283cb9208f238a984b675fa11c16645380b78
parent18375286ec27c59665c553eddc0c439c2be12ef8 (diff)
downloadpaludis-aaf74164232371436e46749da85db5d7320f9cc8.tar.gz
paludis-aaf74164232371436e46749da85db5d7320f9cc8.tar.xz
VCise sync
-rw-r--r--paludis/files.m41
-rw-r--r--paludis/name.cc5
-rw-r--r--paludis/portage_repository.cc17
-rw-r--r--paludis/syncer.cc67
-rw-r--r--paludis/syncer.hh66
-rw-r--r--src/Makefile.am12
-rw-r--r--src/applets.cc37
-rw-r--r--src/applets.hh8
-rw-r--r--src/command_line.cc2
-rw-r--r--src/command_line.hh6
-rw-r--r--src/paludis.cc18
-rw-r--r--src/sync.cc8
12 files changed, 229 insertions, 18 deletions
diff --git a/paludis/files.m4 b/paludis/files.m4
index fcd7120..e24845e 100644
--- a/paludis/files.m4
+++ b/paludis/files.m4
@@ -29,6 +29,7 @@ add(`package_database', `hh', `cc', `test')
add(`paludis', `hh', `cc')
add(`portage_repository', `hh', `cc')
add(`repository', `hh', `cc')
+add(`syncer', `hh', `cc')
add(`test_environment', `hh', `cc')
add(`vdb_repository', `hh', `cc')
add(`version_metadata', `hh', `cc')
diff --git a/paludis/name.cc b/paludis/name.cc
index a025c63..29a071c 100644
--- a/paludis/name.cc
+++ b/paludis/name.cc
@@ -146,6 +146,11 @@ PackageNamePartValidator::validate(const std::string & s)
Context c("When validating package name part '" + s + "':");
throw PackageNamePartError(s);
}
+
+ if ((p + 1 < s.length()) && (s[p] == '-') &&
+ (std::string::npos != number_chars.find(s[p + 1])))
+ if (std::string::npos == s.find_first_not_of(number_chars, p + 1))
+ throw PackageNamePartError(s);
}
}
diff --git a/paludis/portage_repository.cc b/paludis/portage_repository.cc
index cacaf86..54caf69 100644
--- a/paludis/portage_repository.cc
+++ b/paludis/portage_repository.cc
@@ -27,6 +27,7 @@
#include <paludis/match_package.hh>
#include <paludis/package_database.hh>
#include <paludis/portage_repository.hh>
+#include <paludis/syncer.hh>
#include <paludis/util/iterator.hh>
#include <paludis/util/dir_iterator.hh>
#include <paludis/util/fs_entry.hh>
@@ -1192,19 +1193,17 @@ PortageRepository::do_system_packages() const
bool
PortageRepository::do_sync() const
{
+ Context context("When syncing repository '" + stringify(name()) + "':");
+
if (_imp->sync.empty())
return false;
- if (0 != _imp->sync.compare(0, 8, "rsync://"))
- throw InternalError(PALUDIS_HERE, "todo"); /// \todo fixme
-
- std::string cmd("rsync --recursive --links --safe-links --perms --times "
- "--compress --force --whole-file --delete --delete-after --stats "
- "--timeout=180 --exclude=/distfiles --exclude=/packages --progress "
- "'" + stringify(_imp->sync) + "' '" + stringify(_imp->location) + "/'");
+ std::string::size_type p(_imp->sync.find("://"));
+ if (std::string::npos == p)
+ throw InternalError(PALUDIS_HERE, "todo: no protocol for sync"); /// \todo fixme
- if (0 != run_command(cmd))
- throw InternalError(PALUDIS_HERE, "todo"); /// \todo fixme
+ SyncerMaker::get_instance()->find_maker(_imp->sync.substr(0, p))(
+ _imp->sync, _imp->location)->sync();
return true;
}
diff --git a/paludis/syncer.cc b/paludis/syncer.cc
new file mode 100644
index 0000000..0493745
--- /dev/null
+++ b/paludis/syncer.cc
@@ -0,0 +1,67 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaranm@gentoo.org>
+ *
+ * This file is part of the Paludis package manager. Paludis is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU General
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "syncer.hh"
+#include <paludis/util/system.hh>
+
+NoSuchSyncerError::NoSuchSyncerError(const std::string & format) throw () :
+ ConfigurationError("No such syncer for format '" + format + "'")
+{
+}
+
+namespace
+{
+ class RsyncSyncer :
+ public Syncer
+ {
+ private:
+ std::string _local;
+ std::string _remote;
+
+ protected:
+ RsyncSyncer(const std::string & local, const std::string & remote) :
+ _local(local),
+ _remote(remote)
+ {
+ }
+
+ public:
+ virtual void sync() const;
+
+ static Syncer::Pointer make(const std::string & local, const std::string & remote)
+ {
+ return Syncer::Pointer(new RsyncSyncer(local, remote));
+ }
+ };
+
+ static const SyncerMaker::RegisterMaker register_rsync_syncer("rsync", &RsyncSyncer::make);
+}
+
+void
+RsyncSyncer::sync() const
+{
+ std::string cmd("rsync --recursive --links --safe-links --perms --times "
+ "--compress --force --whole-file --delete --delete-after --stats "
+ "--timeout=180 --exclude=/distfiles --exclude=/packages --progress "
+ "'" + _remote + "' '" + _local + "/'");
+
+ if (0 != run_command(cmd))
+ throw InternalError(PALUDIS_HERE, "todo"); /// \todo fixme
+}
+
diff --git a/paludis/syncer.hh b/paludis/syncer.hh
new file mode 100644
index 0000000..cb6b969
--- /dev/null
+++ b/paludis/syncer.hh
@@ -0,0 +1,66 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaranm@gentoo.org>
+ *
+ * This file is part of the Paludis package manager. Paludis is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU General
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef PALUDIS_GUARD_PALUDIS_SYNCER_HH
+#define PALUDIS_GUARD_PALUDIS_SYNCER_HH 1
+
+#include <paludis/util/virtual_constructor.hh>
+#include <paludis/util/exception.hh>
+#include <string>
+
+using namespace paludis;
+
+namespace paludis
+{
+ class Syncer :
+ private InstantiationPolicy<Syncer, instantiation_method::NonCopyableTag>,
+ public InternalCounted<Syncer>
+ {
+ protected:
+ Syncer()
+ {
+ }
+
+ public:
+ virtual ~Syncer()
+ {
+ }
+
+ virtual void sync() const = 0;
+ };
+
+ /**
+ * Thrown if a syncer of the specified type does not exist.
+ *
+ * \ingroup Exception
+ */
+ class NoSuchSyncerError : public ConfigurationError
+ {
+ public:
+ /**
+ * Constructor.
+ */
+ NoSuchSyncerError(const std::string & format) throw ();
+ };
+
+ typedef VirtualConstructor<std::string, Syncer::Pointer (*) (const std::string &, const std::string &),
+ virtual_constructor_not_found::ThrowException<NoSuchSyncerError> > SyncerMaker;
+}
+
+#endif
diff --git a/src/Makefile.am b/src/Makefile.am
index 13df6ea..b9abd25 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,4 +1,4 @@
-CLEANFILES = *~ version_TEST
+CLEANFILES = *~ version_TEST list_sync_formats_TEST list_repository_formats_TEST
MAINTAINERCLEANFILES = Makefile.in
AM_CXXFLAGS = -I$(top_srcdir)
DEFS= \
@@ -25,8 +25,14 @@ paludis_LDADD = \
$(top_builddir)/paludis/util/libpaludisutil.a
TESTS_ENVIRONMENT = env TEST_SCRIPT_DIR="$(srcdir)/" $(SHELL) $(top_srcdir)/test/run_test.sh bash
-TESTS = version_TEST
+TESTS = version_TEST list_sync_formats_TEST list_repository_formats_TEST
-version_TEST :
+version_TEST : paludis
echo -e "#!/bin/sh\n./paludis --version" > $@
+list_sync_formats_TEST : paludis
+ echo -e "#!/bin/sh\n./paludis --list-sync-protocols" > $@
+
+list_repository_formats_TEST : paludis
+ echo -e "#!/bin/sh\n./paludis --list-repository-formats" > $@
+
diff --git a/src/applets.cc b/src/applets.cc
index be395f3..c6ab9d4 100644
--- a/src/applets.cc
+++ b/src/applets.cc
@@ -18,11 +18,13 @@
*/
#include "src/applets.hh"
+#include "src/colour.hh"
#include <functional>
#include <iomanip>
#include <iostream>
#include <paludis/paludis.hh>
#include <string>
+#include <set>
/** \file
* Handle the --has-version and --best-version actions for the main paludis
@@ -67,4 +69,39 @@ int do_best_version()
return return_code;
}
+int do_list_repository_formats()
+{
+ int return_code(1);
+
+ std::set<std::string> keys;
+ p::RepositoryMaker::get_instance()->copy_keys(std::inserter(keys, keys.begin()));
+
+ if (! keys.empty())
+ {
+ return_code = 0;
+ for (std::set<std::string>::const_iterator k(keys.begin()), k_end(keys.end()) ;
+ k != k_end ; ++k)
+ std::cout << "* " << colour(cl_package_name, *k) << std::endl;
+ }
+
+ return return_code;
+}
+
+int do_list_sync_protocols()
+{
+ int return_code(1);
+
+ std::set<std::string> keys;
+ p::SyncerMaker::get_instance()->copy_keys(std::inserter(keys, keys.begin()));
+
+ if (! keys.empty())
+ {
+ return_code = 0;
+ for (std::set<std::string>::const_iterator k(keys.begin()), k_end(keys.end()) ;
+ k != k_end ; ++k)
+ std::cout << "* " << colour(cl_package_name, *k) << std::endl;
+ }
+
+ return return_code;
+}
diff --git a/src/applets.hh b/src/applets.hh
index 442a2d4..7262aee 100644
--- a/src/applets.hh
+++ b/src/applets.hh
@@ -23,7 +23,7 @@
#include "src/command_line.hh"
/** \file
- * Declaration for the do_has_version and do_best_version functions.
+ * Declaration for small do_* functions.
*/
/// Handle --has-version.
@@ -32,5 +32,11 @@ int do_has_version();
/// Handle --best-version.
int do_best_version();
+/// Handle --list-repository-formats
+int do_list_repository_formats();
+
+/// Handle --list-sync-protocols
+int do_list_sync_protocols();
+
#endif
diff --git a/src/command_line.cc b/src/command_line.cc
index 5dbff82..cdd354c 100644
--- a/src/command_line.cc
+++ b/src/command_line.cc
@@ -29,6 +29,8 @@ CommandLine::CommandLine() :
a_list_repositories(&action_args, "list-repositories", '\0', "List available repositories"),
a_list_categories(&action_args, "list-categories", '\0', "List available categories"),
a_list_packages(&action_args, "list-packages", '\0', "List available packages"),
+ a_list_sync_protocols(&action_args, "list-sync-protocols", '\0', "List available sync protocols"),
+ a_list_repository_formats(&action_args, "list-repository-formats", '\0', "List available repository formats"),
a_has_version(&action_args, "has-version", '\0', "Check whether the specified atom is installed"),
a_best_version(&action_args, "best-version", '\0', "Display the best version of the specified atom"),
a_version(&action_args, "version", 'V', "Display program version"),
diff --git a/src/command_line.hh b/src/command_line.hh
index f91cfc3..ac707f5 100644
--- a/src/command_line.hh
+++ b/src/command_line.hh
@@ -68,6 +68,12 @@ class CommandLine :
/// --list-packages
paludis::args::SwitchArg a_list_packages;
+ /// --list-sync-protocols
+ paludis::args::SwitchArg a_list_sync_protocols;
+
+ /// --list-repository-formats
+ paludis::args::SwitchArg a_list_repository_formats;
+
/// --has-version
paludis::args::SwitchArg a_has_version;
diff --git a/src/paludis.cc b/src/paludis.cc
index bfe4853..1107b0c 100644
--- a/src/paludis.cc
+++ b/src/paludis.cc
@@ -80,6 +80,8 @@ main(int argc, char *argv[])
CommandLine::get_instance()->a_list_repositories.specified() +
CommandLine::get_instance()->a_list_categories.specified() +
CommandLine::get_instance()->a_list_packages.specified() +
+ CommandLine::get_instance()->a_list_sync_protocols.specified() +
+ CommandLine::get_instance()->a_list_repository_formats.specified() +
CommandLine::get_instance()->a_has_version.specified() +
CommandLine::get_instance()->a_best_version.specified()))
{
@@ -157,6 +159,22 @@ main(int argc, char *argv[])
return do_list_packages();
}
+ if (CommandLine::get_instance()->a_list_sync_protocols.specified())
+ {
+ if (! CommandLine::get_instance()->empty())
+ throw DoHelp("list-sync-protocols action takes no parameters");
+
+ return do_list_sync_protocols();
+ }
+
+ if (CommandLine::get_instance()->a_list_repository_formats.specified())
+ {
+ if (! CommandLine::get_instance()->empty())
+ throw DoHelp("list-repository-formats action takes no parameters");
+
+ return do_list_repository_formats();
+ }
+
if (CommandLine::get_instance()->a_has_version.specified())
{
if (1 != std::distance(CommandLine::get_instance()->begin_parameters(),
diff --git a/src/sync.cc b/src/sync.cc
index c0881ff..a2adf5e 100644
--- a/src/sync.cc
+++ b/src/sync.cc
@@ -41,17 +41,15 @@ int do_sync()
for (p::PackageDatabase::RepositoryIterator r(env->package_database()->begin_repositories()),
r_end(env->package_database()->end_repositories()) ; r != r_end ; ++r)
{
- std::cout << std::endl << "Sync " << (*r)->name() << ":" << std::endl << std::endl;
+ std::cout << colour(cl_heading, "Sync " + p::stringify((*r)->name())) << std::endl;
if ((*r)->sync())
{
- std::cout << std::endl << "Sync " << (*r)->name() << " completed"
- << std::endl << std::endl;
+ std::cout << "Sync " << (*r)->name() << " completed" << std::endl;
}
else
{
- std::cout << std::endl << "Sync " << (*r)->name() << " skipped"
- << std::endl << std::endl;
+ std::cout << "Sync " << (*r)->name() << " skipped" << std::endl;
}
}