/* 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 #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace paludis; using namespace paludis::python; namespace bp = boost::python; struct RepositoryWrapper : Repository, bp::wrapper { static RepositoryEnvironmentVariableInterface * get_environment_variable_interface(const Repository & self) { return self.environment_variable_interface(); } static RepositoryDestinationInterface * get_destination_interface(const Repository & self) { return self.destination_interface(); } static PyObject * find_metadata(const Repository & self, const std::string & key) { Repository::MetadataConstIterator i(self.find_metadata(key)); if (i != self.end_metadata()) return bp::incref(bp::object(*i).ptr()); else return Py_None; } }; struct FakeRepositoryWrapper { static std::shared_ptr add_version(FakeRepository & self, const QualifiedPackageName & qpn, const VersionSpec & vs) { return self.add_version(qpn, vs); } }; // FIXME //template //struct repository_interface_to_python //{ // static PyObject * // convert(const I_ & i) // { // return 0; // return bp::incref(bp::object(bp::ptr(&i)).ptr()); // } //}; // //template //void register_repository_interface_to_python() //{ // bp::to_python_converter >(); //} namespace { std::shared_ptr make_fake_repository(const Environment * const env, const RepositoryName & n) { return std::make_shared(make_named_values( n::environment() = env, n::name() = n )); } } void expose_repository() { /** * Repository */ register_shared_ptrs_to_python(rsp_const); bp::class_, boost::noncopyable> ( "Repository", "A Repository provides a representation of a physical repository to an Environment.", bp::no_init ) .add_property("name", &Repository::name, "[ro] RepositoryName\n" "Our name." ) .def("has_category_named", &Repository::has_category_named, "has_category_named(CategoryNamePart, RepositoryContentMayExcludes) -> bool\n" "Do we have a category with the given name?" ) .def("has_package_named", &Repository::has_package_named, "has_package_named(QualifiedPackageName, RepositoryContentMayExcludes) -> bool\n" "Do we have a package in the given category with the given name?" ) .def("category_names", &Repository::category_names, "category_names(RepositoryContentMayExcludes) -> CategoryNamePartIterable\n" "Our category names." ) .def("category_names_containing_package", &Repository::category_names_containing_package, "category_names_containing_package(PackageNamePart, RepositoryContentMayExcludes) -> CategoryNamePartIterable\n" "Fetch categories that contain a named package." ) .def("package_names", &Repository::package_names, "package_names(CategoryNamePart, RepositoryContentMayExcludes) -> QualifiedPackageNameIterable\n" "Fetch our package names." ) .def("package_ids", &Repository::package_ids, bp::with_custodian_and_ward_postcall<0, 1>(), "package_ids(QualifiedPackageName, RepositoryContentMayExcludes) -> PackageIDIterable\n" "Fetch our versions." ) .def("some_ids_might_support_action", &Repository::some_ids_might_support_action, "some_ids_might_support_action(SupportsActionTestBase) -> bool\n" "Might some of our IDs support a particular action?\n\n" "Used to optimise Environment::[]. If a repository doesn't\n" "support, say, InstallAction, a query can skip searching it\n" "entirely when looking for installable packages." ) .add_property("environment_variable_interface", bp::make_function(&RepositoryWrapper::get_environment_variable_interface, bp::return_internal_reference<>()), "[ro] RepositoryEnvironmentInterface" ) .add_property("destination_interface", bp::make_function(&RepositoryWrapper::get_destination_interface, bp::return_internal_reference<>()), "[ro] RepositoryDestinationInterface" ) .def("format_key", &Repository::format_key, "The format_key, if not None, holds our repository's format" ) .def("location_key", &Repository::location_key, "The location_key, if not None, holds a file or directory containing " "our repository's data." ) .def("installed_root_key", &Repository::installed_root_key, "The installed_root_key, if not None, specifies that we contain installed " "packages at the specified root." ) .add_property("metadata", bp::range(&Repository::begin_metadata, &Repository::end_metadata), "[ro] Iterable of MetadataKey\n" "NEED_DOC" ) .def("find_metadata", &RepositoryWrapper::find_metadata, "find_metadata(string) -> MetadataKey\n" "NEED_DOC" ) ; /** * RepositoryEnvironmentVariableInterface */ bp::class_ ( "RepositoryEnvironmentVariableInterface", "Interface for environment variable querying for repositories.", bp::no_init ); /** * RepositoryDestinationInterface */ bp::class_ ( "RepositoryDestinationInterface", "Interface for repositories that can be used as an install destination.", bp::no_init ); /** * FakeRepository */ bp::implicitly_convertible, std::shared_ptr >(); bp::class_, bp::bases, boost::noncopyable> ( "FakeRepository", "Fake repository for use in test cases.", bp::no_init ) .def("__init__", bp::make_constructor(&make_fake_repository), "__init__(Environment, RepositoryName)" ) .def("add_category", &FakeRepository::add_category) .def("add_package", &FakeRepository::add_package) .def("add_version", &FakeRepositoryWrapper::add_version) ; enum_auto("RepositoryContentMayExclude", last_rcme, "Tells repository it may exclude certain content from queries if doing so will be faster."); class_options("RepositoryContentMayExcludes", "RepositoryContentMayExclude", "Options for various Repository methods."); }