aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-07-30 21:41:42 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-07-30 21:41:42 +0000
commit056a2bf29d376ae6eb39a7c1f36e95eb227f649e (patch)
tree5ba50b26849a3a0df96e385af2214a2ce4b3c45b
parent824aa9bd2263b57453fa896143bc100137b851a3 (diff)
downloadpaludis-056a2bf29d376ae6eb39a7c1f36e95eb227f649e.tar.gz
paludis-056a2bf29d376ae6eb39a7c1f36e95eb227f649e.tar.xz
Make a SyncTask. Use it.
-rw-r--r--paludis/tasks/Makefile.am6
-rw-r--r--paludis/tasks/sync_task.cc104
-rw-r--r--paludis/tasks/sync_task.hh72
-rw-r--r--src/gtkpaludis/Makefile.am1
-rw-r--r--src/gtkpaludis/browse_tree.cc8
-rw-r--r--src/gtkpaludis/gtkpaludis.cc5
-rw-r--r--src/gtkpaludis/main_window.hh9
-rw-r--r--src/gtkpaludis/sync.cc100
-rw-r--r--src/gtkpaludis/sync.hh50
-rw-r--r--src/paludis/sync.cc166
10 files changed, 427 insertions, 94 deletions
diff --git a/paludis/tasks/Makefile.am b/paludis/tasks/Makefile.am
index dbbb445..bcb445b 100644
--- a/paludis/tasks/Makefile.am
+++ b/paludis/tasks/Makefile.am
@@ -22,9 +22,11 @@ lib_LIBRARIES = libpaludistasks.a
paludis_tasks_includedir = $(includedir)/paludis/tasks
paludis_tasks_include_HEADERS = \
install_task.hh \
- uninstall_task.hh
+ uninstall_task.hh \
+ sync_task.hh
libpaludistasks_a_SOURCES = $(paludis_tasks_include_HEADERS) \
install_task.cc \
- uninstall_task.cc
+ uninstall_task.cc \
+ sync_task.cc
diff --git a/paludis/tasks/sync_task.cc b/paludis/tasks/sync_task.cc
new file mode 100644
index 0000000..80e34ee
--- /dev/null
+++ b/paludis/tasks/sync_task.cc
@@ -0,0 +1,104 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaran.mccreesh@blueyonder.co.uk>
+ *
+ * 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 "sync_task.hh"
+#include <paludis/environment.hh>
+#include <paludis/syncer.hh>
+#include <list>
+
+using namespace paludis;
+
+namespace paludis
+{
+ template<>
+ struct Implementation<SyncTask> :
+ InternalCounted<Implementation<SyncTask> >
+ {
+ Environment * const env;
+ std::list<RepositoryName> targets;
+
+ Implementation(Environment * const e) :
+ env(e)
+ {
+ }
+ };
+}
+
+SyncTask::SyncTask(Environment * const env) :
+ PrivateImplementationPattern<SyncTask>(new Implementation<SyncTask>(env))
+{
+}
+
+SyncTask::~SyncTask()
+{
+}
+
+void
+SyncTask::add_target(const std::string & t)
+{
+ Context context("When adding sync target '" + t + "':");
+ _imp->targets.push_back(RepositoryName(t));
+}
+
+void
+SyncTask::execute()
+{
+ Context context("When executing sync task:");
+
+ if (_imp->targets.empty())
+ for (PackageDatabase::RepositoryIterator r(_imp->env->package_database()->begin_repositories()),
+ r_end(_imp->env->package_database()->end_repositories()) ; r != r_end ; ++r)
+ _imp->targets.push_back((*r)->name());
+
+ _imp->env->perform_hook(Hook("sync_all_pre")("TARGETS", join(_imp->targets.begin(),
+ _imp->targets.end(), " ")));
+ on_sync_all_pre();
+
+ for (std::list<RepositoryName>::const_iterator r(_imp->targets.begin()), r_end(_imp->targets.end()) ;
+ r != r_end ; ++r)
+ {
+ Context context_local("When syncing repository '" + stringify(*r) + "':");
+
+ _imp->env->perform_hook(Hook("sync_pre")("TARGET", stringify(*r)));
+ on_sync_pre(*r);
+
+ try
+ {
+ Repository::ConstPointer rr(_imp->env->package_database()->fetch_repository(*r));
+
+ if (rr->get_interface<repo_syncable>() && rr->get_interface<repo_syncable>()->sync())
+ on_sync_succeed(*r);
+ else
+ on_sync_skip(*r);
+ }
+ catch (const SyncFailedError & e)
+ {
+ _imp->env->perform_hook(Hook("sync_fail")("TARGET", stringify(*r)));
+ on_sync_fail(*r, e);
+ }
+
+ on_sync_post(*r);
+ _imp->env->perform_hook(Hook("sync_post")("TARGET", stringify(*r)));
+ }
+
+ on_sync_all_post();
+ _imp->env->perform_hook(Hook("sync_all_post")("TARGETS", join(_imp->targets.begin(),
+ _imp->targets.end(), " ")));
+}
+
diff --git a/paludis/tasks/sync_task.hh b/paludis/tasks/sync_task.hh
new file mode 100644
index 0000000..7bd7186
--- /dev/null
+++ b/paludis/tasks/sync_task.hh
@@ -0,0 +1,72 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaran.mccreesh@blueyonder.co.uk>
+ *
+ * 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_TASKS_SYNC_TASK_HH
+#define PALUDIS_GUARD_PALUDIS_TASKS_SYNC_TASK_HH 1
+
+#include <paludis/util/instantiation_policy.hh>
+#include <paludis/util/private_implementation_pattern.hh>
+#include <paludis/dep_list.hh>
+
+namespace paludis
+{
+ class Environment;
+ class SyncFailedError;
+
+ class SyncTask :
+ PrivateImplementationPattern<SyncTask>,
+ InstantiationPolicy<SyncTask, instantiation_method::NonCopyableTag>
+ {
+ public:
+ ///\name Basic operations
+ ///\{
+
+ SyncTask(Environment * const env);
+ virtual ~SyncTask();
+
+ ///\}
+
+ ///\name Add targets
+ ///\{
+
+ void add_target(const std::string &);
+
+ ///\}
+
+ ///\name Event callbacks
+ ///\{
+
+ virtual void on_sync_all_pre() = 0;
+ virtual void on_sync_pre(const RepositoryName &) = 0;
+ virtual void on_sync_post(const RepositoryName &) = 0;
+ virtual void on_sync_skip(const RepositoryName &) = 0;
+ virtual void on_sync_fail(const RepositoryName &, const SyncFailedError &) = 0;
+ virtual void on_sync_succeed(const RepositoryName &) = 0;
+ virtual void on_sync_all_post() = 0;
+
+ ///\}
+
+ /**
+ * Run the task.
+ */
+ void execute();
+ };
+}
+
+#endif
diff --git a/src/gtkpaludis/Makefile.am b/src/gtkpaludis/Makefile.am
index 88c442d..3607d60 100644
--- a/src/gtkpaludis/Makefile.am
+++ b/src/gtkpaludis/Makefile.am
@@ -20,6 +20,7 @@ gtkpaludis_SOURCES = \
information_tree.cc information_tree.hh \
message_window.cc message_window.hh \
main_window.cc main_window.hh \
+ sync.cc sync.hh \
gtkpaludis.cc
gtkpaludis_LDADD = \
diff --git a/src/gtkpaludis/browse_tree.cc b/src/gtkpaludis/browse_tree.cc
index 7fd7d92..b124efa 100644
--- a/src/gtkpaludis/browse_tree.cc
+++ b/src/gtkpaludis/browse_tree.cc
@@ -20,6 +20,7 @@
#include "browse_tree.hh"
#include "information_tree.hh"
#include "main_window.hh"
+#include "sync.hh"
#include <gtkmm/treestore.h>
#include <gtkmm/menu.h>
@@ -271,10 +272,9 @@ namespace
virtual void sync() const
{
- Repository::ConstPointer repo(
- DefaultEnvironment::get_instance()->package_database()->fetch_repository(_r));
- if (repo->get_interface<repo_syncable>())
- repo->get_interface<repo_syncable>()->sync();
+ OurSyncTask task;
+ task.add_target(stringify(_r));
+ task.execute();
}
};
diff --git a/src/gtkpaludis/gtkpaludis.cc b/src/gtkpaludis/gtkpaludis.cc
index 02156e9..5a87031 100644
--- a/src/gtkpaludis/gtkpaludis.cc
+++ b/src/gtkpaludis/gtkpaludis.cc
@@ -187,9 +187,8 @@ main(int argc, char * argv[])
if (! gui_kit.initialized())
throw GtkInitFailed();
-
- MainWindow main_window;
- TryMain::run(main_window);
+
+ TryMain::run(*MainWindow::get_instance());
}
}
catch (const DoVersion &)
diff --git a/src/gtkpaludis/main_window.hh b/src/gtkpaludis/main_window.hh
index 90a5c31..22ddba6 100644
--- a/src/gtkpaludis/main_window.hh
+++ b/src/gtkpaludis/main_window.hh
@@ -22,17 +22,22 @@
#include <gtkmm/window.h>
#include <paludis/util/private_implementation_pattern.hh>
+#include <paludis/util/instantiation_policy.hh>
namespace paludis
{
class MainWindow :
public Gtk::Window,
- private PrivateImplementationPattern<MainWindow>
+ private PrivateImplementationPattern<MainWindow>,
+ public InstantiationPolicy<MainWindow, instantiation_method::SingletonAsNeededTag>
{
- public:
+ friend class InstantiationPolicy<MainWindow, instantiation_method::SingletonAsNeededTag>;
+
+ private:
MainWindow();
virtual ~MainWindow();
+ public:
void set_children_sensitive(bool value);
};
}
diff --git a/src/gtkpaludis/sync.cc b/src/gtkpaludis/sync.cc
new file mode 100644
index 0000000..f8fd68f
--- /dev/null
+++ b/src/gtkpaludis/sync.cc
@@ -0,0 +1,100 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaran.mccreesh@blueyonder.co.uk>
+ *
+ * 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 "sync.hh"
+#include "main_window.hh"
+
+#include <paludis/default_environment.hh>
+#include <paludis/util/log.hh>
+#include <paludis/syncer.hh>
+
+#include <list>
+
+using namespace paludis;
+
+namespace paludis
+{
+ template<>
+ struct Implementation<OurSyncTask> :
+ InternalCounted<Implementation<OurSyncTask> >
+ {
+ std::list<std::string> failed_repositories;
+ };
+}
+
+OurSyncTask::OurSyncTask() :
+ SyncTask(DefaultEnvironment::get_instance()),
+ PrivateImplementationPattern<OurSyncTask>(new Implementation<OurSyncTask>)
+{
+}
+
+OurSyncTask::~OurSyncTask()
+{
+}
+
+void
+OurSyncTask::on_sync_all_pre()
+{
+}
+
+void
+OurSyncTask::on_sync_pre(const RepositoryName &)
+{
+}
+
+void
+OurSyncTask::on_sync_post(const RepositoryName &)
+{
+}
+
+void
+OurSyncTask::on_sync_skip(const RepositoryName &)
+{
+}
+
+void
+OurSyncTask::on_sync_succeed(const RepositoryName &)
+{
+}
+
+void
+OurSyncTask::on_sync_fail(const RepositoryName & r, const SyncFailedError &)
+{
+ Log::get_instance()->message(ll_warning, lc_no_context, "Sync of repository '"
+ + stringify(r) + "' failed");
+ PrivateImplementationPattern<OurSyncTask>::_imp->failed_repositories.push_back(stringify(r));
+}
+
+void
+OurSyncTask::on_sync_all_post()
+{
+}
+
+OurSyncTask::FailedIterator
+OurSyncTask::begin_failed() const
+{
+ return FailedIterator(PrivateImplementationPattern<OurSyncTask>::_imp->failed_repositories.begin());
+}
+
+OurSyncTask::FailedIterator
+OurSyncTask::end_failed() const
+{
+ return FailedIterator(PrivateImplementationPattern<OurSyncTask>::_imp->failed_repositories.end());
+}
+
diff --git a/src/gtkpaludis/sync.hh b/src/gtkpaludis/sync.hh
new file mode 100644
index 0000000..0028e53
--- /dev/null
+++ b/src/gtkpaludis/sync.hh
@@ -0,0 +1,50 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaran.mccreesh@blueyonder.co.uk>
+ *
+ * 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_SRC_GTKPALUDIS_SYNC_HH
+#define PALUDIS_GUARD_SRC_GTKPALUDIS_SYNC_HH 1
+
+#include <paludis/tasks/sync_task.hh>
+#include <paludis/util/private_implementation_pattern.hh>
+
+namespace paludis
+{
+ class OurSyncTask :
+ public SyncTask,
+ private PrivateImplementationPattern<OurSyncTask>
+ {
+ public:
+ OurSyncTask();
+ ~OurSyncTask();
+
+ virtual void on_sync_all_pre();
+ virtual void on_sync_pre(const RepositoryName &);
+ virtual void on_sync_post(const RepositoryName &);
+ virtual void on_sync_skip(const RepositoryName &);
+ virtual void on_sync_fail(const RepositoryName &, const SyncFailedError &);
+ virtual void on_sync_succeed(const RepositoryName &);
+ virtual void on_sync_all_post();
+
+ typedef libwrapiter::ForwardIterator<OurSyncTask, const std::string> FailedIterator;
+ FailedIterator begin_failed() const;
+ FailedIterator end_failed() const;
+ };
+}
+
+#endif
diff --git a/src/paludis/sync.cc b/src/paludis/sync.cc
index e511d73..8a87f1c 100644
--- a/src/paludis/sync.cc
+++ b/src/paludis/sync.cc
@@ -19,111 +19,111 @@
#include "colour.hh"
#include "sync.hh"
-#include <functional>
+#include <paludis/tasks/sync_task.hh>
+#include <paludis/default_environment.hh>
+#include <paludis/syncer.hh>
#include <iomanip>
#include <iostream>
-#include <paludis/paludis.hh>
#include <string>
-#include <set>
/** \file
* Handle the --sync action for the main paludis program.
*/
-namespace p = paludis;
+using namespace paludis;
using std::cerr;
+using std::cout;
+using std::endl;
namespace
{
- int do_one_sync(p::Repository::ConstPointer r)
+ class OurSyncTask :
+ public SyncTask
+ {
+ private:
+ int _return_code;
+
+ public:
+ OurSyncTask() :
+ SyncTask(DefaultEnvironment::get_instance()),
+ _return_code(0)
+ {
+ }
+
+ virtual void on_sync_all_pre();
+ virtual void on_sync_pre(const RepositoryName &);
+ virtual void on_sync_post(const RepositoryName &);
+ virtual void on_sync_skip(const RepositoryName &);
+ virtual void on_sync_fail(const RepositoryName &, const SyncFailedError &);
+ virtual void on_sync_succeed(const RepositoryName &);
+ virtual void on_sync_all_post();
+
+ int return_code() const
+ {
+ return _return_code;
+ }
+ };
+
+ void
+ OurSyncTask::on_sync_all_pre()
{
- int return_code(0);
-
- p::Context context("When performing sync action for '"
- + p::stringify(r->name()) + "': ");
- p::Environment * const env(p::DefaultEnvironment::get_instance());
-
- std::cout << colour(cl_heading, "Sync " + p::stringify(r->name())) << std::endl;
- try
- {
- cerr << xterm_title("Syncing " + p::stringify(r->name()));
- if (r->get_interface<p::repo_syncable>() && r->get_interface<p::repo_syncable>()->sync())
- std::cout << "Sync " << r->name() << " completed" << std::endl;
- else
- std::cout << "Sync " << r->name() << " skipped" << std::endl;
- }
- catch (const p::SyncFailedError & e)
- {
- return_code |= 1;
- std::cout << std::endl;
- std::cerr << "Sync error:" << std::endl;
- std::cerr << " * " << e.backtrace("\n * ") << e.message() << std::endl;
- std::cerr << std::endl;
- std::cout << "Sync " << r->name() << " failed" << std::endl;
- env->perform_hook(p::Hook("sync_fail")("TARGET", stringify(r->name())));
- }
-
- return return_code;
}
-}
-int do_sync()
-{
- int return_code(0);
+ void
+ OurSyncTask::on_sync_pre(const RepositoryName & r)
+ {
+ cout << colour(cl_heading, "Sync " + stringify(r)) << endl;
+ cerr << xterm_title("Syncing " + stringify(r));
+ }
+
+ void
+ OurSyncTask::on_sync_post(const RepositoryName &)
+ {
+ }
- p::Context context("When performing sync action from command line:");
- p::Environment * const env(p::DefaultEnvironment::get_instance());
+ void
+ OurSyncTask::on_sync_skip(const RepositoryName & r)
+ {
+ cout << "Sync " << r << " skipped" << endl;
+ }
- if (CommandLine::get_instance()->empty())
+ void
+ OurSyncTask::on_sync_succeed(const RepositoryName & r)
{
- std::string targets;
- for (p::PackageDatabase::RepositoryIterator r(env->package_database()->begin_repositories()),
- r_end(env->package_database()->end_repositories()) ; r != r_end ; ++r)
- targets.append(stringify((*r)->name()) + " ");
-
- env->perform_hook(p::Hook("sync_all_pre")("TARGETS", targets));
- for (p::PackageDatabase::RepositoryIterator r(env->package_database()->begin_repositories()),
- r_end(env->package_database()->end_repositories()) ; r != r_end ; ++r)
- {
- env->perform_hook(p::Hook("sync_pre")("TARGET", stringify((*r)->name())));
- return_code |= do_one_sync(*r);
- env->perform_hook(p::Hook("sync_post")("TARGET", stringify((*r)->name())));
- }
- env->perform_hook(p::Hook("sync_all_post")("TARGETS", targets));
+ cout << "Sync " << r << " completed" << endl;
}
- else
+
+ void
+ OurSyncTask::on_sync_fail(const RepositoryName & r, const SyncFailedError & e)
{
- std::set<p::RepositoryName> repo_names;
- std::copy(CommandLine::get_instance()->begin_parameters(),
- CommandLine::get_instance()->end_parameters(),
- p::create_inserter<p::RepositoryName>(std::inserter(
- repo_names, repo_names.begin())));
-
- env->perform_hook(p::Hook("sync_all_pre")("TARGETS", p::join(
- CommandLine::get_instance()->begin_parameters(),
- CommandLine::get_instance()->end_parameters(), " ")));
- for (std::set<p::RepositoryName>::iterator r(repo_names.begin()), r_end(repo_names.end()) ;
- r != r_end ; ++r)
- {
- try
- {
- env->perform_hook(p::Hook("sync_pre")("TARGET", stringify(*r)));
- return_code |= do_one_sync(env->package_database()->fetch_repository(*r));
- env->perform_hook(p::Hook("sync_post")("TARGET", stringify(*r)));
- }
- catch (const p::NoSuchRepositoryError & e)
- {
- return_code |= 1;
- std::cerr << "No such repository '" << *r << "'" << std::endl;
- std::cout << "Sync " << *r << " failed" << std::endl;
- }
- }
- env->perform_hook(p::Hook("sync_all_post")("TARGETS", p::join(
- CommandLine::get_instance()->begin_parameters(),
- CommandLine::get_instance()->end_parameters(), " ")));
+ _return_code |= 1;
+ cout << endl;
+ cerr << "Sync error:" << endl;
+ cerr << " * " << e.backtrace("\n * ") << e.message() << endl;
+ cerr << endl;
+ cout << "Sync " << r << " failed" << endl;
}
- return return_code;
+ void
+ OurSyncTask::on_sync_all_post()
+ {
+ cout << endl;
+ }
+}
+
+int do_sync()
+{
+ Context context("When performing sync action from command line:");
+
+ OurSyncTask task;
+
+ for (CommandLine::ParametersIterator q(CommandLine::get_instance()->begin_parameters()),
+ q_end(CommandLine::get_instance()->end_parameters()) ; q != q_end ; ++q)
+ task.add_target(*q);
+
+ task.execute();
+
+ return task.return_code();
}