/* 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 using namespace paludis; using namespace paludis::python; namespace bp = boost::python; // For classes derived from ContentsEntry template class class_contents: public bp::class_, bp::bases, boost::noncopyable> { public: template class_contents(const std::string & name, const std::string & class_doc, Init_ initspec) : bp::class_, bp::bases, boost::noncopyable>( name.c_str(), class_doc.c_str(), initspec) { bp::register_ptr_to_python >(); bp::implicitly_convertible, std::shared_ptr >(); } }; void expose_contents() { /** * ContentsEntry */ bp::register_ptr_to_python >(); bp::implicitly_convertible, std::shared_ptr >(); bp::class_ ( "ContentsEntry", "Base class for a contents entry.", bp::no_init ) .add_property("metadata", bp::range(&ContentsEntry::begin_metadata, &ContentsEntry::end_metadata), "[ro] Iterable of MetadataKey\n" "NEED_DOC" ) .def("find_metadata", &ContentsEntry::find_metadata, "find_metadata(string) -> MetadataKey\n" "NEED_DOC" ) .def("location_key", &ContentsEntry::location_key, "The location_key, which will not be None, provides the path on the filesystem\n" "of the entry. It is not modified for root." ) ; /** * ContentsFileEntry */ class_contents ( "ContentsFileEntry", "A file contents entry.", bp::init("__init__(location, part)") ) .def("part_key", &ContentsFileEntry::part_key) ; /** * ContentsDirEntry */ class_contents ( "ContentsDirEntry", "A directory contents entry.", bp::init("__init__(location)") ); /** * ContentsOtherEntry */ class_contents ( "ContentsOtherEntry", "An 'other' contents entry.", bp::init("__init__(location)") ); /** * ContentsSymEntry */ class_contents ( "ContentsSymEntry", "A sym contents entry.", bp::init("__init__(location, target_string, part)") ) .def("target_key", &ContentsSymEntry::target_key, "The target_key, which will not be None, holds the symlink's target (as per readlink)." ) .def("part_key", &ContentsSymEntry::part_key) ; /** * Contents */ register_shared_ptrs_to_python(rsp_const); bp::class_, boost::noncopyable> ( "Contents", "Iterable of ContentsEntry.\n" "A package's contents.", bp::init<>("__init__()") ) .def("add", &Contents::add, "add(ContentsEntry)\n" "Add a new entry." ) .def("__iter__", bp::range(&Contents::begin, &Contents::end)) ; }