aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Danny van Dyk <dvandyk@exherbo.org> 2007-01-22 22:17:37 +0000
committerAvatar Danny van Dyk <dvandyk@exherbo.org> 2007-01-22 22:17:37 +0000
commitb3a138365116f14fcb39d271618c4eb89010b19b (patch)
treedcad388a1cf97bc86b3a613901413613b8b4598f
parentb7b35781fc844d89a2f8902a053e6b8b36a9529e (diff)
downloadpaludis-b3a138365116f14fcb39d271618c4eb89010b19b.tar.gz
paludis-b3a138365116f14fcb39d271618c4eb89010b19b.tar.xz
Create task for finding unused packages. Add action to adjutrix for finding all unused packages in a given repository.
-rw-r--r--paludis/tasks/Makefile.am2
-rw-r--r--paludis/tasks/find_unused_packages_task.cc86
-rw-r--r--paludis/tasks/find_unused_packages_task.hh69
-rw-r--r--src/clients/adjutrix/Makefile.am2
-rw-r--r--src/clients/adjutrix/adjutrix.cc12
-rw-r--r--src/clients/adjutrix/command_line.cc4
-rw-r--r--src/clients/adjutrix/command_line.hh1
-rw-r--r--src/clients/adjutrix/find_unused_packages.cc95
-rw-r--r--src/clients/adjutrix/find_unused_packages.hh27
-rw-r--r--src/clients/adjutrix/keywords_graph.cc49
10 files changed, 302 insertions, 45 deletions
diff --git a/paludis/tasks/Makefile.am b/paludis/tasks/Makefile.am
index 6932997..0bda44a 100644
--- a/paludis/tasks/Makefile.am
+++ b/paludis/tasks/Makefile.am
@@ -22,6 +22,7 @@ check_SCRIPTS =
noinst_LIBRARIES = libpaludistasks.a
paludis_tasks_includedir = $(includedir)/paludis/tasks
paludis_tasks_include_HEADERS = \
+ find_unused_packages_task.hh \
install_task.hh \
uninstall_task.hh \
sync_task.hh \
@@ -30,6 +31,7 @@ paludis_tasks_include_HEADERS = \
report_task.hh
libpaludistasks_a_SOURCES = $(paludis_tasks_include_HEADERS) \
+ find_unused_packages_task.cc \
install_task.cc \
uninstall_task.cc \
sync_task.cc \
diff --git a/paludis/tasks/find_unused_packages_task.cc b/paludis/tasks/find_unused_packages_task.cc
new file mode 100644
index 0000000..2ddfb59
--- /dev/null
+++ b/paludis/tasks/find_unused_packages_task.cc
@@ -0,0 +1,86 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2007 Danny van Dyk <kugelfang@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 "find_unused_packages_task.hh"
+
+#include <paludis/environment.hh>
+#include <paludis/repository.hh>
+#include <paludis/util/tokeniser.hh>
+#include <paludis/util/compare.hh>
+#include <paludis/util/collection_concrete.hh>
+
+#include <set>
+
+using namespace paludis;
+
+FindUnusedPackagesTask::~FindUnusedPackagesTask()
+{
+}
+
+PackageDatabaseEntryCollection::ConstPointer
+FindUnusedPackagesTask::execute(const QualifiedPackageName & package)
+{
+ PackageDatabaseEntryCollection::Pointer result(new PackageDatabaseEntryCollection::Concrete);
+ PackageDatabaseEntryCollection::ConstPointer packages(_env->package_database()->query(
+ PackageDepAtom(stringify(package) + "::" + stringify(_repo->name())),
+ is_installable_only,
+ qo_group_by_slot));
+
+ SlotName old_slot("I_am_a_slot");
+ std::set<KeywordName> keywords;
+ for (PackageDatabaseEntryCollection::ReverseIterator p(packages->rbegin()), p_end(packages->rend()) ;
+ p != p_end ; ++p)
+ {
+ VersionMetadata::ConstPointer metadata(_repo->version_metadata(package, p->version));
+ if (! metadata->get_ebuild_interface())
+ continue;
+
+ if (metadata->slot != old_slot)
+ {
+ keywords.clear();
+ old_slot = metadata->slot;
+ }
+
+ std::set<KeywordName> current_keywords;
+ WhitespaceTokeniser::get_instance()->tokenise(metadata->get_ebuild_interface()->keywords,
+ create_inserter<KeywordName>(std::inserter(current_keywords, current_keywords.end())));
+
+ bool used(false);
+ for (std::set<KeywordName>::const_iterator k(current_keywords.begin()), k_end(current_keywords.end()) ;
+ k != k_end ; ++k)
+ {
+ std::string stable_keyword(stringify(*k));
+ if (stable_keyword[0] == '~')
+ stable_keyword.erase(0, 1);
+
+ if ((keywords.end() == keywords.find(*k)) && (keywords.end() == keywords.find(KeywordName(stable_keyword))))
+ {
+ used = true;
+ break;
+ }
+ }
+
+ if (! used)
+ result->append(PackageDatabaseEntry(package, p->version, _repo->name()));
+
+ keywords.insert(current_keywords.begin(), current_keywords.end());
+ }
+
+ return result;
+}
diff --git a/paludis/tasks/find_unused_packages_task.hh b/paludis/tasks/find_unused_packages_task.hh
new file mode 100644
index 0000000..baa5d92
--- /dev/null
+++ b/paludis/tasks/find_unused_packages_task.hh
@@ -0,0 +1,69 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2007 Danny van Dyk <kugelfang@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_TASKS_FIND_UNUSED_PACKAGES_TASK_HH
+#define PALUDIS_GUARD_PALUDIS_TASKS_FIND_UNUSED_PACKAGES_TASK_HH 1
+
+#include <paludis/util/instantiation_policy.hh>
+#include <paludis/package_database.hh>
+
+namespace paludis
+{
+ class Environment;
+ class Repository;
+
+ /**
+ * Task to find unused package versions for a given package name.
+ *
+ * \ingroup grptasks
+ * \nosubgrouping
+ */
+ class PALUDIS_VISIBLE FindUnusedPackagesTask :
+ InstantiationPolicy<FindUnusedPackagesTask, instantiation_method::NonCopyableTag>
+ {
+ private:
+ /// Our environment
+ const Environment * const _env;
+
+ /// Our repository
+ const Repository * const _repo;
+
+
+ public:
+ ///\name Basic operations
+ ///\{
+
+ FindUnusedPackagesTask(const Environment * const env, const Repository * const repo) :
+ _env(env),
+ _repo(repo)
+ {
+ }
+
+ virtual ~FindUnusedPackagesTask();
+
+ ///\}
+
+ /**
+ * Run the task.
+ */
+ PackageDatabaseEntryCollection::ConstPointer execute(const QualifiedPackageName &);
+ };
+}
+
+#endif
diff --git a/src/clients/adjutrix/Makefile.am b/src/clients/adjutrix/Makefile.am
index e6039f6..7f848b8 100644
--- a/src/clients/adjutrix/Makefile.am
+++ b/src/clients/adjutrix/Makefile.am
@@ -22,6 +22,7 @@ man_adjutrix_SOURCES = \
man_adjutrix_LDADD = \
$(top_builddir)/paludis/args/libpaludisargs.la \
+ $(top_builddir)/paludis/tasks/libpaludistasks.a \
$(top_builddir)/paludis/util/libpaludisutil.la \
$(top_builddir)/src/output/liboutput.a \
$(top_builddir)/src/common_args/libcommonargs.a \
@@ -33,6 +34,7 @@ adjutrix_SOURCES = \
find_dropped_keywords.hh find_dropped_keywords.cc \
find_insecure_packages.hh find_insecure_packages.cc \
find_reverse_deps.hh find_reverse_deps.cc \
+ find_unused_packages.hh find_unused_packages.cc \
keywords_graph.hh keywords_graph.cc \
display_profiles_use.hh display_profiles_use.cc \
display_default_system_resolution.hh display_default_system_resolution.cc \
diff --git a/src/clients/adjutrix/adjutrix.cc b/src/clients/adjutrix/adjutrix.cc
index 7a929fa..de8f567 100644
--- a/src/clients/adjutrix/adjutrix.cc
+++ b/src/clients/adjutrix/adjutrix.cc
@@ -23,6 +23,7 @@
#include "find_dropped_keywords.hh"
#include "find_insecure_packages.hh"
#include "find_reverse_deps.hh"
+#include "find_unused_packages.hh"
#include "keywords_graph.hh"
#include "display_profiles_use.hh"
#include "display_default_system_resolution.hh"
@@ -131,6 +132,7 @@ main(int argc, char *argv[])
CommandLine::get_instance()->a_find_stable_candidates.specified() +
CommandLine::get_instance()->a_find_dropped_keywords.specified() +
CommandLine::get_instance()->a_find_insecure_packages.specified() +
+ CommandLine::get_instance()->a_find_unused_packages.specified() +
CommandLine::get_instance()->a_keywords_graph.specified() +
CommandLine::get_instance()->a_reverse_deps.specified() +
CommandLine::get_instance()->a_display_profiles_use.specified() +
@@ -180,6 +182,16 @@ main(int argc, char *argv[])
return EXIT_SUCCESS;
}
+ if (CommandLine::get_instance()->a_find_unused_packages.specified())
+ {
+ if (CommandLine::get_instance()->begin_parameters() !=
+ CommandLine::get_instance()->end_parameters())
+ throw DoHelp("find-unused-packages action takes no parameters");
+
+ do_find_unused_packages(env);
+ return EXIT_SUCCESS;
+ }
+
if (CommandLine::get_instance()->a_keywords_graph.specified())
{
diff --git a/src/clients/adjutrix/command_line.cc b/src/clients/adjutrix/command_line.cc
index 8024e4a..dc17118 100644
--- a/src/clients/adjutrix/command_line.cc
+++ b/src/clients/adjutrix/command_line.cc
@@ -31,7 +31,9 @@ CommandLine::CommandLine() :
a_find_dropped_keywords(&tree_action_args,
"find-dropped-keywords", 'd', "Search for packages where keywords have been dropped"),
a_find_insecure_packages(&tree_action_args,
- "find-insecure-packages", 'i', "Search for packages marked as insecure by a GLSA"),
+ "find-insecure-packages", 'i', "Search for packages marked as insecure by a GLSA"),
+ a_find_unused_packages(&tree_action_args,
+ "find-unused-packages", 'U', "Search package versions that can probably safely be removed"),
a_keywords_graph(&tree_action_args,
"keyword-graph", 'k', "Display keywords graphically"),
a_reverse_deps(&tree_action_args,
diff --git a/src/clients/adjutrix/command_line.hh b/src/clients/adjutrix/command_line.hh
index 81053c4..c4cbca3 100644
--- a/src/clients/adjutrix/command_line.hh
+++ b/src/clients/adjutrix/command_line.hh
@@ -63,6 +63,7 @@ class CommandLine :
paludis::args::SwitchArg a_find_stable_candidates;
paludis::args::SwitchArg a_find_dropped_keywords;
paludis::args::SwitchArg a_find_insecure_packages;
+ paludis::args::SwitchArg a_find_unused_packages;
paludis::args::SwitchArg a_keywords_graph;
paludis::args::SwitchArg a_reverse_deps;
paludis::args::SwitchArg a_what_needs_keywording;
diff --git a/src/clients/adjutrix/find_unused_packages.cc b/src/clients/adjutrix/find_unused_packages.cc
new file mode 100644
index 0000000..1bc4026
--- /dev/null
+++ b/src/clients/adjutrix/find_unused_packages.cc
@@ -0,0 +1,95 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2007 Danny van Dyk <kugelfang@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 "find_unused_packages.hh"
+#include "command_line.hh"
+
+#include <paludis/tasks/find_unused_packages_task.hh>
+#include <paludis/util/tokeniser.hh>
+#include <paludis/util/compare.hh>
+
+#include <set>
+#include <map>
+#include <iostream>
+#include <iomanip>
+#include <algorithm>
+
+using namespace paludis;
+using std::cout;
+using std::cerr;
+using std::endl;
+
+void do_find_unused_packages(const Environment & env)
+{
+ Context context("When performing find-unused-packages action:");
+
+ for (IndirectIterator<PackageDatabase::RepositoryIterator, const Repository>
+ r(env.package_database()->begin_repositories()),
+ r_end(env.package_database()->end_repositories()) ; r != r_end ; ++r)
+ {
+ if (r->name() == RepositoryName("virtuals"))
+ continue;
+
+ if (! r->use_interface)
+ continue;
+
+ Context repo_context("When searching for unused packages in repository '" + stringify(r->name()) + "':");
+ FindUnusedPackagesTask task(&env, &(*r));
+
+ cout << "Searching for unused packages in repository " << stringify(r->name()) << endl;
+
+ CategoryNamePartCollection::ConstPointer categories(r->category_names());
+ for (CategoryNamePartCollection::Iterator c(categories->begin()), c_end(categories->end()) ;
+ c != c_end ; ++c)
+ {
+ Context cat_context("When searching for unused packages in category '" + stringify(*c) + "':");
+
+ if (CommandLine::get_instance()->a_category.specified())
+ if (CommandLine::get_instance()->a_category.end_args() == std::find(
+ CommandLine::get_instance()->a_category.begin_args(),
+ CommandLine::get_instance()->a_category.end_args(),
+ stringify(*c)))
+ continue;
+
+ cout << " In category " << stringify(*c) << ":" << endl;
+ QualifiedPackageNameCollection::ConstPointer packages(r->package_names(*c));
+
+ for (QualifiedPackageNameCollection::Iterator p(packages->begin()), p_end(packages->end()) ;
+ p != p_end ; ++p)
+ {
+ Context pkg_context("When searching for unused packages with package name '" + stringify(*p) + "':");
+
+ if (CommandLine::get_instance()->a_category.specified())
+ if (CommandLine::get_instance()->a_category.end_args() == std::find(
+ CommandLine::get_instance()->a_category.begin_args(),
+ CommandLine::get_instance()->a_category.end_args(),
+ stringify(*c)))
+ continue;
+
+ PackageDatabaseEntryCollection::ConstPointer unused(task.execute(*p));
+ for (PackageDatabaseEntryCollection::Iterator u(unused->begin()), u_end(unused->end()) ;
+ u != u_end ; ++u)
+ cout << stringify(*u) << endl;
+ }
+
+ cout << endl;
+ }
+ }
+}
+
diff --git a/src/clients/adjutrix/find_unused_packages.hh b/src/clients/adjutrix/find_unused_packages.hh
new file mode 100644
index 0000000..0b38ff8
--- /dev/null
+++ b/src/clients/adjutrix/find_unused_packages.hh
@@ -0,0 +1,27 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2007 Danny van Dyk <kugelfang@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_SRC_ADJUTRIX_FIND_UNUSED_PACKAGES_HH
+#define PALUDIS_GUARD_SRC_ADJUTRIX_FIND_UNUSED_PACKAGES_HH 1
+
+#include <paludis/environment.hh>
+
+void do_find_unused_packages(const paludis::Environment & env);
+
+#endif
diff --git a/src/clients/adjutrix/keywords_graph.cc b/src/clients/adjutrix/keywords_graph.cc
index 7d8bc3d..2a8e11b 100644
--- a/src/clients/adjutrix/keywords_graph.cc
+++ b/src/clients/adjutrix/keywords_graph.cc
@@ -21,6 +21,7 @@
#include "command_line.hh"
#include <output/colour.hh>
+#include <paludis/tasks/find_unused_packages_task.hh>
#include <paludis/util/tokeniser.hh>
#include <paludis/util/compare.hh>
@@ -60,10 +61,12 @@ namespace
cout << endl;
VersionSpecCollection::ConstPointer versions(repo.version_specs(package));
+ FindUnusedPackagesTask task(&e, &repo);
PackageDatabaseEntryCollection::ConstPointer packages(e.package_database()->query(
PackageDepAtom(stringify(package) + "::" + stringify(repo.name())),
is_installable_only,
qo_group_by_slot));
+ PackageDatabaseEntryCollection::ConstPointer unused(task.execute(package));
if (packages->empty())
return;
@@ -118,48 +121,6 @@ namespace
<< std::string(longest_slot_name + 3, '-') << endl;
SlotName old_slot("unused_round");
- std::map<VersionSpec, bool> unused_versions;
- std::set<KeywordName> keywords;
-
- for (PackageDatabaseEntryCollection::ReverseIterator p(packages->rbegin()), p_end(packages->rend()) ;
- p != p_end ; ++p)
- {
- VersionMetadata::ConstPointer metadata(repo.version_metadata(package, p->version));
- if (! metadata->get_ebuild_interface())
- continue;
-
- if (metadata->slot != old_slot)
- {
- keywords.clear();
- old_slot = metadata->slot;
- }
-
- std::set<KeywordName> current_keywords;
- WhitespaceTokeniser::get_instance()->tokenise(metadata->get_ebuild_interface()->keywords,
- create_inserter<KeywordName>(std::inserter(current_keywords, current_keywords.end())));
-
- bool used(false);
- for (std::set<KeywordName>::const_iterator k(current_keywords.begin()), k_end(current_keywords.end()) ;
- k != k_end ; ++k)
- {
- std::string stable_keyword(stringify(*k));
- if (stable_keyword[0] == '~')
- stable_keyword.erase(0, 1);
-
- if ((keywords.end() == keywords.find(*k)) && (keywords.end() == keywords.find(KeywordName(stable_keyword))))
- {
- used = true;
- break;
- }
- }
-
- if (! used)
- unused_versions[p->version] = true;
-
- keywords.insert(current_keywords.begin(), current_keywords.end());
- }
-
- old_slot = SlotName("first_slot");
for (PackageDatabaseEntryCollection::Iterator p(packages->begin()), p_end(packages->end()) ;
p != p_end ; ++p)
{
@@ -175,7 +136,7 @@ namespace
cout << std::left << std::setw(version_specs_columns_width) << p->version << "| ";
- keywords.clear();
+ std::set<KeywordName> keywords;
WhitespaceTokeniser::get_instance()->tokenise(metadata->get_ebuild_interface()->keywords,
create_inserter<KeywordName>(std::inserter(keywords, keywords.end())));
@@ -194,7 +155,7 @@ namespace
cout << " ";
}
- cout << "| " << (unused_versions[p->version] ? "* " : " ");
+ cout << "| " << (unused->find(*p) != unused->end() ? "* " : " ");
if (metadata->slot != old_slot)
{