aboutsummaryrefslogtreecommitdiff
path: root/python/package_id.cc
blob: 4325d14b04c77a58c5c548b6b468d5e384922758 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/* 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/package_id.hh>
#include <paludis/repositories/fake/fake_package_id.hh>
#include <paludis/metadata_key.hh>
#include <paludis/name.hh>
#include <paludis/version_spec.hh>
#include <paludis/action.hh>
#include <paludis/util/wrapped_forward_iterator.hh>

using namespace paludis;
using namespace paludis::python;
namespace bp = boost::python;

struct PackageIDWrapper
{
    static PyObject *
    find_metadata(const PackageID & self, const std::string & key)
    {
        PackageID::MetadataConstIterator i(self.find_metadata(key));
        if (i != self.end_metadata())
            return bp::incref(bp::object(*i).ptr());
        else
            return Py_None;
    }
};

void expose_package_id()
{
    /**
     * Enums
     */
    enum_auto("PackageIDCanonicalForm", last_idcf,
            "How to generate paludis::PackageID::canonical_form().");

    /**
     * PackageID
     */
    register_shared_ptrs_to_python<PackageID>();
    bp::class_<PackageID, boost::noncopyable>
        (
         "PackageID",
         bp::no_init
        )
        .def("canonical_form", &PackageID::canonical_form,
                "canonical_form(PackageIDCanonicalForm) -> string\n"
                )

        .add_property("name", &PackageID::name,
                "[ro] QualifiedPackageName\n"
                )

        .add_property("version", &PackageID::version,
                "[ro] VersionSpec\n"
                )

        .add_property("repository_name", &PackageID::repository_name,
                "[ro] RepositoryName\n"
                )

        .def("supports_action", &PackageID::supports_action,
                "supports_action(SupportsActionTestBase) -> bool\n"
                "NEED_DOC"
            )

        .def("perform_action", &PackageID::perform_action,
                "perform_action(Action)\n"
                "NEED_DOC"
            )

        .add_property("metadata", bp::range(&PackageID::begin_metadata, &PackageID::end_metadata),
                "[ro] Iterable of MetadataKey\n"
                "NEED_DOC"
                )

        .def("find_metadata", &PackageIDWrapper::find_metadata,
                "find_metadata(string) -> MetadataKey\n"
                "NEED_DOC"
            )

        .add_property("masked", &PackageID::masked,
                "[ro] bool\n"
                "NEED_DOC"
                )

        .add_property("masks", bp::range(&PackageID::begin_masks, &PackageID::end_masks),
                "[ro] Iterable of Mask\n"
                "NEED_DOC"
                )

        .def("keywords_key", &PackageID::keywords_key,
                "The keywords_key, if not None, is used by FindUnusedPackagesTask\n"
                "to determine whether a package is unused."
            )

        .def("contains_key", &PackageID::contains_key,
                "The contains_key, if not None, indicates that a package contains\n"
                "other packages. This affects dependency resolution."
            )

        .def("contained_in_key", &PackageID::contained_in_key,
                "The contained_in_key, if not None, indicates that a package is\n"
                "contained in another package. This affects dependency resolution."
            )

        .def("build_dependencies_key", &PackageID::build_dependencies_key,
                "The build_dependencies_key, if not None, indicates a package's\n"
                "build-time dependencies."
            )

        .def("run_dependencies_key", &PackageID::run_dependencies_key,
                "The run_dependencies_key, if not None, indicates a package's\n"
                "run-time dependencies."
            )

        .def("post_dependencies_key", &PackageID::post_dependencies_key,
                "The post_dependencies_key, if not None, indicates a package's\n"
                "post-merge dependencies."
            )

        .def("fetches_key", &PackageID::fetches_key,
                "The fetches_key, if not None, indicates files that have to be fetched\n"
                "in order to install a package."
            )

        .def("homepage_key", &PackageID::homepage_key,
                "The homepage_key, if not None, describes a package's homepages."
            )

        .def("short_description_key", &PackageID::short_description_key,
                "The short_description_key, if not None, provides a short (no more\n"
                "than a few hundred characters) description of a package."
            )

        .def("long_description_key", &PackageID::long_description_key,
                "The long_description_key, if not None, provides a long\n"
                "description of a package."
            )

        .def("contents_key", &PackageID::contents_key,
                "The contents_key, if not None, contains the contents of a\n"
                "package. For installed packages, this means the files installed;\n"
                "for installable packages, this means the files that will be\n"
                "installed (if known, which it may be for some binary packages)."
            )


        .def("installed_time_key", &PackageID::installed_time_key,
                "The installed_time_key, if not None, contains the time a package\n"
                "was installed. It affects dependency resolution if DepList is\n"
                "using dl_reinstall_scm_daily or dl_reinstall_scm_weekly."
            )

        .def("from_repositories_key", &PackageID::from_repositories_key,
                "The from_repositories_key, if not None, contains strings describing\n"
                "the repositories whence a package originated."
            )

        .def("fs_location_key", &PackageID::fs_location_key,
                "The fs_location_key, if not None, indicates the filesystem\n"
                "location (for example, the ebuild file or VDB directory) that\n"
                "best describes the location of a PackageID."
            )

        .def("slot_key", &PackageID::slot_key,
                "The slot_key, if not None, indicates the package's slot."
            )

        .def("choices_key", &PackageID::choices_key,
                "The choices_key, if not None, indicates the package's choices."
            )

        .def("__eq__", &py_eq<PackageID>)

        .def("__ne__", &py_ne<PackageID>)

        .def(bp::self_ns::str(bp::self))
        ;

    /**
     * PackageIDIterable
     */
    class_iterable<PackageIDSequence>
        (
         "PackageIDIterable",
         "Iterable of PackageID",
         true
        );
}