aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Piotr Jaroszyński <peper@gentoo.org> 2007-10-08 20:27:48 +0000
committerAvatar Piotr Jaroszyński <peper@gentoo.org> 2007-10-08 20:27:48 +0000
commit61795d66c7229ab282d5ed0339b013efeab2f1ce (patch)
tree4dff0b37f983d635e5ee1082461a36303efefc93
parent1bdf09699a222f8c97163ef6fd75a16533abf578 (diff)
downloadpaludis-61795d66c7229ab282d5ed0339b013efeab2f1ce.tar.gz
paludis-61795d66c7229ab282d5ed0339b013efeab2f1ce.tar.xz
(python) Add Formatters.
-rw-r--r--python/Makefile.am15
-rw-r--r--python/additional_tests.cc71
-rw-r--r--python/dep_spec.cc203
-rw-r--r--python/dep_spec.hh1
-rw-r--r--python/formatter.cc432
-rw-r--r--python/nice_names.nn95
-rw-r--r--python/paludis_python.hh1
-rw-r--r--python/paludis_python_so.cc1
8 files changed, 652 insertions, 167 deletions
diff --git a/python/Makefile.am b/python/Makefile.am
index 45b9d23..e11cf1e 100644
--- a/python/Makefile.am
+++ b/python/Makefile.am
@@ -38,7 +38,8 @@ IF_PYTHON_TESTS = \
metadata_key_TEST.py \
mask_TEST.py \
package_id_TEST.py \
- dep_list_TEST.py
+ dep_list_TEST.py \
+ formatter_TEST.py
IF_PYTHON_QA_TESTS = \
qa_TEST.py
@@ -55,11 +56,13 @@ IF_PYTHON_SOURCES = \
dep_tag.cc \
environment.cc \
exception.hh exception.cc \
+ formatter.cc \
fs_entry.cc \
mask.cc \
metadata_key.cc \
mutex.hh mutex.cc \
name.cc \
+ nice_names-nn.hh nice_names-nn.cc \
log.cc \
package_database.cc \
package_id.cc \
@@ -69,6 +72,9 @@ IF_PYTHON_SOURCES = \
version_requirements.cc \
version_spec.cc
+BUILT_SOURCES = \
+ nice_names-nn.hh nice_names-nn.cc
+
IF_PYTHON_QA_SOURCES = \
qa.cc
@@ -80,6 +86,7 @@ EXTRA_DIST = $(IF_PYTHON_TESTS) $(IF_PYTHON_SOURCES) \
environment_TEST_setup.sh environment_TEST_cleanup.sh \
mask_TEST_setup.sh mask_TEST_cleanup.sh \
metadata_key_TEST_setup.sh metadata_key_TEST_cleanup.sh \
+ nice_names.nn \
package_database_TEST_setup.sh package_database_TEST_cleanup.sh \
package_id_TEST_setup.sh package_id_TEST_cleanup.sh \
query_TEST_setup.sh query_TEST_cleanup.sh \
@@ -149,6 +156,12 @@ TESTS = $(IF_PYTHON_TESTS)
endif
+nice_names-nn.hh : nice_names.nn $(top_srcdir)/misc/make_nn.bash
+ if ! $(top_srcdir)/misc/make_nn.bash --header $(srcdir)/nice_names.nn > $@ ; then rm -f $@ ; exit 1 ; fi
+
+nice_names-nn.cc : nice_names.nn $(top_srcdir)/misc/make_nn.bash
+ if ! $(top_srcdir)/misc/make_nn.bash --source $(srcdir)/nice_names.nn > $@ ; then rm -f $@ ; exit 1 ; fi
+
libpaludispython_la_LIBADD = \
$(top_builddir)/paludis/libpaludis.la \
$(top_builddir)/paludis/util/libpaludisutil.la \
diff --git a/python/additional_tests.cc b/python/additional_tests.cc
index 126364d..ef69e2d 100644
--- a/python/additional_tests.cc
+++ b/python/additional_tests.cc
@@ -29,6 +29,7 @@
#include <paludis/repositories/fake/fake_package_id.hh>
#include <paludis/mask.hh>
#include <paludis/hook.hh>
+#include <paludis/formatter.hh>
#include <paludis/stringify_formatter-impl.hh>
using namespace paludis;
@@ -187,6 +188,66 @@ namespace metadata_key
}
}
+namespace formatter
+{
+ using namespace format;
+
+ // CanFormat for PlainRoles
+ void test_plain_roles(CanFormat<PlainTextDepSpec> & f)
+ {
+ PlainTextDepSpec d("foo");
+ f.format(d, Plain());
+ }
+
+ // CanFormat for AcceptableRoles
+ void test_acceptable_roles(CanFormat<KeywordName> & f)
+ {
+ KeywordName k("keyword");
+ f.format(k, Plain());
+ f.format(k, Accepted());
+ f.format(k, Unaccepted());
+ }
+
+ // CanFormat for UseRoles
+ void test_use_roles(CanFormat<UseFlagName> & f)
+ {
+ UseFlagName u("use");
+ f.format(u, Plain());
+ f.format(u, Enabled());
+ f.format(u, Disabled());
+ f.format(u, Forced());
+ f.format(u, Masked());
+ }
+
+ // CanFormat for IUseRoles
+ void test_iuse_roles(CanFormat<IUseFlag> & f)
+ {
+ IUseFlag u("iuse_flag", iuse_pm_permissive, 1);
+ f.format(u, Plain());
+ f.format(u, Enabled());
+ f.format(u, Disabled());
+ f.format(u, Forced());
+ f.format(u, Masked());
+ f.decorate(u, "%", Added());
+ f.decorate(u, "*", Changed());
+ }
+
+ // CanFormat for PackageRoles
+ void test_package_roles(CanFormat<PackageDepSpec> & f)
+ {
+ PackageDepSpec p("cat/pkg", pds_pm_permissive);
+ f.format(p, Plain());
+ f.format(p, Installed());
+ f.format(p, Installable());
+ }
+
+ // CanSpace
+ void test_can_space(CanSpace & f)
+ {
+ f.newline();
+ f.indent(1);
+ }
+}
void expose_additional_tests()
{
@@ -222,4 +283,14 @@ void expose_additional_tests()
bp::def("test_metadata_restrict_spec_tree_key", &metadata_key::test_metadata_spec_tree_key<RestrictSpecTree>);
bp::def("test_metadata_fetchable_uri_spec_tree_key", &metadata_key::test_metadata_spec_tree_key<FetchableURISpecTree>);
bp::def("test_metadata_simple_uri_spec_tree_key", &metadata_key::test_metadata_spec_tree_key<SimpleURISpecTree>);
+
+ /**
+ * Formatter tests
+ */
+ bp::def("test_plain_roles", &formatter::test_plain_roles);
+ bp::def("test_acceptable_roles", &formatter::test_acceptable_roles);
+ bp::def("test_use_roles", &formatter::test_use_roles);
+ bp::def("test_iuse_roles", &formatter::test_iuse_roles);
+ bp::def("test_package_roles", &formatter::test_package_roles);
+ bp::def("test_can_space", &formatter::test_can_space);
}
diff --git a/python/dep_spec.cc b/python/dep_spec.cc
index 6d9e3d9..273bf52 100644
--- a/python/dep_spec.cc
+++ b/python/dep_spec.cc
@@ -20,6 +20,7 @@
#include "dep_spec.hh"
#include <python/paludis_python.hh>
#include <python/exception.hh>
+#include <python/nice_names-nn.hh>
#include <paludis/dep_tag.hh>
#include <paludis/version_requirements.hh>
@@ -404,6 +405,11 @@ PythonPlainTextDepSpec::PythonPlainTextDepSpec(const PlainTextDepSpec & d) :
{
}
+PythonPlainTextDepSpec::PythonPlainTextDepSpec(const PythonPlainTextDepSpec & d) :
+ PythonStringDepSpec(d.text())
+{
+}
+
PythonNamedSetDepSpec::PythonNamedSetDepSpec(const SetName & s) :
PythonStringDepSpec(stringify(s)),
_name(s)
@@ -695,165 +701,6 @@ struct AllowedTypes<SetSpecTree>
AllowedTypes(const NamedSetDepSpec &) {};
};
-
-template <typename>
-struct NiceClassNames;
-
-template<>
-struct NiceClassNames<DepSpec>
-{
- static const char * name;
-};
-const char * NiceClassNames<DepSpec>::name = "DepSpec";
-
-template<>
-struct NiceClassNames<AllDepSpec>
-{
- static const char * name;
-};
-const char * NiceClassNames<AllDepSpec>::name = "AllDepSpec";
-
-template<>
-struct NiceClassNames<AnyDepSpec>
-{
- static const char * name;
-};
-const char * NiceClassNames<AnyDepSpec>::name = "AnyDepSpec";
-
-template<>
-struct NiceClassNames<UseDepSpec>
-{
- static const char * name;
-};
-const char * NiceClassNames<UseDepSpec>::name = "UseDepSpec";
-
-template<>
-struct NiceClassNames<StringDepSpec>
-{
- static const char * name;
-};
-const char * NiceClassNames<StringDepSpec>::name = "StringDepSpec";
-
-template<>
-struct NiceClassNames<PlainTextDepSpec>
-{
- static const char * name;
-};
-const char * NiceClassNames<PlainTextDepSpec>::name = "PlainTextDepSpec";
-
-template<>
-struct NiceClassNames<NamedSetDepSpec>
-{
- static const char * name;
-};
-const char * NiceClassNames<NamedSetDepSpec>::name = "NamedSetDepSpec";
-
-template<>
-struct NiceClassNames<LicenseDepSpec>
-{
- static const char * name;
-};
-const char * NiceClassNames<LicenseDepSpec>::name = "LicenseDepSpec";
-
-template<>
-struct NiceClassNames<SimpleURIDepSpec>
-{
- static const char * name;
-};
-const char * NiceClassNames<SimpleURIDepSpec>::name = "SimpleURIDepSpec";
-
-template<>
-struct NiceClassNames<PackageDepSpec>
-{
- static const char * name;
-};
-const char * NiceClassNames<PackageDepSpec>::name = "PackageDepSpec";
-
-template<>
-struct NiceClassNames<FetchableURIDepSpec>
-{
- static const char * name;
-};
-const char * NiceClassNames<FetchableURIDepSpec>::name = "FetchableURIDepSpec";
-
-template<>
-struct NiceClassNames<URILabelsDepSpec>
-{
- static const char * name;
-};
-const char * NiceClassNames<URILabelsDepSpec>::name = "URILabelsDepSpec";
-
-template<>
-struct NiceClassNames<DependencyLabelsDepSpec>
-{
- static const char * name;
-};
-const char * NiceClassNames<DependencyLabelsDepSpec>::name = "DependencyLabelsDepSpec";
-
-template<>
-struct NiceClassNames<BlockDepSpec>
-{
- static const char * name;
-};
-const char * NiceClassNames<BlockDepSpec>::name = "BlockDepSpec";
-
-template<>
-struct NiceClassNames<GenericSpecTree>
-{
- static const char * name;
-};
-const char * NiceClassNames<GenericSpecTree>::name = "GenericSpecTree";
-
-template<>
-struct NiceClassNames<LicenseSpecTree>
-{
- static const char * name;
-};
-const char * NiceClassNames<LicenseSpecTree>::name = "LicenseSpecTree";
-
-template<>
-struct NiceClassNames<FetchableURISpecTree>
-{
- static const char * name;
-};
-const char * NiceClassNames<FetchableURISpecTree>::name = "FetchableURISpecTree";
-
-template<>
-struct NiceClassNames<SimpleURISpecTree>
-{
- static const char * name;
-};
-const char * NiceClassNames<SimpleURISpecTree>::name = "SimpleURISpecTree";
-
-template<>
-struct NiceClassNames<ProvideSpecTree>
-{
- static const char * name;
-};
-const char * NiceClassNames<ProvideSpecTree>::name = "ProvideSpecTree";
-
-template<>
-struct NiceClassNames<RestrictSpecTree>
-{
- static const char * name;
-};
-const char * NiceClassNames<RestrictSpecTree>::name = "RestrictSpecTree";
-
-template<>
-struct NiceClassNames<DependencySpecTree>
-{
- static const char * name;
-};
-const char * NiceClassNames<DependencySpecTree>::name = "DependencySpecTree";
-
-template<>
-struct NiceClassNames<SetSpecTree>
-{
- static const char * name;
-};
-const char * NiceClassNames<SetSpecTree>::name = "SetSpecTree";
-
-
class PALUDIS_VISIBLE NotAllowedInThisHeirarchy :
public Exception
{
@@ -886,8 +733,8 @@ template <typename H_, typename D_, typename PyD_>
void
Dispatcher<H_, D_, PyD_, false>::do_dispatch(SpecTreeFromPython<H_> *, const PyD_ &)
{
- throw NotAllowedInThisHeirarchy(std::string("Spec parts of type '") + NiceClassNames<D_>::name +
- " are not allowed in a heirarchy of type '" + NiceClassNames<H_>::name + "'");
+ throw NotAllowedInThisHeirarchy(std::string("Spec parts of type '") + NiceNames<D_>::name +
+ " are not allowed in a heirarchy of type '" + NiceNames<H_>::name + "'");
}
template <typename H_, typename D_, typename PyD_>
@@ -1149,9 +996,16 @@ void register_tree_to_python()
tree_to_python<tr1::shared_ptr<typename T_::ConstItem> > >();
}
-struct sp_package_dep_spec_to_python
+struct package_dep_spec_to_python
{
static PyObject *
+ convert(const PackageDepSpec & d)
+ {
+ PythonPackageDepSpec pyd(d);
+ return bp::incref(bp::object(pyd).ptr());
+ }
+
+ static PyObject *
convert(const tr1::shared_ptr<const PackageDepSpec> & d)
{
PythonPackageDepSpec pyd(*d);
@@ -1159,11 +1013,26 @@ struct sp_package_dep_spec_to_python
}
};
-void register_sp_package_dep_spec_to_python()
+void register_package_dep_spec_to_python()
{
- bp::to_python_converter<tr1::shared_ptr<const PackageDepSpec>, sp_package_dep_spec_to_python>();
+ bp::to_python_converter<PackageDepSpec, package_dep_spec_to_python>();
+ bp::to_python_converter<tr1::shared_ptr<const PackageDepSpec>, package_dep_spec_to_python>();
}
+struct plain_text_dep_spec_to_python
+{
+ static PyObject *
+ convert(const PlainTextDepSpec & d)
+ {
+ PythonPlainTextDepSpec pyd(d);
+ return bp::incref(bp::object(pyd).ptr());
+ }
+};
+
+void register_plain_text_dep_spec_to_python()
+{
+ bp::to_python_converter<PlainTextDepSpec, plain_text_dep_spec_to_python>();
+}
template <typename H_>
struct RegisterSpecTreeSPTRFromPython
@@ -1442,7 +1311,7 @@ void expose_dep_spec()
RegisterPackageDepSpecSPTRFromPython();
bp::implicitly_convertible<PackageDepSpec, PythonPackageDepSpec>();
- register_sp_package_dep_spec_to_python();
+ register_package_dep_spec_to_python();
bp::class_<PythonPackageDepSpec, tr1::shared_ptr<const PythonPackageDepSpec>, bp::bases<PythonStringDepSpec> >
(
@@ -1506,7 +1375,9 @@ void expose_dep_spec()
/**
* PlainTextDepSpec
*/
- bp::class_<PythonPlainTextDepSpec, bp::bases<PythonStringDepSpec>, boost::noncopyable>
+ bp::implicitly_convertible<PlainTextDepSpec, PythonPlainTextDepSpec>();
+ register_plain_text_dep_spec_to_python();
+ bp::class_<PythonPlainTextDepSpec, bp::bases<PythonStringDepSpec> >
(
"PlainTextDepSpec",
"A PlainTextDepSpec represents a plain text entry (for example, a RESTRICT keyword).",
diff --git a/python/dep_spec.hh b/python/dep_spec.hh
index 23e9aa3..e38d1a4 100644
--- a/python/dep_spec.hh
+++ b/python/dep_spec.hh
@@ -192,6 +192,7 @@ namespace paludis
public:
PythonPlainTextDepSpec(const std::string &);
PythonPlainTextDepSpec(const PlainTextDepSpec &);
+ PythonPlainTextDepSpec(const PythonPlainTextDepSpec &);
};
class PALUDIS_VISIBLE PythonNamedSetDepSpec :
diff --git a/python/formatter.cc b/python/formatter.cc
new file mode 100644
index 0000000..bc5891f
--- /dev/null
+++ b/python/formatter.cc
@@ -0,0 +1,432 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2007 Piotr Jaroszyński <peper@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
+ */
+
+#define BOOST_PYTHON_MAX_BASES 20
+
+#include <python/paludis_python.hh>
+#include <python/exception.hh>
+#include <python/nice_names-nn.hh>
+
+#include <paludis/formatter.hh>
+#include <paludis/name.hh>
+#include <paludis/dep_spec.hh>
+
+using namespace paludis;
+using namespace paludis::python;
+namespace bp = boost::python;
+
+template <typename T_>
+struct PythonCanFormatBase
+{
+ virtual bp::override get_override(const char *) const = 0;
+
+ template <typename F_>
+ std::string do_format(const T_ & t, const F_ &) const
+ {
+ Lock l(get_mutex());
+
+ std::string func_name(std::string("format_") + LowercaseNiceNames<T_>::name
+ + "_" + LowercaseNiceNames<F_>::name);
+
+ if (bp::override f = this->get_override(func_name.c_str()))
+ return f(t);
+ else
+ throw PythonMethodNotImplemented(std::string("CanFormat") + NiceNames<T_>::name, func_name);
+ }
+};
+
+template <typename T_, typename C_ = typename format::CategorySelector<T_>::Category >
+struct PythonCanFormat;
+
+template <typename T_>
+struct PythonCanFormat<T_, format::PlainRoles> :
+ CanFormat<T_>,
+ PythonCanFormatBase<T_>
+{
+ std::string format(const T_ & t, const format::Plain & f) const
+ {
+ return do_format(t, f);
+ }
+};
+
+template <typename T_>
+struct PythonCanFormat<T_, format::AcceptableRoles> :
+ CanFormat<T_>,
+ PythonCanFormatBase<T_>
+{
+ std::string format(const T_ & t, const format::Plain & f) const
+ {
+ return do_format(t, f);
+ }
+
+ std::string format(const T_ & t, const format::Accepted & f) const
+ {
+ return do_format(t, f);
+ }
+
+ std::string format(const T_ & t, const format::Unaccepted & f) const
+ {
+ return do_format(t, f);
+ }
+};
+
+template <typename T_>
+struct PythonCanFormat<T_, format::UseRoles> :
+ CanFormat<T_>,
+ PythonCanFormatBase<T_>
+{
+ std::string format(const T_ & t, const format::Plain & f) const
+ {
+ return do_format(t, f);
+ }
+
+ std::string format(const T_ & t, const format::Enabled & f) const
+ {
+ return do_format(t, f);
+ }
+
+ std::string format(const T_ & t, const format::Disabled & f) const
+ {
+ return do_format(t, f);
+ }
+
+ std::string format(const T_ & t, const format::Forced & f) const
+ {
+ return do_format(t, f);
+ }
+
+ std::string format(const T_ & t, const format::Masked & f) const
+ {
+ return do_format(t, f);
+ }
+};
+
+template <typename T_>
+struct PythonCanFormat<T_, format::IUseRoles> :
+ CanFormat<T_>,
+ PythonCanFormatBase<T_>
+{
+ template <typename F_>
+ std::string do_decorate(const T_ & t, const std::string & s, const F_ &) const
+ {
+ Lock l(get_mutex());
+
+ std::string func_name(std::string("decorate_") + LowercaseNiceNames<T_>::name
+ + "_" + LowercaseNiceNames<F_>::name);
+
+ if (bp::override f = this->get_override(func_name.c_str()))
+ return f(t, s);
+ else
+ throw PythonMethodNotImplemented(std::string("CanFormat") + NiceNames<T_>::name, func_name);
+ }
+
+ std::string format(const T_ & t, const format::Plain & f) const
+ {
+ return do_format(t, f);
+ }
+
+ std::string format(const T_ & t, const format::Enabled & f) const
+ {
+ return do_format(t, f);
+ }
+
+ std::string format(const T_ & t, const format::Disabled & f) const
+ {
+ return do_format(t, f);
+ }
+
+ std::string format(const T_ & t, const format::Forced & f) const
+ {
+ return do_format(t, f);
+ }
+
+ std::string format(const T_ & t, const format::Masked & f) const
+ {
+ return do_format(t, f);
+ }
+
+ std::string decorate(const T_ & t, const std::string & s, const format::Added & f) const
+ {
+ return do_decorate(t, s, f);
+ }
+
+ std::string decorate(const T_ & t, const std::string & s, const format::Changed & f) const
+ {
+ return do_decorate(t, s, f);
+ }
+};
+
+template <typename T_>
+struct PythonCanFormat<T_, format::PackageRoles> :
+ CanFormat<T_>,
+ PythonCanFormatBase<T_>
+{
+ virtual std::string format(const T_ & t, const format::Plain & f) const
+ {
+ return do_format(t, f);
+ }
+
+ virtual std::string format(const T_ & t, const format::Installed & f) const
+ {
+ return do_format(t, f);
+ }
+
+ virtual std::string format(const T_ & t, const format::Installable & f) const
+ {
+ return do_format(t, f);
+ }
+};
+
+template <typename T_>
+struct PythonCanFormatWrapper:
+ PythonCanFormat<T_>,
+ bp::wrapper<CanFormat<T_> >
+{
+ bp::override get_override(const char * name) const
+ {
+ return bp::wrapper<CanFormat<T_> >::get_override(name);
+ }
+};
+
+struct PythonCanSpace :
+ CanSpace
+{
+ virtual bp::override get_override(const char *) const = 0;
+
+ std::string newline() const
+ {
+ Lock l(get_mutex());
+
+ if (bp::override f = this->get_override("newline"))
+ return f();
+ else
+ throw PythonMethodNotImplemented(std::string("CanSpace"), "newline");
+ }
+
+ std::string indent(const int i) const
+ {
+ Lock l(get_mutex());
+
+ if (bp::override f = this->get_override("indent"))
+ return f(i);
+ else
+ throw PythonMethodNotImplemented(std::string("CanSpace"), "indent");
+ }
+};
+
+struct PythonCanSpaceWrapper :
+ PythonCanSpace,
+ bp::wrapper<CanSpace>
+{
+ bp::override get_override(const char * name) const
+ {
+ return bp::wrapper<CanSpace>::get_override(name);
+ }
+};
+
+class PythonFormatterWrapper :
+ public PythonCanFormat<UseFlagName>,
+ public PythonCanFormat<IUseFlag>,
+ public PythonCanFormat<KeywordName>,
+ public PythonCanFormat<PackageDepSpec>,
+ public PythonCanFormat<BlockDepSpec>,
+ public PythonCanFormat<FetchableURIDepSpec>,
+ public PythonCanFormat<SimpleURIDepSpec>,
+ public PythonCanFormat<DependencyLabelsDepSpec>,
+ public PythonCanFormat<URILabelsDepSpec>,
+ public PythonCanFormat<PlainTextDepSpec>,
+ public PythonCanFormat<LicenseDepSpec>,
+ public PythonCanFormat<UseDepSpec>,
+ public PythonCanFormat<NamedSetDepSpec>,
+ public PythonCanSpace,
+ public bp::wrapper<PythonFormatterWrapper>
+{
+ bp::override get_override(const char * name) const
+ {
+ return bp::wrapper<PythonFormatterWrapper>::get_override(name);
+ }
+};
+
+void expose_formatter()
+{
+ /**
+ * CanFormatUseFlagName
+ */
+ bp::class_<PythonCanFormatWrapper<UseFlagName>, boost::noncopyable>
+ (
+ "CanFormatUseFlagName",
+ "Descendents of this class implement the necessary methods to format a UseFlagName.",
+ bp::init<>("__init__()")
+ );
+
+ /**
+ * CanFormatIUseFlag
+ */
+ bp::class_<PythonCanFormatWrapper<IUseFlag>, boost::noncopyable>
+ (
+ "CanFormatIUseFlag",
+ "Descendents of this class implement the necessary methods to format a IUseFlag.",
+ bp::init<>("__init__()")
+ );
+
+ /**
+ * CanFormatKeywordName
+ */
+ bp::class_<PythonCanFormatWrapper<KeywordName>, boost::noncopyable>
+ (
+ "CanFormatKeywordName",
+ "Descendents of this class implement the necessary methods to format a KeywordName.",
+ bp::init<>("__init__()")
+ );
+
+ /**
+ * CanFormatPackageDepSpec
+ */
+ bp::class_<PythonCanFormatWrapper<PackageDepSpec>, boost::noncopyable>
+ (
+ "CanFormatPackageDepSpec",
+ "Descendents of this class implement the necessary methods to format a PackageDepSpec.",
+ bp::init<>("__init__()")
+ );
+
+ /**
+ * CanFormatBlockDepSpec
+ */
+ bp::class_<PythonCanFormatWrapper<BlockDepSpec>, boost::noncopyable>
+ (
+ "CanFormatBlockDepSpec",
+ "Descendents of this class implement the necessary methods to format a BlockDepSpec.",
+ bp::init<>("__init__()")
+ );
+
+ /**
+ * CanFormatFetchableURIDepSpec
+ */
+ bp::class_<PythonCanFormatWrapper<FetchableURIDepSpec>, boost::noncopyable>
+ (
+ "CanFormatFetchableURIDepSpec",
+ "Descendents of this class implement the necessary methods to format a FetchableURIDepSpec.",
+ bp::init<>("__init__()")
+ );
+
+ /**
+ * CanFormatSimpleURIDepSpec
+ */
+ bp::class_<PythonCanFormatWrapper<SimpleURIDepSpec>, boost::noncopyable>
+ (
+ "CanFormatSimpleURIDepSpec",
+ "Descendents of this class implement the necessary methods to format a SimpleURIDepSpec.",
+ bp::init<>("__init__()")
+ );
+
+ /**
+ * CanFormatDependencyLabelsDepSpec
+ */
+ bp::class_<PythonCanFormatWrapper<DependencyLabelsDepSpec>, boost::noncopyable>
+ (
+ "CanFormatDependencyLabelsDepSpec",
+ "Descendents of this class implement the necessary methods to format a DependencyLabelsDepSpec.",
+ bp::init<>("__init__()")
+ );
+
+ /**
+ * CanFormatURILabelsDepSpec
+ */
+ bp::class_<PythonCanFormatWrapper<URILabelsDepSpec>, boost::noncopyable>
+ (
+ "CanFormatURILabelsDepSpec",
+ "Descendents of this class implement the necessary methods to format an URILabelsDepSpec.",
+ bp::init<>("__init__()")
+ );
+
+ /**
+ * CanFormatPlainTextDepSpec
+ */
+ bp::class_<PythonCanFormatWrapper<PlainTextDepSpec>, boost::noncopyable>
+ (
+ "CanFormatPlainTextDepSpec",
+ "Descendents of this class implement the necessary methods to format a PlainTextDepSpec.",
+ bp::init<>("__init__()")
+ );
+
+ /**
+ * CanFormatLicenseDepSpec
+ */
+ bp::class_<PythonCanFormatWrapper<LicenseDepSpec>, boost::noncopyable>
+ (
+ "CanFormatLicenseDepSpec",
+ "Descendents of this class implement the necessary methods to format a LicenseDepSpec.",
+ bp::init<>("__init__()")
+ );
+
+ /**
+ * CanFormatUseDepSpec
+ */
+ bp::class_<PythonCanFormatWrapper<UseDepSpec>, boost::noncopyable>
+ (
+ "CanFormatUseDepSpec",
+ "Descendents of this class implement the necessary methods to format a UseDepSpec.",
+ bp::init<>("__init__()")
+ );
+
+ /**
+ * CanFormatNamedSetDepSpec
+ */
+ bp::class_<PythonCanFormatWrapper<NamedSetDepSpec>, boost::noncopyable>
+ (
+ "CanFormatNamedSetDepSpec",
+ "Descendents of this class implement the necessary methods to format a NamedSetDepSpec.",
+ bp::init<>("__init__()")
+ );
+
+ /**
+ * CanSpace
+ */
+ bp::class_<PythonCanSpaceWrapper, boost::noncopyable>
+ (
+ "CanSpace",
+ "Descendents of this class implement the necessary methods to format whitespace.",
+ bp::init<>("__init__()")
+ );
+
+ /**
+ * PythonFormatter
+ */
+ bp::class_<PythonFormatterWrapper,
+ bp::bases<
+ CanFormat<UseFlagName>,
+ CanFormat<IUseFlag>,
+ CanFormat<KeywordName>,
+ CanFormat<PackageDepSpec>,
+ CanFormat<BlockDepSpec>,
+ CanFormat<FetchableURIDepSpec>,
+ CanFormat<SimpleURIDepSpec>,
+ CanFormat<DependencyLabelsDepSpec>,
+ CanFormat<URILabelsDepSpec>,
+ CanFormat<PlainTextDepSpec>,
+ CanFormat<LicenseDepSpec>,
+ CanFormat<UseDepSpec>,
+ CanFormat<NamedSetDepSpec>,
+ CanSpace>,
+ boost::noncopyable>
+ (
+ "PythonFormatter",
+ bp::init<>("__init__()")
+ );
+}
diff --git a/python/nice_names.nn b/python/nice_names.nn
new file mode 100644
index 0000000..c22e2cd
--- /dev/null
+++ b/python/nice_names.nn
@@ -0,0 +1,95 @@
+#!/bin/bash
+# vim: set sw=4 sts=4 et ft=sh :
+
+include_hh << END
+#include <paludis/dep_spec-fwd.hh>
+#include <paludis/dep_tree-fwd.hh>
+#include <paludis/formatter.hh>
+END
+
+include_cc << END
+#include "nice_names-nn.hh"
+END
+
+use_namespace "paludis"
+
+make_nn_NiceNames() {
+ namespace "paludis::python"
+
+ # paludis/dep_spec-fwd.hh
+ name "DepSpec"
+ name "PackageDepSpec"
+ name "PlainTextDepSpec"
+ name "LicenseDepSpec"
+ name "FetchableURIDepSpec"
+ name "SimpleURIDepSpec"
+ name "AllDepSpec"
+ name "AnyDepSpec"
+ name "UseDepSpec"
+ name "BlockDepSpec"
+ name "StringDepSpec"
+ name "NamedSetDepSpec"
+ name "URILabelsDepSpec"
+ name "DependencyLabelsDepSpec"
+
+ # paludis/dep_tree-fwd.hh
+ name "GenericSpecTree"
+ name "LicenseSpecTree"
+ name "FetchableURISpecTree"
+ name "SimpleURISpecTree"
+ name "FlattenableSpecTree"
+ name "ProvideSpecTree"
+ name "RestrictSpecTree"
+ name "DependencySpecTree"
+ name "SetSpecTree"
+
+
+ # paludis/name-fwd.hh
+ name "PackageNamePart"
+ name "PackageNamePartSet"
+ name "CategoryNamePart"
+ name "CategoryNamePartSet"
+ name "UseFlagName"
+ name "UseFlagNameSet"
+ name "QualifiedPackageName"
+ name "IUseFlag"
+ name "QualifiedPackageNameSet"
+ name "SlotName"
+ name "RepositoryName"
+ name "RepositoryNameSequence"
+ name "KeywordName"
+ name "KeywordNameSet"
+ name "SetName"
+ name "SetNameSet"
+ name "IUseFlagSet"
+}
+
+make_nn_LowercaseNiceNames() {
+ namespace "paludis::python"
+
+ name "UseFlagName" "use_flag_name"
+ name "IUseFlag" "iuse_flag"
+ name "KeywordName" "keyword_name"
+ name "PackageDepSpec" "package_dep_spec"
+ name "BlockDepSpec" "block_dep_spec"
+ name "FetchableURIDepSpec" "fetchable_uri_dep_spec"
+ name "SimpleURIDepSpec" "simple_uri_dep_spec"
+ name "DependencyLabelsDepSpec" "dependency_labels_dep_spec"
+ name "URILabelsDepSpec" "uri_labels_dep_spec"
+ name "PlainTextDepSpec" "plain_text_dep_spec"
+ name "LicenseDepSpec" "license_dep_spec"
+ name "UseDepSpec" "use_dep_spec"
+ name "NamedSetDepSpec" "named_set_dep_spec"
+
+ name "format::Plain" "plain"
+ name "format::Enabled" "enabled"
+ name "format::Disabled" "disabled"
+ name "format::Masked" "masked"
+ name "format::Forced" "forced"
+ name "format::Changed" "changed"
+ name "format::Added" "added"
+ name "format::Accepted" "accepted"
+ name "format::Unaccepted" "unaccepted"
+ name "format::Installed" "installed"
+ name "format::Installable" "installable"
+}
diff --git a/python/paludis_python.hh b/python/paludis_python.hh
index 14aca88..14aa645 100644
--- a/python/paludis_python.hh
+++ b/python/paludis_python.hh
@@ -164,6 +164,7 @@ void expose_dep_spec() PALUDIS_VISIBLE;
void expose_dep_tag() PALUDIS_VISIBLE;
void expose_environment() PALUDIS_VISIBLE;
void expose_exception() PALUDIS_VISIBLE;
+void expose_formatter() PALUDIS_VISIBLE;
void expose_fs_entry() PALUDIS_VISIBLE;
void expose_log() PALUDIS_VISIBLE;
void expose_mask() PALUDIS_VISIBLE;
diff --git a/python/paludis_python_so.cc b/python/paludis_python_so.cc
index 521824d..1b06d55 100644
--- a/python/paludis_python_so.cc
+++ b/python/paludis_python_so.cc
@@ -48,6 +48,7 @@ BOOST_PYTHON_MODULE(paludis)
expose_action();
expose_package_database();
expose_repository();
+ expose_formatter();
#ifdef ENABLE_QA
expose_qa();
#endif