aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-01-22 15:06:27 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-01-22 14:50:42 +0000
commit79d96501ffb6b3bcbf2dfd47bc4085170d7ae38f (patch)
treeeb771d1fd1eca633d969f7883b68ea2722f7f682
parentfd995d32cba3a621f1ae3b2f857ec083a2047f15 (diff)
downloadpaludis-79d96501ffb6b3bcbf2dfd47bc4085170d7ae38f.tar.gz
paludis-79d96501ffb6b3bcbf2dfd47bc4085170d7ae38f.tar.xz
Make users dep upon groups
-rw-r--r--paludis/repositories/accounts/Makefile.am2
-rw-r--r--paludis/repositories/accounts/accounts_dep_key.cc140
-rw-r--r--paludis/repositories/accounts/accounts_dep_key.hh56
-rw-r--r--paludis/repositories/accounts/accounts_id.cc26
4 files changed, 219 insertions, 5 deletions
diff --git a/paludis/repositories/accounts/Makefile.am b/paludis/repositories/accounts/Makefile.am
index 35dd4ac..0cb9ec1 100644
--- a/paludis/repositories/accounts/Makefile.am
+++ b/paludis/repositories/accounts/Makefile.am
@@ -25,6 +25,7 @@ paludis_repositories_accounts_include_HEADERS = \
dummy_accounts_handler.hh \
passwd_accounts_handler.hh \
accounts_id.hh \
+ accounts_dep_key.hh \
installed_accounts_id.hh
libpaludisaccountsrepository_@PALUDIS_PC_SLOT@_la_SOURCES = \
@@ -33,6 +34,7 @@ libpaludisaccountsrepository_@PALUDIS_PC_SLOT@_la_SOURCES = \
accounts_repository.cc \
accounts_repository_store.cc \
accounts_id.cc \
+ accounts_dep_key.cc \
installed_accounts_id.cc \
dummy_accounts_handler.cc \
passwd_accounts_handler.cc \
diff --git a/paludis/repositories/accounts/accounts_dep_key.cc b/paludis/repositories/accounts/accounts_dep_key.cc
new file mode 100644
index 0000000..913ec40
--- /dev/null
+++ b/paludis/repositories/accounts/accounts_dep_key.cc
@@ -0,0 +1,140 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2009 Ciaran McCreesh
+ *
+ * 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 <paludis/repositories/accounts/accounts_dep_key.hh>
+#include <paludis/util/set.hh>
+#include <paludis/util/wrapped_forward_iterator.hh>
+#include <paludis/selection.hh>
+#include <paludis/generator.hh>
+#include <paludis/filtered_generator.hh>
+#include <paludis/filter.hh>
+#include <paludis/dep_spec.hh>
+#include <paludis/formatter.hh>
+#include <paludis/environment.hh>
+#include <sstream>
+
+using namespace paludis;
+using namespace paludis::accounts_repository;
+
+namespace paludis
+{
+ template <>
+ struct Implementation<AccountsDepKey>
+ {
+ const Environment * const env;
+ const std::tr1::shared_ptr<Sequence<std::tr1::shared_ptr<PackageDepSpec> > > specs;
+ const std::tr1::shared_ptr<DependencySpecTree> tree;
+ const std::tr1::shared_ptr<DependencyLabelSequence> initial_labels;
+
+ Implementation(const Environment * const e, const std::tr1::shared_ptr<const Set<std::string> > & s) :
+ env(e),
+ specs(new Sequence<std::tr1::shared_ptr<PackageDepSpec> >),
+ tree(new DependencySpecTree(make_shared_ptr(new AllDepSpec))),
+ initial_labels(new DependencyLabelSequence)
+ {
+ for (Set<std::string>::ConstIterator i(s->begin()), i_end(s->end()) ;
+ i != i_end ; ++i)
+ {
+ std::tr1::shared_ptr<PackageDepSpec> spec(new PackageDepSpec(make_package_dep_spec()
+ .package(CategoryNamePart("group") + PackageNamePart(*i))));
+ specs->push_back(spec);
+ tree->root()->append(spec);
+ }
+
+ initial_labels->push_back(make_shared_ptr(new DependencyBuildLabel("build")));
+ initial_labels->push_back(make_shared_ptr(new DependencyRunLabel("run")));
+ }
+ };
+}
+
+AccountsDepKey::AccountsDepKey(const Environment * const e,
+ const std::tr1::shared_ptr<const Set<std::string> > & s) :
+ PrivateImplementationPattern<AccountsDepKey>(new Implementation<AccountsDepKey>(e, s))
+{
+}
+
+AccountsDepKey::~AccountsDepKey()
+{
+}
+
+const std::string
+AccountsDepKey::raw_name() const
+{
+ return "dependencies";
+}
+
+const std::string
+AccountsDepKey::human_name() const
+{
+ return "Dependencies";
+}
+
+MetadataKeyType
+AccountsDepKey::type() const
+{
+ return mkt_dependencies;
+}
+
+const std::tr1::shared_ptr<const DependencySpecTree>
+AccountsDepKey::value() const
+{
+ return _imp->tree;
+}
+
+const std::tr1::shared_ptr<const DependencyLabelSequence>
+AccountsDepKey::initial_labels() const
+{
+ return _imp->initial_labels;
+}
+
+std::string
+AccountsDepKey::pretty_print(const DependencySpecTree::ItemFormatter & f) const
+{
+ std::stringstream s;
+
+ for (Sequence<std::tr1::shared_ptr<PackageDepSpec> >::ConstIterator i(_imp->specs->begin()),
+ i_end(_imp->specs->end()) ; i != i_end ; ++i)
+ {
+ if (! s.str().empty())
+ s << ", ";
+
+ if (_imp->env)
+ {
+ if (! (*_imp->env)[selection::SomeArbitraryVersion(generator::Matches(**i, MatchPackageOptions()) |
+ filter::InstalledAtRoot(_imp->env->root()))]->empty())
+ s << f.format(**i, format::Installed());
+ else if (! (*_imp->env)[selection::SomeArbitraryVersion(generator::Matches(**i, MatchPackageOptions()) |
+ filter::SupportsAction<InstallAction>() | filter::NotMasked())]->empty())
+ s << f.format(**i, format::Installable());
+ else
+ s << f.format(**i, format::Plain());
+ }
+ else
+ s << f.format(**i, format::Plain());
+ }
+
+ return s.str();
+}
+
+std::string
+AccountsDepKey::pretty_print_flat(const DependencySpecTree::ItemFormatter & f) const
+{
+ return pretty_print(f);
+}
+
diff --git a/paludis/repositories/accounts/accounts_dep_key.hh b/paludis/repositories/accounts/accounts_dep_key.hh
new file mode 100644
index 0000000..a52af75
--- /dev/null
+++ b/paludis/repositories/accounts/accounts_dep_key.hh
@@ -0,0 +1,56 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2009 Ciaran McCreesh
+ *
+ * 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_REPOSITORIES_ACCOUNTS_ACCOUNTS_DEP_KEY_HH
+#define PALUDIS_GUARD_PALUDIS_REPOSITORIES_ACCOUNTS_ACCOUNTS_DEP_KEY_HH 1
+
+#include <paludis/metadata_key.hh>
+#include <paludis/util/private_implementation_pattern.hh>
+
+namespace paludis
+{
+ namespace accounts_repository
+ {
+ class AccountsDepKey :
+ public MetadataSpecTreeKey<DependencySpecTree>,
+ private PrivateImplementationPattern<AccountsDepKey>
+ {
+ public:
+ AccountsDepKey(const Environment * const e,
+ const std::tr1::shared_ptr<const Set<std::string> > &);
+ ~AccountsDepKey();
+
+ virtual const std::string raw_name() const PALUDIS_ATTRIBUTE((warn_unused_result));
+ virtual const std::string human_name() const PALUDIS_ATTRIBUTE((warn_unused_result));
+ virtual MetadataKeyType type() const PALUDIS_ATTRIBUTE((warn_unused_result));
+
+ virtual const std::tr1::shared_ptr<const DependencySpecTree> value() const
+ PALUDIS_ATTRIBUTE((warn_unused_result));
+
+ virtual std::string pretty_print(const DependencySpecTree::ItemFormatter &) const
+ PALUDIS_ATTRIBUTE((warn_unused_result));
+ virtual std::string pretty_print_flat(const DependencySpecTree::ItemFormatter &) const
+ PALUDIS_ATTRIBUTE((warn_unused_result));
+ virtual const std::tr1::shared_ptr<const DependencyLabelSequence> initial_labels() const
+ PALUDIS_ATTRIBUTE((warn_unused_result));
+ };
+ }
+}
+
+#endif
diff --git a/paludis/repositories/accounts/accounts_id.cc b/paludis/repositories/accounts/accounts_id.cc
index e53a9a3..06e0924 100644
--- a/paludis/repositories/accounts/accounts_id.cc
+++ b/paludis/repositories/accounts/accounts_id.cc
@@ -18,6 +18,7 @@
*/
#include <paludis/repositories/accounts/accounts_id.hh>
+#include <paludis/repositories/accounts/accounts_dep_key.hh>
#include <paludis/util/private_implementation_pattern-impl.hh>
#include <paludis/util/make_shared_ptr.hh>
#include <paludis/util/config_file.hh>
@@ -33,6 +34,7 @@
#include <paludis/literal_metadata_key.hh>
#include <paludis/repository.hh>
#include <paludis/action.hh>
+#include <algorithm>
using namespace paludis;
using namespace paludis::accounts_repository;
@@ -65,6 +67,7 @@ namespace paludis
mutable std::tr1::shared_ptr<const LiteralMetadataStringSetKey> extra_groups_key;
mutable std::tr1::shared_ptr<const LiteralMetadataValueKey<std::string> > home_key;
mutable std::tr1::shared_ptr<const LiteralMetadataValueKey<std::string> > shell_key;
+ mutable std::tr1::shared_ptr<const AccountsDepKey> dependencies_key;
mutable std::tr1::shared_ptr<const LiteralMetadataValueKey<std::string> > groupname_key;
mutable std::tr1::shared_ptr<const LiteralMetadataValueKey<std::string> > preferred_gid_key;
@@ -126,6 +129,8 @@ AccountsID::_add_metadata_keys() const
add_metadata_key(_imp->shell_key);
if (_imp->home_key)
add_metadata_key(_imp->home_key);
+ if (_imp->dependencies_key)
+ add_metadata_key(_imp->dependencies_key);
if (_imp->groupname_key)
add_metadata_key(_imp->groupname_key);
@@ -169,17 +174,26 @@ AccountsID::_need_file_keys() const
_imp->home_key.reset(new LiteralMetadataValueKey<std::string>("home", "Home Directory",
mkt_normal, k.get("home")));
- if (! k.get("default_group").empty())
- _imp->default_group_key.reset(new LiteralMetadataValueKey<std::string>("default_group", "Default Group",
- mkt_normal, k.get("default_group")));
+ std::tr1::shared_ptr<Set<std::string> > all_groups_s(new Set<std::string>);
if (! k.get("extra_groups").empty())
{
std::tr1::shared_ptr<Set<std::string> > groups_s(new Set<std::string>);
tokenise_whitespace(k.get("extra_groups"), groups_s->inserter());
+ std::copy(groups_s->begin(), groups_s->end(), all_groups_s->inserter());
_imp->extra_groups_key.reset(new LiteralMetadataStringSetKey("extra_groups", "Extra Groups",
mkt_normal, groups_s));
}
+
+ if (! k.get("default_group").empty())
+ {
+ _imp->default_group_key.reset(new LiteralMetadataValueKey<std::string>("default_group", "Default Group",
+ mkt_normal, k.get("default_group")));
+ all_groups_s->insert(k.get("default_group"));
+ }
+
+ if (! all_groups_s->empty())
+ _imp->dependencies_key.reset(new AccountsDepKey(_imp->env, all_groups_s));
}
else
{
@@ -295,13 +309,15 @@ AccountsID::contained_in_key() const
const std::tr1::shared_ptr<const MetadataSpecTreeKey<DependencySpecTree> >
AccountsID::build_dependencies_key() const
{
- return make_null_shared_ptr();
+ _need_file_keys();
+ return _imp->dependencies_key;
}
const std::tr1::shared_ptr<const MetadataSpecTreeKey<DependencySpecTree> >
AccountsID::run_dependencies_key() const
{
- return make_null_shared_ptr();
+ _need_file_keys();
+ return _imp->dependencies_key;
}
const std::tr1::shared_ptr<const MetadataSpecTreeKey<DependencySpecTree> >