aboutsummaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-05-19 14:20:48 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-05-19 20:52:24 +0100
commite52571861104efe6139b78b22557211f08025f11 (patch)
tree634bec98491886d12f8f5a25b24f4cacf8d69de5 /python
parent80bf4ad14bfd8ab74a9c0d5f203ad5a370351def (diff)
downloadpaludis-e52571861104efe6139b78b22557211f08025f11.tar.gz
paludis-e52571861104efe6139b78b22557211f08025f11.tar.xz
Revert the package dep spec changes
Diffstat (limited to 'python')
-rw-r--r--python/Makefile.am3
-rw-r--r--python/dep_spec.cc287
-rw-r--r--python/dep_spec.hh20
-rwxr-xr-xpython/dep_spec_TEST.py18
-rw-r--r--python/generator_TEST.py6
-rwxr-xr-xpython/mask_TEST.py2
-rw-r--r--python/package_dep_spec_constraint.cc253
-rw-r--r--python/paludis_python.hh2
-rw-r--r--python/paludis_python_so.cc2
-rw-r--r--python/version_requirements.cc85
-rwxr-xr-xpython/version_requirements_TEST.py38
11 files changed, 289 insertions, 427 deletions
diff --git a/python/Makefile.am b/python/Makefile.am
index e0cf4f0e1..4a275959e 100644
--- a/python/Makefile.am
+++ b/python/Makefile.am
@@ -42,6 +42,7 @@ IF_PYTHON_TESTS = \
repository_TEST.py \
selection_TEST.py \
version_operator_TEST.py \
+ version_requirements_TEST.py \
version_spec_TEST.py
IF_PYTHON_SOURCES = \
@@ -69,10 +70,10 @@ IF_PYTHON_SOURCES = \
nice_names-nn.hh nice_names-nn.cc \
log.cc \
package_id.cc \
- package_dep_spec_constraint.cc \
repository.cc \
selection.cc \
version_operator.cc \
+ version_requirements.cc \
version_spec.cc
BUILT_SOURCES = \
diff --git a/python/dep_spec.cc b/python/dep_spec.cc
index 20e6899b4..b53d3a768 100644
--- a/python/dep_spec.cc
+++ b/python/dep_spec.cc
@@ -26,10 +26,9 @@
#include <paludis/dep_spec.hh>
#include <paludis/environment.hh>
#include <paludis/user_dep_spec.hh>
+#include <paludis/version_requirements.hh>
+#include <paludis/partially_made_package_dep_spec.hh>
#include <paludis/dep_spec_data.hh>
-#include <paludis/package_dep_spec_requirement.hh>
-#include <paludis/version_spec.hh>
-#include <paludis/version_operator.hh>
#include <paludis/util/save.hh>
#include <paludis/util/stringify.hh>
@@ -40,7 +39,6 @@
#include <paludis/util/sequence-impl.hh>
#include <paludis/util/indirect_iterator-impl.hh>
#include <paludis/util/accept_visitor.hh>
-#include <paludis/util/visitor_cast.hh>
#include <type_traits>
#include <list>
@@ -74,40 +72,37 @@ namespace paludis
template<>
struct Imp<PythonPackageDepSpec>
{
- std::shared_ptr<const NameRequirement> package_name_requirement;
- std::shared_ptr<const CategoryNamePartRequirement> category_name_part_requirement;
- std::shared_ptr<const PackageNamePartRequirement> package_name_part_requirement;
- std::shared_ptr<const VersionRequirementSequence> all_versions;
- std::shared_ptr<const AnySlotRequirement> any_slot;
- std::shared_ptr<const ExactSlotRequirement> exact_slot;
- std::shared_ptr<const InRepositoryRequirement> in_repository;
- std::shared_ptr<const FromRepositoryRequirement> from_repository;
- std::shared_ptr<const KeyRequirementSequence> all_keys;
- std::shared_ptr<const ChoiceRequirementSequence> all_choices;
+ std::shared_ptr<const QualifiedPackageName> package_ptr;
+ std::shared_ptr<const CategoryNamePart> category_name_part_ptr;
+ std::shared_ptr<const PackageNamePart> package_name_part_ptr;
+ std::shared_ptr<VersionRequirements> version_requirements;
+ VersionRequirementsMode version_requirements_mode;
+ std::shared_ptr<const SlotRequirement> slot;
+ std::shared_ptr<const RepositoryName> in_repository;
+ std::shared_ptr<const RepositoryName> from_repository;
+ std::shared_ptr<const AdditionalPackageDepSpecRequirements> additional_requirements;
const std::string str;
Imp(
- const std::shared_ptr<const NameRequirement> & q,
- const std::shared_ptr<const CategoryNamePartRequirement> & c,
- const std::shared_ptr<const PackageNamePartRequirement> & p,
- const std::shared_ptr<const VersionRequirementSequence> & v,
- const std::shared_ptr<const AnySlotRequirement> & s,
- const std::shared_ptr<const ExactSlotRequirement> & xs,
- const std::shared_ptr<const InRepositoryRequirement> & ri,
- const std::shared_ptr<const FromRepositoryRequirement> & rf,
- const std::shared_ptr<const KeyRequirementSequence> & k,
- const std::shared_ptr<const ChoiceRequirementSequence> & a,
+ const std::shared_ptr<const QualifiedPackageName> & q,
+ const std::shared_ptr<const CategoryNamePart> & c,
+ const std::shared_ptr<const PackageNamePart> & p,
+ const std::shared_ptr<VersionRequirements> & v,
+ const VersionRequirementsMode m,
+ const std::shared_ptr<const SlotRequirement> & s,
+ const std::shared_ptr<const RepositoryName> & ri,
+ const std::shared_ptr<const RepositoryName> & rf,
+ const std::shared_ptr<const AdditionalPackageDepSpecRequirements> & u,
const std::string & st) :
- package_name_requirement(q),
- category_name_part_requirement(c),
- package_name_part_requirement(p),
- all_versions(v),
- any_slot(s),
- exact_slot(xs),
+ package_ptr(q),
+ category_name_part_ptr(c),
+ package_name_part_ptr(p),
+ version_requirements(v),
+ version_requirements_mode(m),
+ slot(s),
in_repository(ri),
from_repository(rf),
- all_keys(k),
- all_choices(a),
+ additional_requirements(u),
str(st)
{
}
@@ -224,58 +219,43 @@ deep_copy(const std::shared_ptr<const T_> & x)
return std::shared_ptr<T_>();
}
-namespace
-{
- template <typename T_>
- std::shared_ptr<Sequence<std::shared_ptr<const T_> > > get_requirements(const std::shared_ptr<const PackageDepSpecRequirementSequence> & s)
- {
- auto result(std::make_shared<Sequence<std::shared_ptr<const T_> > >());
- for (auto i(s->begin()), i_end(s->end()) ;
- i != i_end ; ++i)
- {
- auto v(visitor_cast<const T_>(**i));
- if (! v)
- continue;
-
- result->push_back(std::static_pointer_cast<const T_>(*i));
- }
-
- return result;
- }
-}
-
PythonPackageDepSpec::PythonPackageDepSpec(const PackageDepSpec & p) :
PythonStringDepSpec(p.text()),
_imp(
- p.package_name_requirement(),
- p.category_name_part_requirement(),
- p.package_name_part_requirement(),
- get_requirements<VersionRequirement>(p.requirements()),
- p.any_slot_requirement(),
- p.exact_slot_requirement(),
- p.in_repository_requirement(),
- p.from_repository_requirement(),
- get_requirements<KeyRequirement>(p.requirements()),
- get_requirements<ChoiceRequirement>(p.requirements()),
+ deep_copy(p.package_ptr()),
+ deep_copy(p.category_name_part_ptr()),
+ deep_copy(p.package_name_part_ptr()),
+ std::make_shared<VersionRequirements>(),
+ p.version_requirements_mode(),
+ p.slot_requirement_ptr(),
+ deep_copy(p.in_repository_ptr()),
+ deep_copy(p.from_repository_ptr()),
+ p.additional_requirements_ptr(),
stringify(p))
{
+ if (p.version_requirements_ptr())
+ {
+ std::copy(p.version_requirements_ptr()->begin(), p.version_requirements_ptr()->end(),
+ _imp->version_requirements->back_inserter());
+ }
}
PythonPackageDepSpec::PythonPackageDepSpec(const PythonPackageDepSpec & p) :
PythonStringDepSpec(p.text()),
_imp(
- p.package_name_requirement(),
- p.category_name_part_requirement(),
- p.package_name_part_requirement(),
- p.all_version_requirements(),
- p.any_slot_requirement(),
- p.exact_slot_requirement(),
- p.in_repository_requirement(),
- p.from_repository_requirement(),
- p.all_key_requirements(),
- p.all_choice_requirements(),
+ deep_copy(p.package_ptr()),
+ deep_copy(p.category_name_part_ptr()),
+ deep_copy(p.package_name_part_ptr()),
+ std::make_shared<VersionRequirements>(),
+ p.version_requirements_mode(),
+ p.slot_requirement_ptr(),
+ deep_copy(p.in_repository_ptr()),
+ deep_copy(p.from_repository_ptr()),
+ p.additional_requirements_ptr(),
p.py_str())
{
+ std::copy(p.version_requirements_ptr()->begin(), p.version_requirements_ptr()->end(),
+ _imp->version_requirements->back_inserter());
}
PythonPackageDepSpec::~PythonPackageDepSpec()
@@ -284,51 +264,43 @@ PythonPackageDepSpec::~PythonPackageDepSpec()
PythonPackageDepSpec::operator PackageDepSpec() const
{
- MutablePackageDepSpecData p({ });
+ PartiallyMadePackageDepSpec p((PartiallyMadePackageDepSpecOptions()));
- if (package_name_requirement())
- p.require_package(package_name_requirement()->name());
+ if (package_ptr())
+ p.package(*package_ptr());
- if (category_name_part_requirement())
- p.require_category_name_part(category_name_part_requirement()->name_part());
+ if (category_name_part_ptr())
+ p.category_name_part(*category_name_part_ptr());
- if (package_name_part_requirement())
- p.require_package_name_part(package_name_part_requirement()->name_part());
+ if (package_name_part_ptr())
+ p.package_name_part(*package_name_part_ptr());
- if (all_version_requirements())
- {
- for (auto i(all_version_requirements()->begin()), i_end(all_version_requirements()->end()) ;
- i != i_end ; ++i)
- p.require_version((*i)->combiner(), (*i)->version_operator(), (*i)->version_spec());
- }
-
- if (any_slot_requirement())
- p.require_any_slot(any_slot_requirement()->locking());
+ p.version_requirements_mode(version_requirements_mode());
- if (exact_slot_requirement())
- p.require_exact_slot(exact_slot_requirement()->name(), exact_slot_requirement()->locked());
+ if (slot_requirement_ptr())
+ p.slot_requirement(slot_requirement_ptr());
- if (in_repository_requirement())
- p.require_in_repository(in_repository_requirement()->name());
+ if (in_repository_ptr())
+ p.in_repository(*in_repository_ptr());
- if (from_repository_requirement())
- p.require_from_repository(from_repository_requirement()->name());
+ if (from_repository_ptr())
+ p.from_repository(*from_repository_ptr());
- if (all_choice_requirements())
+ if (additional_requirements_ptr())
{
- for (ChoiceRequirementSequence::ConstIterator i(all_choice_requirements()->begin()),
- i_end(all_choice_requirements()->end()) ; i != i_end ; ++i)
- p.require_choice(*i);
+ for (AdditionalPackageDepSpecRequirements::ConstIterator i(additional_requirements_ptr()->begin()),
+ i_end(additional_requirements_ptr()->end()) ; i != i_end ; ++i)
+ p.additional_requirement(*i);
}
- if (all_key_requirements())
+ if (version_requirements_ptr())
{
- for (auto i(all_key_requirements()->begin()), i_end(all_key_requirements()->end()) ;
- i != i_end ; ++i)
- p.require_key((*i)->key_type(), (*i)->key(), (*i)->operation(), (*i)->pattern());
+ for (VersionRequirements::ConstIterator i(version_requirements_ptr()->begin()),
+ i_end(version_requirements_ptr()->end()) ; i != i_end ; ++i)
+ p.version_requirement(*i);
}
- return PackageDepSpec(p);
+ return p.to_package_dep_spec();
}
@@ -337,64 +309,64 @@ PythonPackageDepSpec::operator std::shared_ptr<PackageDepSpec>() const
return std::make_shared<PackageDepSpec>(*this);
}
-const std::shared_ptr<const NameRequirement>
-PythonPackageDepSpec::package_name_requirement() const
+std::shared_ptr<const QualifiedPackageName>
+PythonPackageDepSpec::package_ptr() const
{
- return _imp->package_name_requirement;
+ return _imp->package_ptr;
}
-const std::shared_ptr<const PackageNamePartRequirement>
-PythonPackageDepSpec::package_name_part_requirement() const
+std::shared_ptr<const PackageNamePart>
+PythonPackageDepSpec::package_name_part_ptr() const
{
- return _imp->package_name_part_requirement;
+ return _imp->package_name_part_ptr;
}
-const std::shared_ptr<const CategoryNamePartRequirement>
-PythonPackageDepSpec::category_name_part_requirement() const
+std::shared_ptr<const CategoryNamePart>
+PythonPackageDepSpec::category_name_part_ptr() const
{
- return _imp->category_name_part_requirement;
+ return _imp->category_name_part_ptr;
}
-const std::shared_ptr<const VersionRequirementSequence>
-PythonPackageDepSpec::all_version_requirements() const
+std::shared_ptr<const VersionRequirements>
+PythonPackageDepSpec::version_requirements_ptr() const
{
- return _imp->all_versions;
+ return _imp->version_requirements;
}
-const std::shared_ptr<const AnySlotRequirement>
-PythonPackageDepSpec::any_slot_requirement() const
+VersionRequirementsMode
+PythonPackageDepSpec::version_requirements_mode() const
{
- return _imp->any_slot;
+ return _imp->version_requirements_mode;
}
-const std::shared_ptr<const ExactSlotRequirement>
-PythonPackageDepSpec::exact_slot_requirement() const
+void
+PythonPackageDepSpec::set_version_requirements_mode(const VersionRequirementsMode m)
{
- return _imp->exact_slot;
+ _imp->version_requirements_mode = m;
}
-const std::shared_ptr<const InRepositoryRequirement>
-PythonPackageDepSpec::in_repository_requirement() const
+std::shared_ptr<const SlotRequirement>
+PythonPackageDepSpec::slot_requirement_ptr() const
{
- return _imp->in_repository;
+ return _imp->slot;
}
-const std::shared_ptr<const FromRepositoryRequirement>
-PythonPackageDepSpec::from_repository_requirement() const
+std::shared_ptr<const RepositoryName>
+PythonPackageDepSpec::in_repository_ptr() const
{
- return _imp->from_repository;
+ return _imp->in_repository;
}
-const std::shared_ptr<const ChoiceRequirementSequence>
-PythonPackageDepSpec::all_choice_requirements() const
+std::shared_ptr<const RepositoryName>
+PythonPackageDepSpec::from_repository_ptr() const
{
- return _imp->all_choices;
+ return _imp->from_repository;
}
-const std::shared_ptr<const KeyRequirementSequence>
-PythonPackageDepSpec::all_key_requirements() const
+std::shared_ptr<const AdditionalPackageDepSpecRequirements>
+PythonPackageDepSpec::additional_requirements_ptr() const
{
- return _imp->all_keys;
+ return _imp->additional_requirements;
}
std::string
@@ -1228,40 +1200,47 @@ void expose_dep_spec()
bp::no_init
)
- .add_property("package_name_requirement", &PythonPackageDepSpec::package_name_requirement,
- "[ro] NameRequirement\n"
- "Qualified package name requirement (may be None)."
+ .add_property("package", &PythonPackageDepSpec::package_ptr,
+ "[ro] QualifiedPackageName\n"
+ "Qualified package name."
+ )
+
+ .add_property("package_name_part", &PythonPackageDepSpec::package_name_part_ptr,
+ "[ro] PackageNamePart\n"
+ "Package name part (may be None)"
)
- .add_property("package_name_part_requirement", &PythonPackageDepSpec::package_name_part_requirement,
- "[ro] CategoryNamePartRequirement\n"
- "Package name part requirement (may be None)"
+ .add_property("category_name_part", &PythonPackageDepSpec::category_name_part_ptr,
+ "[ro] CategoryNamePart\n"
+ "Category name part (may be None)."
)
- .add_property("category_name_part_requirement", &PythonPackageDepSpec::category_name_part_requirement,
- "[ro] CategoryNamePartRequirement\n"
- "Category name part requirement (may be None)."
+ .add_property("version_requirements", &PythonPackageDepSpec::version_requirements_ptr,
+ "[ro] VersionRequirements\n"
+ "Version requirements (may be None)."
)
- .add_property("exact_slot", &PythonPackageDepSpec::exact_slot_requirement,
- "[ro] ExactSlotRequirement\n"
- "Exact slot requirement (may be None)."
+ .add_property("version_requirements_mode", &PythonPackageDepSpec::version_requirements_mode,
+ "[ro] VersionRequirementsMode\n"
+ "Version requirements mode."
)
- .add_property("any_slot", &PythonPackageDepSpec::any_slot_requirement,
- "[ro] AnySlotRequirement\n"
- "Any slot requirement (may be None)."
+#if 0
+ .add_property("slot", &PythonPackageDepSpec::slot_ptr,
+ "[ro] SlotName\n"
+ "Slot name (may be None)."
)
+#endif
- .add_property("in_repository_requirement", &PythonPackageDepSpec::in_repository_requirement,
- "[ro] InRepositoryRequirement\n"
- "In repository requirement (may be None)."
+ .add_property("in_repository", &PythonPackageDepSpec::in_repository_ptr,
+ "[ro] RepositoryName\n"
+ "In repository name (may be None)."
)
- .add_property("from_repository_requirement", &PythonPackageDepSpec::from_repository_requirement,
- "[ro] FromRepositoryRequirement\n"
- "From repository requirement (may be None)."
+ .add_property("from_repository", &PythonPackageDepSpec::from_repository_ptr,
+ "[ro] RepositoryName\n"
+ "From repository name (may be None)."
)
#if 0
diff --git a/python/dep_spec.hh b/python/dep_spec.hh
index a6e407f37..1a10fc191 100644
--- a/python/dep_spec.hh
+++ b/python/dep_spec.hh
@@ -172,16 +172,16 @@ namespace paludis
operator PackageDepSpec() const;
operator std::shared_ptr<PackageDepSpec>() const;
- const std::shared_ptr<const NameRequirement> package_name_requirement() const;
- const std::shared_ptr<const PackageNamePartRequirement> package_name_part_requirement() const;
- const std::shared_ptr<const CategoryNamePartRequirement> category_name_part_requirement() const;
- const std::shared_ptr<const VersionRequirementSequence> all_version_requirements() const;
- const std::shared_ptr<const InRepositoryRequirement> in_repository_requirement() const;
- const std::shared_ptr<const FromRepositoryRequirement> from_repository_requirement() const;
- const std::shared_ptr<const ExactSlotRequirement> exact_slot_requirement() const;
- const std::shared_ptr<const AnySlotRequirement> any_slot_requirement() const;
- const std::shared_ptr<const KeyRequirementSequence> all_key_requirements() const;
- const std::shared_ptr<const ChoiceRequirementSequence> all_choice_requirements() const;
+ std::shared_ptr<const QualifiedPackageName> package_ptr() const;
+ std::shared_ptr<const PackageNamePart> package_name_part_ptr() const;
+ std::shared_ptr<const CategoryNamePart> category_name_part_ptr() const;
+ std::shared_ptr<const VersionRequirements> version_requirements_ptr() const;
+ VersionRequirementsMode version_requirements_mode() const;
+ void set_version_requirements_mode(const VersionRequirementsMode m);
+ std::shared_ptr<const SlotRequirement> slot_requirement_ptr() const;
+ std::shared_ptr<const RepositoryName> in_repository_ptr() const;
+ std::shared_ptr<const RepositoryName> from_repository_ptr() const;
+ std::shared_ptr<const AdditionalPackageDepSpecRequirements> additional_requirements_ptr() const;
std::string py_str() const;
};
diff --git a/python/dep_spec_TEST.py b/python/dep_spec_TEST.py
index da992cfe5..ec22662c4 100755
--- a/python/dep_spec_TEST.py
+++ b/python/dep_spec_TEST.py
@@ -64,12 +64,24 @@ class TestCase_1_DepSpecs(unittest.TestCase):
def test_05_package(self):
self.get_depspecs()
- self.assertEqual(str(self.pds.package_name_requirement.name), "foo/bar")
+ self.assertEqual(str(self.pds.package), "foo/bar")
def test_06_in_from_repository(self):
self.get_depspecs()
- self.assertEqual(str(self.pds.in_repository_requirement.name), "testrepo")
- self.assertEqual(self.pds.from_repository_requirement, None)
+ self.assertEqual(str(self.pds.in_repository), "testrepo")
+ self.assertEqual(self.pds.from_repository, None)
+
+ def test_07_version_requirements(self):
+ self.get_depspecs()
+ vrc = self.pds.version_requirements
+
+ self.assertEquals(len(list(vrc)), 1)
+ self.assertEquals(iter(vrc).next().version_spec, VersionSpec("1"))
+ self.assertEquals(iter(vrc).next().version_operator.value, VersionOperator(">=").value)
+
+ def test_08_version_requirements_mode(self):
+ self.get_depspecs()
+ self.assertEquals(self.pds.version_requirements_mode, VersionRequirementsMode.AND)
### def test_09_additional_requirements(self):
### spec = parse_user_package_dep_spec("foo/monkey[foo]", UserPackageDepSpecOptions())
diff --git a/python/generator_TEST.py b/python/generator_TEST.py
index a35833b0b..4d8b0deed 100644
--- a/python/generator_TEST.py
+++ b/python/generator_TEST.py
@@ -2,7 +2,7 @@
# vim: set fileencoding=utf-8 sw=4 sts=4 et :
#
-# Copyright (c) 2008, 2011 Ciaran McCreesh
+# Copyright (c) 2008 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
@@ -35,8 +35,8 @@ class TestCase_01_Generator(unittest.TestCase):
self.assertEquals(str(Generator.Matches(parse_user_package_dep_spec("foo/bar",
env, []), MatchPackageOptions())), "packages matching foo/bar")
self.assertEquals(str(Generator.Matches(parse_user_package_dep_spec("foo/bar",
- env, []), [MatchPackageOption.IGNORE_CHOICE_REQUIREMENTS])),
- "packages matching foo/bar (ignoring choice requirements)")
+ env, []), [MatchPackageOption.IGNORE_ADDITIONAL_REQUIREMENTS])),
+ "packages matching foo/bar (ignoring additional requirements)")
if __name__ == "__main__":
diff --git a/python/mask_TEST.py b/python/mask_TEST.py
index 5190afda5..f38a2dad3 100755
--- a/python/mask_TEST.py
+++ b/python/mask_TEST.py
@@ -98,7 +98,7 @@ class TestCase_01_Masks(unittest.TestCase):
self.assertEquals(m.key(), "A")
self.assertEquals(m.description(), "by association")
- self.assertEquals(m.associated_package_spec().package_name_requirement.name, "masked/repo")
+ self.assertEquals(m.associated_package_spec().package, "masked/repo")
elif os.environ.get("PALUDIS_ENABLE_VIRTUALS_REPOSITORY") != "no":
raise "oops"
diff --git a/python/package_dep_spec_constraint.cc b/python/package_dep_spec_constraint.cc
deleted file mode 100644
index d794a3934..000000000
--- a/python/package_dep_spec_constraint.cc
+++ /dev/null
@@ -1,253 +0,0 @@
-/* vim: set sw=4 sts=4 et foldmethod=syntax : */
-
-/*
- * Copyright (c) 2007 Piotr Jaroszyński
- * Copyright (c) 2011 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 <python/paludis_python.hh>
-#include <paludis/util/wrapped_forward_iterator-impl.hh>
-#include <paludis/util/fs_path.hh>
-#include <paludis/package_dep_spec_requirement.hh>
-
-using namespace paludis;
-using namespace paludis::python;
-namespace bp = boost::python;
-
-// For classes derived from PackageDepSpecRequirement
-template <typename C_>
-class class_package_dep_spec_requirement :
- public bp::class_<C_, std::shared_ptr<C_>, bp::bases<PackageDepSpecRequirement>, boost::noncopyable>
-{
- public:
- template <class Init_>
- class_package_dep_spec_requirement(const std::string & name, const std::string & class_doc, Init_ initspec) :
- bp::class_<C_, std::shared_ptr<C_>, bp::bases<PackageDepSpecRequirement>, boost::noncopyable>(
- name.c_str(), class_doc.c_str(), initspec)
- {
- bp::register_ptr_to_python<std::shared_ptr<const C_> >();
- bp::implicitly_convertible<std::shared_ptr<C_>, std::shared_ptr<PackageDepSpecRequirement> >();
- }
-};
-
-void expose_package_dep_spec_requirement()
-{
- /**
- * Enums
- */
- enum_auto("KeyRequirementOperation", last_kro,
- "The operation for a KeyRequirement");
-
- /**
- * PackageDepSpecRequirement
- */
- bp::register_ptr_to_python<std::shared_ptr<const PackageDepSpecRequirement> >();
- bp::implicitly_convertible<std::shared_ptr<PackageDepSpecRequirement>,
- std::shared_ptr<const PackageDepSpecRequirement> >();
- bp::class_<PackageDepSpecRequirement, boost::noncopyable>
- (
- "PackageDepSpecRequirement",
- "Base class for a requirement for a PackageDepSpec.",
- bp::no_init
- )
- ;
-
- /**
- * NameRequirement
- */
- class_package_dep_spec_requirement<NameRequirement>
- (
- "NameRequirement",
- "A cat/pkg requirement for a PackageDepSpec.",
- bp::no_init
- )
-
- .add_property("name", &NameRequirement::name,
- "[RO] The cat/pkg in question"
- )
- ;
-
- /**
- * PackageNamePartRequirement
- */
- class_package_dep_spec_requirement<PackageNamePartRequirement>
- (
- "PackageNamePartRequirement",
- "A /pkg requirement for a PackageDepSpec.",
- bp::no_init
- )
-
- .add_property("name_part", &PackageNamePartRequirement::name_part,
- "[RO] The /pkg in question"
- )
- ;
-
- /**
- * CategoryNamePartRequirement
- */
- class_package_dep_spec_requirement<CategoryNamePartRequirement>
- (
- "CategoryNamePartRequirement",
- "A cat/ requirement for a PackageDepSpec.",
- bp::no_init
- )
-
- .add_property("name_part", &CategoryNamePartRequirement::name_part,
- "[RO] The cat/ in question"
- )
- ;
-
- /**
- * InRepositoryRequirement
- */
- class_package_dep_spec_requirement<InRepositoryRequirement>
- (
- "InRepositoryRequirement",
- "A ::repo requirement for a PackageDepSpec.",
- bp::no_init
- )
-
- .add_property("name", &InRepositoryRequirement::name,
- "[RO] The ::repo name in question"
- )
- ;
-
- /**
- * FromRepositoryRequirement
- */
- class_package_dep_spec_requirement<FromRepositoryRequirement>
- (
- "FromRepositoryRequirement",
- "A ::repo-> requirement for a PackageDepSpec.",
- bp::no_init
- )
-
- .add_property("name", &FromRepositoryRequirement::name,
- "[RO] The ::repo-> name in question"
- )
- ;
-
- /**
- * InstalledAtPathRequirement
- */
- class_package_dep_spec_requirement<InstalledAtPathRequirement>
- (
- "InstalledAtPathRequirement",
- "A ::/ requirement for a PackageDepSpec.",
- bp::no_init
- )
-
- .add_property("path", &InstalledAtPathRequirement::path,
- "[RO] The ::/ path in question"
- )
- ;
-
- /**
- * InstallableToPathRequirement
- */
- class_package_dep_spec_requirement<InstallableToPathRequirement>
- (
- "InstalledableToPathRequirement",
- "A ::/? requirement for a PackageDepSpec.",
- bp::no_init
- )
-
- .add_property("path", &InstallableToPathRequirement::path,
- "[RO] The ::/? path in question"
- )
-
- .add_property("include_masked", &InstallableToPathRequirement::include_masked,
- "[RO] Whether to include masked, as per ::/??"
- )
- ;
-
- /**
- * InstallableToRepositoryRequirement
- */
- class_package_dep_spec_requirement<InstallableToRepositoryRequirement>
- (
- "InstalledableToPathRequirement",
- "A ::/? requirement for a PackageDepSpec.",
- bp::no_init
- )
-
- .add_property("name", &InstallableToRepositoryRequirement::name,
- "[RO] The ::repo? in question"
- )
-
- .add_property("include_masked", &InstallableToRepositoryRequirement::include_masked,
- "[RO] Whether to include masked, as per ::repo??"
- )
- ;
-
- /**
- * AnySlotRequirement
- */
- class_package_dep_spec_requirement<AnySlotRequirement>
- (
- "AnySlotRequirement",
- "A :* or := requirement for a PackageDepSpec.",
- bp::no_init
- )
-
- .add_property("locking", &AnySlotRequirement::locking,
- "[RO] Are we locking (:= rather than :*)?"
- )
- ;
-
- /**
- * ExactSlotRequirement
- */
- class_package_dep_spec_requirement<ExactSlotRequirement>
- (
- "ExactSlotRequirement",
- "A :slot or :=slot requirement for a PackageDepSpec.",
- bp::no_init
- )
-
- .add_property("locked", &ExactSlotRequirement::locked,
- "[RO] Are we locked (:=blah)?"
- )
-
- .add_property("name", &ExactSlotRequirement::name,
- "[RO] The slot name"
- )
- ;
-
- /**
- * KeyRequirement
- */
- class_package_dep_spec_requirement<KeyRequirement>
- (
- "KeyRequirement",
- "A [.key=value] requirement for a PackageDepSpec.",
- bp::no_init
- )
-
- .add_property("key", &KeyRequirement::key,
- "[RO] The key"
- )
-
- .add_property("pattern", &KeyRequirement::pattern,
- "[RO] The pattern"
- )
-
- .add_property("operation", &KeyRequirement::operation,
- "[RO] The operation"
- )
- ;
-}
-
diff --git a/python/paludis_python.hh b/python/paludis_python.hh
index 5df480097..aacf7beac 100644
--- a/python/paludis_python.hh
+++ b/python/paludis_python.hh
@@ -188,11 +188,11 @@ void expose_mask() PALUDIS_VISIBLE;
void expose_match_package() PALUDIS_VISIBLE;
void expose_metadata_key() PALUDIS_VISIBLE;
void expose_name() PALUDIS_VISIBLE;
-void expose_package_dep_spec_requirement() PALUDIS_VISIBLE;
void expose_package_id() PALUDIS_VISIBLE;
void expose_repository() PALUDIS_VISIBLE;
void expose_selection() PALUDIS_VISIBLE;
void expose_version_operator() PALUDIS_VISIBLE;
+void expose_version_requirements() PALUDIS_VISIBLE;
void expose_version_spec() PALUDIS_VISIBLE;
#endif
diff --git a/python/paludis_python_so.cc b/python/paludis_python_so.cc
index 179a11907..f8b4e3eca 100644
--- a/python/paludis_python_so.cc
+++ b/python/paludis_python_so.cc
@@ -33,10 +33,10 @@ BOOST_PYTHON_MODULE(paludis)
expose_exception();
expose_version_spec();
expose_version_operator();
+ expose_version_requirements();
expose_fs_path();
expose_contents();
expose_filter(); /* must be before dep_spec */
- expose_package_dep_spec_requirement();
expose_dep_spec();
expose_dep_label();
expose_name();
diff --git a/python/version_requirements.cc b/python/version_requirements.cc
new file mode 100644
index 000000000..3ec32da3c
--- /dev/null
+++ b/python/version_requirements.cc
@@ -0,0 +1,85 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2007 Piotr Jaroszyński
+ *
+ * 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 <python/paludis_python.hh>
+#include <python/iterable.hh>
+
+#include <paludis/version_requirements.hh>
+#include <paludis/util/wrapped_forward_iterator.hh>
+#include <paludis/util/make_named_values.hh>
+
+using namespace paludis;
+using namespace paludis::python;
+namespace bp = boost::python;
+
+namespace
+{
+ VersionRequirement * make_version_requirement(const VersionOperator & op, const VersionSpec & spec)
+ {
+ return new VersionRequirement(make_named_values<VersionRequirement>(
+ n::version_operator() = op,
+ n::version_spec() = spec
+ ));
+ }
+}
+
+void expose_version_requirements()
+{
+ /**
+ * Enums
+ */
+ enum_auto("VersionRequirementsMode", last_vr,
+ "Whether our version requirements are an 'and' or an 'or' set.");
+
+ /**
+ * VersionRequirement
+ */
+ bp::class_<VersionRequirement>
+ (
+ "VersionRequirement",
+ bp::no_init
+ )
+
+ .def("__init__",
+ bp::make_constructor(&make_version_requirement),
+ "__init__(VersionOperator, VersionSpec)"
+ )
+
+ .add_property("version_operator",
+ &named_values_getter<VersionRequirement, n::version_operator, VersionOperator, &VersionRequirement::version_operator>,
+ &named_values_setter<VersionRequirement, n::version_operator, VersionOperator, &VersionRequirement::version_operator>,
+ "[rw] VersionOperator"
+ )
+
+ .add_property("version_spec",
+ &named_values_getter<VersionRequirement, n::version_spec, VersionSpec, &VersionRequirement::version_spec>,
+ &named_values_setter<VersionRequirement, n::version_spec, VersionSpec, &VersionRequirement::version_spec>,
+ "[rw] VersionSpec"
+ )
+ ;
+
+ /**
+ * VersionRequirements
+ */
+ class_iterable<VersionRequirements>
+ (
+ "VersionRequirements",
+ "Iterable collection of VersionRequirement instances, usually for a PackageDepSpec."
+ );
+}
diff --git a/python/version_requirements_TEST.py b/python/version_requirements_TEST.py
new file mode 100755
index 000000000..46321ed4f
--- /dev/null
+++ b/python/version_requirements_TEST.py
@@ -0,0 +1,38 @@
+#!/usr/bin/env python
+# vim: set fileencoding=utf-8 sw=4 sts=4 et :
+
+#
+# Copyright (c) 2007 Piotr Jaroszyński
+#
+# 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
+#
+
+from paludis import *
+import unittest
+
+class TestCase_VersionRequirements(unittest.TestCase):
+ def test_01_init(self):
+ VersionRequirement("<", VersionSpec("0"))
+ VersionRequirement(VersionOperatorValue.LESS, VersionSpec("0"))
+
+ def test_02_data_members(self):
+ v1 = VersionRequirement("<", VersionSpec("0"))
+ v1.version_operator = ">"
+ v1.version_spec = VersionSpec("1")
+
+ self.assertEquals(str(v1.version_operator), ">")
+ self.assertEquals(str(v1.version_spec), "1")
+
+if __name__ == "__main__":
+ unittest.main()