aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-04-17 22:30:24 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-04-17 22:30:24 +0000
commit98b0b6ad9f35830ab27a1f1b9767d55f1dee2e30 (patch)
treefff9055611a88e6f923499f85438d58e9a1883bd
parentab89dca59cc680035b7c6eed7c4482cc6605be2d (diff)
downloadpaludis-98b0b6ad9f35830ab27a1f1b9767d55f1dee2e30.tar.gz
paludis-98b0b6ad9f35830ab27a1f1b9767d55f1dee2e30.tar.xz
Turn dep tags into a proper class. Associate some basic GLSA information with GLSA tags (future expansion expected). Display new style dep tags.
-rw-r--r--paludis/dep_atom.cc6
-rw-r--r--paludis/dep_atom.hh7
-rw-r--r--paludis/dep_list.cc14
-rw-r--r--paludis/dep_list.hh3
-rw-r--r--paludis/dep_tag.cc85
-rw-r--r--paludis/dep_tag.hh128
-rw-r--r--paludis/files.m41
-rw-r--r--paludis/portage_repository.cc6
-rw-r--r--paludis/vdb_repository.cc2
-rw-r--r--src/install.cc70
10 files changed, 300 insertions, 22 deletions
diff --git a/paludis/dep_atom.cc b/paludis/dep_atom.cc
index f1b1f2d..33e7539 100644
--- a/paludis/dep_atom.cc
+++ b/paludis/dep_atom.cc
@@ -77,7 +77,8 @@ PackageDepAtom::PackageDepAtom(const QualifiedPackageName & package) :
_version_operator("="),
_version_spec(0),
_slot(0),
- _repository(0)
+ _repository(0),
+ _tag(0)
{
}
@@ -87,7 +88,8 @@ PackageDepAtom::PackageDepAtom(const std::string & ss) :
_version_operator("="),
_version_spec(0),
_slot(0),
- _repository(0)
+ _repository(0),
+ _tag(0)
{
Context context("When parsing package dep atom '" + ss + "':");
diff --git a/paludis/dep_atom.hh b/paludis/dep_atom.hh
index 77840c0..0b7e4c4 100644
--- a/paludis/dep_atom.hh
+++ b/paludis/dep_atom.hh
@@ -21,6 +21,7 @@
#define PALUDIS_GUARD_PALUDIS_DEP_ATOM_HH 1
#include <list>
+#include <paludis/dep_tag.hh>
#include <paludis/name.hh>
#include <paludis/util/attributes.hh>
#include <paludis/util/composite_pattern.hh>
@@ -235,7 +236,7 @@ namespace paludis
CountedPtr<VersionSpec, count_policy::ExternalCountTag> _version_spec;
CountedPtr<SlotName, count_policy::ExternalCountTag> _slot;
CountedPtr<RepositoryName, count_policy::ExternalCountTag> _repository;
- std::string _tag;
+ DepTag::ConstPointer _tag;
public:
/**
@@ -300,7 +301,7 @@ namespace paludis
/**
* Fetch our tag.
*/
- const std::string & tag() const
+ DepTag::ConstPointer tag() const
{
return _tag;
}
@@ -308,7 +309,7 @@ namespace paludis
/**
* Set our tag.
*/
- void set_tag(const std::string & s)
+ void set_tag(const DepTag::ConstPointer & s)
{
_tag = s;
}
diff --git a/paludis/dep_list.cc b/paludis/dep_list.cc
index 1c2c1d9..01d7264 100644
--- a/paludis/dep_list.cc
+++ b/paludis/dep_list.cc
@@ -361,12 +361,8 @@ DepList::visit(const PackageDepAtom * const p)
throw CircularDependencyError(i, next(i));
}
- if (! p->tag().empty())
- {
- std::set<std::string> new_tags(i->get<dle_tag>());
- new_tags.insert(p->tag());
- i->set<dle_tag>(new_tags);
- }
+ if (p->tag())
+ i->get<dle_tag>().insert(p->tag());
return;
}
}
@@ -405,8 +401,8 @@ DepList::visit(const PackageDepAtom * const p)
}
std::list<DepListEntry>::iterator merge_entry;
- std::set<std::string> tags;
- if (! p->tag().empty())
+ std::set<DepTag::ConstPointer, DepTag::Comparator> tags;
+ if (p->tag())
tags.insert(p->tag());
if (! match)
{
@@ -475,7 +471,7 @@ DepList::visit(const PackageDepAtom * const p)
_imp->merge_list.insert(next(merge_entry),
DepListEntry(pp.package(), merge_entry->get<dle_version>(),
p_metadata, merge_entry->get<dle_repository>(), flags,
- std::set<std::string>()));
+ std::set<DepTag::ConstPointer, DepTag::Comparator>()));
}
}
diff --git a/paludis/dep_list.hh b/paludis/dep_list.hh
index b43a507..539fdb5 100644
--- a/paludis/dep_list.hh
+++ b/paludis/dep_list.hh
@@ -28,6 +28,7 @@
#include <ostream>
#include <set>
#include <paludis/dep_atom.hh>
+#include <paludis/dep_tag.hh>
#include <paludis/name.hh>
#include <paludis/qa/environment.hh>
#include <paludis/util/instantiation_policy.hh>
@@ -76,7 +77,7 @@ namespace paludis
SmartRecordKey<dle_metadata, VersionMetadata::ConstPointer>,
SmartRecordKey<dle_repository, RepositoryName>,
SmartRecordKey<dle_flags, DepListEntryFlags>,
- SmartRecordKey<dle_tag, std::set<std::string> >
+ SmartRecordKey<dle_tag, std::set<DepTag::ConstPointer, DepTag::Comparator> >
{
};
diff --git a/paludis/dep_tag.cc b/paludis/dep_tag.cc
new file mode 100644
index 0000000..76c3ec1
--- /dev/null
+++ b/paludis/dep_tag.cc
@@ -0,0 +1,85 @@
+/* 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 "dep_tag.hh"
+
+using namespace paludis;
+
+namespace
+{
+ DepTagCategory::ConstPointer
+ make_glsa_dep_tag()
+ {
+ return DepTagCategory::ConstPointer(new DepTagCategory(
+ "glsa",
+ "Security advisories",
+ "Your system is potentially affected by these security issues:",
+ "Please read the advisories carefully and take appropriate action."));
+ }
+}
+static const DepTagCategoryMaker::RegisterMaker register_glsa_dep_tag("glsa",
+ &make_glsa_dep_tag);
+
+DepTagCategory::DepTagCategory(const std::string & id,
+ const std::string & t, const std::string & pre,
+ const std::string & post) :
+ _id(id),
+ _title(t),
+ _pre_text(pre),
+ _post_text(post)
+{
+}
+
+NoSuchDepTagCategory::NoSuchDepTagCategory(const std::string & s) throw () :
+ Exception("No such dep tag category '" + s + "'")
+{
+}
+
+DepTag::DepTag()
+{
+}
+
+DepTag::~DepTag()
+{
+}
+
+GLSADepTag::GLSADepTag(const std::string & id, const std::string & glsa_title) :
+ _id(id),
+ _glsa_title(glsa_title)
+{
+}
+
+std::string
+GLSADepTag::short_text() const
+{
+ return "GLSA-" + _id;
+}
+
+std::string
+GLSADepTag::category() const
+{
+ return "glsa";
+}
+
+std::string
+GLSADepTag::glsa_title() const
+{
+ return _glsa_title;
+}
+
diff --git a/paludis/dep_tag.hh b/paludis/dep_tag.hh
new file mode 100644
index 0000000..5a9a571
--- /dev/null
+++ b/paludis/dep_tag.hh
@@ -0,0 +1,128 @@
+/* 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_DEP_TAG_HH
+#define PALUDIS_GUARD_PALUDIS_DEP_TAG_HH 1
+
+#include <string>
+#include <paludis/util/instantiation_policy.hh>
+#include <paludis/util/visitor.hh>
+#include <paludis/util/counted_ptr.hh>
+#include <paludis/util/virtual_constructor.hh>
+#include <paludis/util/exception.hh>
+
+namespace paludis
+{
+ class DepTagCategory :
+ InstantiationPolicy<DepTagCategory, instantiation_method::NonCopyableTag>,
+ public InternalCounted<DepTagCategory>
+ {
+ private:
+ const std::string _id;
+ const std::string _title;
+ const std::string _pre_text;
+ const std::string _post_text;
+
+ public:
+ DepTagCategory(const std::string & id,
+ const std::string & t,
+ const std::string & pre,
+ const std::string & post);
+
+ std::string id() const
+ {
+ return _id;
+ }
+
+ std::string title() const
+ {
+ return _title;
+ }
+
+ std::string pre_text() const
+ {
+ return _pre_text;
+ }
+
+ std::string post_text() const
+ {
+ return _post_text;
+ }
+ };
+
+ class NoSuchDepTagCategory :
+ public Exception
+ {
+ public:
+ NoSuchDepTagCategory(const std::string &) throw ();
+ };
+
+ typedef VirtualConstructor<std::string, DepTagCategory::ConstPointer (*) (),
+ virtual_constructor_not_found::ThrowException<NoSuchDepTagCategory> > DepTagCategoryMaker;
+
+ class DepTag;
+ class GLSADepTag;
+
+ typedef VisitorTypes<GLSADepTag *> DepTagVisitorTypes;
+
+ class DepTag :
+ InstantiationPolicy<DepTag, instantiation_method::NonCopyableTag>,
+ public InternalCounted<DepTag>,
+ public virtual VisitableInterface<DepTagVisitorTypes>
+ {
+ protected:
+ DepTag();
+
+ public:
+ virtual ~DepTag();
+
+ virtual std::string short_text() const = 0;
+
+ virtual std::string category() const = 0;
+
+ struct Comparator
+ {
+ bool operator() (const DepTag::ConstPointer & d1,
+ const DepTag::ConstPointer & d2) const
+ {
+ return d1->short_text() < d2->short_text();
+ }
+ };
+ };
+
+ class GLSADepTag :
+ public DepTag,
+ public Visitable<GLSADepTag, DepTagVisitorTypes>
+ {
+ private:
+ const std::string _id;
+ const std::string _glsa_title;
+
+ public:
+ GLSADepTag(const std::string & id, const std::string & glsa_title);
+
+ virtual std::string short_text() const;
+
+ virtual std::string category() const;
+
+ std::string glsa_title() const;
+ };
+}
+
+#endif
diff --git a/paludis/files.m4 b/paludis/files.m4
index 0bbe050..5fc6b70 100644
--- a/paludis/files.m4
+++ b/paludis/files.m4
@@ -19,6 +19,7 @@ add(`dep_atom_pretty_printer', `hh', `cc')
add(`dep_lexer', `hh', `cc', `test')
add(`dep_list', `hh', `cc', `test')
add(`dep_parser', `hh', `cc', `test')
+add(`dep_tag', `hh', `cc')
add(`ebuild', `hh', `cc')
add(`environment', `hh', `cc')
add(`fake_repository', `hh', `cc')
diff --git a/paludis/portage_repository.cc b/paludis/portage_repository.cc
index 5c53bad..bed181f 100644
--- a/paludis/portage_repository.cc
+++ b/paludis/portage_repository.cc
@@ -352,7 +352,6 @@ Implementation<PortageRepository>::add_profile_r(const FSEntry & f) const
Context context_line("When parsing line '" + *line + "':");
PackageDepAtom::Pointer atom(new PackageDepAtom(line->substr(1)));
- atom->set_tag("system");
system_packages->add_child(atom);
}
}
@@ -1283,7 +1282,10 @@ PortageRepository::do_security_set() const
{
Context c("When parsing security advisory '" + stringify(*f) + "':");
AdvisoryFile advisory(*f);
- std::string advisory_tag = "GLSA " + advisory.get("Id");
+
+ GLSADepTag::Pointer advisory_tag(new GLSADepTag(advisory.get("Id"),
+ advisory.get("Title")));
+
bool is_affected = false;
std::list<std::string> a_list, u_list;
diff --git a/paludis/vdb_repository.cc b/paludis/vdb_repository.cc
index 0d49a86..abefaf0 100644
--- a/paludis/vdb_repository.cc
+++ b/paludis/vdb_repository.cc
@@ -576,7 +576,6 @@ VDBRepository::do_package_set(const std::string & s) const
p_end(_imp->entries.end()) ; p != p_end ; ++p)
{
PackageDepAtom::Pointer atom(new PackageDepAtom(p->name));
- atom->set_tag("everything");
result->add_child(atom);
}
@@ -594,7 +593,6 @@ VDBRepository::do_package_set(const std::string & s) const
line != line_end ; ++line)
{
PackageDepAtom::Pointer atom(new PackageDepAtom(QualifiedPackageName(*line)));
- atom->set_tag("world");
result->add_child(atom);
}
}
diff --git a/src/install.cc b/src/install.cc
index ad8300c..760c5a6 100644
--- a/src/install.cc
+++ b/src/install.cc
@@ -21,6 +21,7 @@
#include "src/install.hh"
#include <iostream>
#include <paludis/paludis.hh>
+#include <paludis/util/iterator.hh>
/** \file
* Handle the --install action for the main paludis program.
@@ -89,6 +90,16 @@ namespace
}
///}
};
+
+ struct TagDisplayer :
+ p::DepTagVisitorTypes::ConstVisitor
+ {
+ void visit(const GLSADepTag * const tag)
+ {
+ cout << "* " << colour(cl_yellow, tag->short_text()) << ": "
+ << tag->glsa_title() << endl;
+ }
+ };
}
int
@@ -178,6 +189,8 @@ do_install()
{
dep_list.add(targets);
+ std::set<p::DepTag::ConstPointer, p::DepTag::Comparator> all_tags;
+
for (p::DepList::Iterator dep(dep_list.begin()), dep_end(dep_list.end()) ;
dep != dep_end ; ++dep)
{
@@ -243,10 +256,22 @@ do_install()
cout << " " << colour(cl_flag_off, "-" + p::stringify(*i));
}
- /* display tag */
+ /* display tag, add tag to our post display list */
if (! dep->get<p::dle_tag>().empty())
- cout << " " << colour(cl_tag, "<" + p::join(dep->get<p::dle_tag>().begin(),
- dep->get<p::dle_tag>().end(), ",") + ">");
+ {
+ std::string tag_titles;
+ for (std::set<DepTag::ConstPointer, DepTag::Comparator>::const_iterator
+ tag(dep->get<p::dle_tag>().begin()),
+ tag_end(dep->get<p::dle_tag>().end()) ;
+ tag != tag_end ; ++tag)
+ {
+ all_tags.insert(*tag);
+ tag_titles.append((*tag)->short_text());
+ tag_titles.append(",");
+ }
+ tag_titles.erase(tag_titles.length() - 1);
+ cout << " " << colour(cl_tag, "<" + tag_titles + ">");
+ }
cout << endl;
}
@@ -257,7 +282,46 @@ do_install()
(max_count == 1 ? " package" : " packages") << endl << endl;
if (CommandLine::get_instance()->a_pretend.specified())
+ {
+ if (all_tags.empty())
+ return return_code;
+
+ TagDisplayer tag_displayer;
+
+ std::set<std::string> tag_categories;
+ std::transform(
+ p::indirect_iterator<const DepTag>(all_tags.begin()),
+ p::indirect_iterator<const DepTag>(all_tags.end()),
+ std::inserter(tag_categories, tag_categories.begin()),
+ std::mem_fun_ref(&DepTag::category));
+
+ for (std::set<std::string>::iterator cat(tag_categories.begin()),
+ cat_end(tag_categories.end()) ; cat != cat_end ; ++cat)
+ {
+ p::DepTagCategory::ConstPointer c(p::DepTagCategoryMaker::get_instance()->
+ find_maker(*cat)());
+
+ if (! c->title().empty())
+ cout << colour(cl_heading, c->title()) << endl << endl;
+ if (! c->pre_text().empty())
+ cout << c->pre_text() << endl << endl;
+
+ for (std::set<p::DepTag::ConstPointer, p::DepTag::Comparator>::const_iterator
+ t(all_tags.begin()), t_end(all_tags.end()) ;
+ t != t_end ; ++t)
+ {
+ if ((*t)->category() != *cat)
+ continue;
+ (*t)->accept(&tag_displayer);
+ }
+ cout << endl;
+
+ if (! c->post_text().empty())
+ cout << c->post_text() << endl << endl;
+ }
+
return return_code;
+ }
p::InstallOptions opts(false, false);
if (CommandLine::get_instance()->a_no_config_protection.specified())