aboutsummaryrefslogtreecommitdiff
path: root/python/dep_tag.cc
blob: b0491c4763e14f5d1180a845db4e12f878c8d4b3 (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
/* 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
 */

#include <paludis_python.hh>

#include <paludis/dep_tag.hh>
#include <paludis/dep_spec.hh>
#include <paludis/util/set.hh>
#include <libwrapiter/libwrapiter_forward_iterator.hh>

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

struct DepTagCategoryMakerWrapper
{
    // More convenient way of creating DepTagCategories
    static tr1::shared_ptr<const DepTagCategory>
    make_from_id(const DepTagCategoryMaker & self, const std::string & id)
    {
        return self[id]();
    }
};

void PALUDIS_VISIBLE expose_dep_tag()
{
    /**
     * Exceptions
     */
    ExceptionRegister::get_instance()->add_exception<NoSuchDepTagCategory>
        ("NoSuchDepTagCategory", "BaseException",
         "Thrown if DepTagCategoryMaker cannot find the named DepTagCategory.");

    /**
     * DepTagCategory
     */
    register_shared_ptrs_to_python<DepTagCategory>();
    bp::class_<DepTagCategory, boost::noncopyable>
        (
         "DepTagCategory",
         "A DepTagCategory is identified by its name and has associated display "
         "information for a DepTag's category.",
         bp::no_init
        )
        .add_property("visible", &DepTagCategory::visible,
                "[ro] bool\n"
                "Should we be displayed in a tag category summary?"
                )

        .add_property("id", &DepTagCategory::id,
                "[ro] string\n"
                "Fetch our short ID (for example, 'GLSA')."
                )

        .add_property("title", &DepTagCategory::title,
                "[ro] string\n"
                "Fetch our title (for example, 'Security advisories'), or an "
                "empty string if we're untitled."
                )

        .add_property("pre_text", &DepTagCategory::pre_text,
                "[ro] string\n"
                "Fetch our pre list text, or an empty string."
                )

        .add_property("post_text", &DepTagCategory::post_text,
                "[ro] string\n"
                "Fetch our post list text, or an empty string."
                )
        ;

    /**
     * DepTagCategoryMaker
     */
    bp::class_<DepTagCategoryMaker, boost::noncopyable>
        (
         "DepTagCategoryMaker",
         "Virtual constructor for accessing DepTagCategory instances.",
         bp::no_init
        )
        .add_static_property("instance", bp::make_function(&DepTagCategoryMaker::get_instance,
                    bp::return_value_policy<bp::reference_existing_object>()),
                "Singleton instance."
                )

        .def("make_from_id", &DepTagCategoryMakerWrapper::make_from_id,
                "make_from_id(id_string) -> DepTagCategory\n"
                "Make DepTagCategory from id."
            )
        ;

    /**
     * DepTag
     */
    bp::class_<DepTag, boost::noncopyable>
        (
         "DepTag",
         "A DepTag can be associated with a PackageDepSpec, and is transferred "
         "onto any associated DepListEntry instances.",
         bp::no_init
        )
        .add_property("short_text", &DepTag::short_text,
                "[ro] string\n"
                "Our short text (for example, 'GLSA-1234') that is "
                "displayed with the dep list entry."
                )

        .add_property("category", &DepTag::category,
                "[ro] string\n"
                "Our DepTagCategory's tag."
                )

        .def("__cmp__", &py_cmp<DepTag>)
        ;

    /**
     * GLSADepTag
     */
    bp::class_<GLSADepTag, bp::bases<DepTag>, boost::noncopyable>
        (
         "GLSADepTag",
         "DepTag subclass for GLSAs.",
         bp::init<const std::string &, const std::string &>("__init__(id_str, glsa_title_str)")
        )
        .add_property("glsa_title", &GLSADepTag::glsa_title,
                "Our GLSA title (for example, 'Yet another PHP remote access hole')"
                )
        ;

    /**
     * GeneralSetDepTag
     */
    bp::class_<GeneralSetDepTag, bp::bases<DepTag>, boost::noncopyable>
        (
         "GeneralSetDepTag",
         "DepTag subclass for general sets.",
         bp::init<const SetName &, const std::string &>("__init__(SetName, source_str)")
        )
        .add_property("source", &GeneralSetDepTag::source,
                "From which repository or environment did we originate?"
                )
        ;

    /**
     * DependencyDepTag
     */
    bp::class_<DependencyDepTag, bp::bases<DepTag>, boost::noncopyable>
        (
         "DependencyDepTag",
         "DepTag subclass for dependencies.",
         bp::init<const tr1::shared_ptr<const PackageID> &, const PackageDepSpec &,
                const tr1::shared_ptr<const DependencySpecTree::ConstItem> >(
                    "__init__(PackageID, PackageDepSpec, CompositeDepSpec)"
                    )
        )
        .add_property("package_id", &DependencyDepTag::package_id,
                "[ro] PackageID\n"
                "The PackageID that contains our dependency."
                )

        .add_property("dependency", bp::make_function(&DependencyDepTag::dependency,
                    bp::return_value_policy<bp::return_by_value>()),
                "[ro] PackageDepSpec\n"
                "The PackageDepSpec that pulled us in."
                )

        .add_property("conditions", &DependencyDepTag::conditions,
                "[ro] CompositeDepSpec\n"
                "The AllDepSpecs and UseDepSpecs that our dependency is conditional upon."
                )
        ;

    /**
     * TargetDepTag
     */
    bp::class_<TargetDepTag, bp::bases<DepTag>, boost::noncopyable>
        (
         "TargetDepTag",
         "DepTag subclass for explicit targets.",
         bp::init<>("__init__()")
        )
        ;

    /**
     * DepListEntryTags
     */
    class_iterable<DepListEntryTags>
        (
         "DepListEntryTags",
         "Tags attached to a DepListEntry."
        );
}