aboutsummaryrefslogtreecommitdiff
path: root/python/dep_list.cc
blob: 858cfb38871f304537530c1b0eb882a9aeed98ef (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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
/* 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 <python/paludis_python.hh>
#include <python/exception.hh>

#include <paludis/dep_list/dep_list.hh>
#include <paludis/dep_list/exceptions.hh>
#include <libwrapiter/libwrapiter_forward_iterator.hh>


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

struct DepListWrapper
{
    static void
    add(DepList & self, tr1::shared_ptr<SetSpecTree::ConstItem> st,
            tr1::shared_ptr<const DestinationsSet> & d)
    {
        self.add(*st, d);
    }

    static bool
    already_installed(const DepList & self, tr1::shared_ptr<DependencySpecTree::ConstItem> st,
            tr1::shared_ptr<const DestinationsSet> & d)
    {
        return self.already_installed(*st, d);
    }
};

void expose_dep_list()
{
    /**
     * Exceptions
     */
    ExceptionRegister::get_instance()->add_exception<DepListError>
        ("DepListError", "BaseException",
         "Thrown if an error occurs whilst building a DepList.");
    ExceptionRegister::get_instance()->add_exception<AllMaskedError>
        ("AllMaskedError", "DepListError",
         "Thrown if all versions of a particular spec are masked.");
    ExceptionRegister::get_instance()->add_exception<UseRequirementsNotMetError>
        ("UseRequirementsNotMetError", "DepListError",
         "Thrown if all versions of a particular spec are masked, "
         "but would not be if use requirements were not in effect.");
    ExceptionRegister::get_instance()->add_exception<DowngradeNotAllowedError>
        ("DowngradeNotAllowedError", "DepListError",
         "Thrown if a downgrade is forced and we're not allowed to downgrade.");
    ExceptionRegister::get_instance()->add_exception<BlockError>
        ("BlockError", "DepListError",
         "Thrown if a block is encountered.");
    ExceptionRegister::get_instance()->add_exception<CircularDependencyError>
        ("CircularDependencyError", "DepListError",
         "Thrown if a circular dependency is encountered.");
    ExceptionRegister::get_instance()->add_exception<NoDestinationError>
        ("NoDestinationError", "DepListError",
         "Thrown if no destination can be found.");

    /**
     * Enums
     */
    enum_auto("DepListTargetType", last_dl_target,
            "Type of target being handled at the top level.");
    enum_auto("DepListReinstallOption", last_dl_reinstall,
            "When we should reinstall.");
    enum_auto("DepListFallBackOption", last_dl_fall_back,
            "When we should fall back to an installed package.");
    enum_auto("DepListReinstallScmOption", last_dl_reinstall_scm,
            "When we should reinstall SCM packages.");
    enum_auto("DepListUpgradeOption", last_dl_upgrade,
            "When we should upgrade.");
    enum_auto("DepListDowngradeOption", last_dl_downgrade,
            "What to do when we downgrade.");
    enum_auto("DepListNewSlotsOption", last_dl_new_slots,
            "When we should pull in a new slot.");
    enum_auto("DepListDepsOption", last_dl_deps,
            "How we should handle a dep class.");
    enum_auto("DepListSuggestedOption", last_dl_suggested,
            "How we should handle suggested deps.");
    enum_auto("DepListCircularOption", last_dl_circular,
            "How we should handle circular deps.");
    enum_auto("DepListBlocksOption", last_dl_blocks,
            "How we handle blocks.");
    enum_auto("DepListUseOption", last_dl_use_deps,
            "How we handle use deps.");
    enum_auto("DepListEntryState", last_dle,
            "State of a DepListEntry.");
    enum_auto("DepListEntryKind", last_dlk,
            "Kind of a DepListEntry.");

    /**
     * DepListOptions
     */
    register_shared_ptrs_to_python<DepListOptions>(rsp_non_const);
    bp::class_<DepListOptions, boost::noncopyable>
        (
         "DepListOptions",
         "Parameters for a DepList.",
         bp::init<>("__init__()")
        )
        .def_readwrite("reinstall", &DepListOptions::reinstall,
                "[rw] DepListReinstallOption"
                )

        .def_readwrite("reinstall_scm", &DepListOptions::reinstall_scm,
                "[rw] DepListReinstallScmOption"
                )

        .def_readwrite("target_type", &DepListOptions::target_type,
                "[rw] DepListTargetType"
                )

        .def_readwrite("upgrade", &DepListOptions::upgrade,
                "[rw] DepListUpgradeOption"
                )

        .def_readwrite("downgrade", &DepListOptions::downgrade,
                "[rw] DepListDowngradeOption"
                )

        .def_readwrite("new_slots", &DepListOptions::new_slots,
                "[rw] DepListNewSlotsOption"
                )

        .def_readwrite("fall_back", &DepListOptions::fall_back,
                "[rw] DepListFallBackOption"
                )

        .def_readwrite("installed_deps_pre", &DepListOptions::installed_deps_pre,
                "[rw] DepListDepsOption"
                )

        .def_readwrite("installed_deps_runtime", &DepListOptions::installed_deps_runtime,
                "[rw] DepListDepsOption"
                )

        .def_readwrite("installed_deps_post", &DepListOptions::installed_deps_post,
                "[rw] DepListDepsOption"
                )

        .def_readwrite("uninstalled_deps_pre", &DepListOptions::uninstalled_deps_pre,
                "[rw] DepListDepsOption"
                )

        .def_readwrite("uninstalled_deps_runtime", &DepListOptions::uninstalled_deps_runtime,
                "[rw] DepListDepsOption"
                )

        .def_readwrite("uninstalled_deps_post", &DepListOptions::uninstalled_deps_post,
                "[rw] DepListDepsOption"
                )

        .def_readwrite("uninstalled_deps_suggested", &DepListOptions::uninstalled_deps_suggested,
                "[rw] DepListDepsOption"
                )

        .def_readwrite("suggested", &DepListOptions::suggested,
                "[rw] DepListSuggestedOption"
                )

        .def_readwrite("circular", &DepListOptions::circular,
                "[rw] DepListCircularOption"
                )

        .def_readwrite("use", &DepListOptions::use,
                "[rw] DepListUseOption"
                )

        .def_readwrite("blocks", &DepListOptions::blocks,
                "[rw] DepListBlocksOption"
                )

        .def_readwrite("dependency_tags", &DepListOptions::dependency_tags,
                "[rw] bool"
                )
        ;

    /**
     * DepListEntry
     */
    bp::register_ptr_to_python<DepListEntry *>();
    bp::class_<DepListEntry, boost::noncopyable>
        (
         "DepListEntry",
         "An entry in a DepList.",
         bp::no_init
        )
        .def_readonly("kind", &DepListEntry::kind,
                "[ro] DepListEntryKind"
                )

        .add_property("package_id", bp::make_getter(&DepListEntry::package_id,
                    bp::return_value_policy<bp::return_by_value>()),
                "[ro] PackageID"
                )

        .add_property("associated_entry", bp::make_getter(&DepListEntry::associated_entry,
                    bp::return_value_policy<bp::reference_existing_object>()),
                "[ro] DepListEntry"
                )

        .add_property("tags", bp::make_getter(&DepListEntry::tags,
                    bp::return_value_policy<bp::return_by_value>()),
                "[ro] DepListEntryTags"
                )

        .add_property("destination", bp::make_getter(&DepListEntry::destination,
                    bp::return_value_policy<bp::return_by_value>()),
                "[ro] Repository"
                )

        .def_readonly("state", &DepListEntry::state,
                "[ro] DepListEntryState"
                )
        ;

    /**
     * DepList
     */
    tr1::shared_ptr<DepListOptions> (DepList::* options_ptr)() = &DepList::options;
    DepList::Iterator (DepList::*dl_begin_ptr)() = &DepList::begin;
    DepList::Iterator (DepList::*dl_end_ptr)() = &DepList::end;
    bp::class_<DepList, boost::noncopyable>
        (
         "DepList",
         "Holds a list of dependencies in merge order.",
         bp::init<const Environment * const, const DepListOptions &>("__init__(Environment, DepListOptions)")
        )
        .add_property("options", options_ptr,
                "[ro] DepListOptions\n"
                "Our options."
                )

        .def("add", &DepListWrapper::add,
                "add(DepSpec, DestinationsIterable)\n"
                "Add the packages required to resolve an additional dependency spec."
            )

        .def("clear", &DepList::clear,
                "clear()\n"
                "Clear the list."
            )

        .def("already_installed", &DepListWrapper::already_installed,
                "already_installed(DepSpec, DestinationsIterable) -> bool\n"
                "Return whether a spec structure is already installed."
            )

        .def("match_on_list", &DepList::match_on_list,
                "match_on_list(PackageDepSpec) -> bool\n"
                "Return whether a spec matches an item in the list."
            )

        .def("__iter__", bp::range<bp::return_internal_reference<> >(dl_begin_ptr, dl_end_ptr))
        ;
}