aboutsummaryrefslogtreecommitdiff
path: root/python/repository.cc
blob: f479a8421f84f681453f7a99467eb95049837403 (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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
/* 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/repository.hh>
#include <paludis/repositories/e/e_repository.hh>
#include <paludis/repositories/fake/fake_repository.hh>
#include <paludis/repositories/fake/fake_package_id.hh>
#include <paludis/action.hh>
#include <paludis/package_id.hh>
#include <paludis/environment.hh>
#include <paludis/qa.hh>
#include <paludis/util/options.hh>
#include <paludis/util/wrapped_forward_iterator.hh>

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

struct RepositoryWrapper :
    Repository,
    bp::wrapper<Repository>
{
    static RepositorySetsInterface *
    get_sets_interface(const Repository & self)
    {
        return self.sets_interface;
    }

    static RepositorySyncableInterface *
    get_syncable_interface(const Repository & self)
    {
        return self.syncable_interface;
    }

    static RepositoryUseInterface *
    get_use_interface(const Repository & self)
    {
        return self.use_interface;
    }

    static RepositoryWorldInterface *
    get_world_interface(const Repository & self)
    {
        return self.world_interface;
    }

    static RepositoryMirrorsInterface *
    get_mirrors_interface(const Repository & self)
    {
        return self.mirrors_interface;
    }

    static RepositoryEnvironmentVariableInterface *
    get_environment_variable_interface(const Repository & self)
    {
        return self.environment_variable_interface;
    }

    static RepositoryProvidesInterface *
    get_provides_interface(const Repository & self)
    {
        return self.provides_interface;
    }

    static RepositoryVirtualsInterface *
    get_virtuals_interface(const Repository & self)
    {
        return self.virtuals_interface;
    }

    static RepositoryDestinationInterface *
    get_destination_interface(const Repository & self)
    {
        return self.destination_interface;
    }

    static RepositoryEInterface *
    get_e_interface(const Repository & self)
    {
        return self.e_interface;
    }

    static RepositoryQAInterface *
    get_qa_interface(const Repository & self)
    {
        return self.qa_interface;
    }
};

struct FakeRepositoryWrapper
{
    static tr1::shared_ptr<PackageID>
    add_version(FakeRepository & self, const QualifiedPackageName & qpn, const VersionSpec & vs)
    {
        return self.add_version(qpn, vs);
    }
};

struct RepositoryEInterfaceWrapper
{
    static bp::object
    my_find_profile(const RepositoryEInterface & self, const FSEntry & location)
    {
        RepositoryEInterface::ProfilesConstIterator p(self.find_profile(location));
        if (p == self.end_profiles())
            return bp::object();
        return bp::object(bp::ptr(&*p));
    }

    static void
    my_set_profile(RepositoryEInterface & self, const RepositoryEInterface::ProfilesDescLine & pdl)
    {
        self.set_profile(self.find_profile(pdl.path));
    }
};

// FIXME
//template <typename I_>
//struct repository_interface_to_python
//{
//    static PyObject *
//    convert(const I_ & i)
//    {
//        return 0;
//        return bp::incref(bp::object(bp::ptr(&i)).ptr());
//    }
//};
//
//template <typename I_>
//void register_repository_interface_to_python()
//{
//    bp::to_python_converter<I_, repository_interface_to_python<I_> >();
//}

void expose_repository()
{
    /**
     * DestinationIterable
     */
    class_iterable<DestinationsSet>
        (
         "DestinationsIterable",
         "Iterable of Repository.",
         true
        );

    /**
     * Repository
     */
    register_shared_ptrs_to_python<Repository>(rsp_const);
    bp::class_<RepositoryWrapper, tr1::shared_ptr<Repository>, boost::noncopyable>
        (
         "Repository",
         "A Repository provides a representation of a physical repository to a PackageDatabase.",
         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) -> bool\n"
                "Do we have a category with the given name?"
            )

        .def("has_package_named", &Repository::has_package_named,
                "has_package_named(QualifiedPackageName) -> bool\n"
                "Do we have a package in the given category with the given name?"
            )

        .add_property("category_names", &Repository::category_names,
                "[ro] CategoryNamePartIterable\n"
                "Our category names."
                )

        .def("category_names_containing_package", &Repository::category_names_containing_package,
                "category_names_containing_package(PackageNamePart) -> CategoryNamePartIterable\n"
                "Fetch categories that contain a named package."
            )

        .def("package_names", &Repository::package_names,
                "package_names(CategoryNamePart) -> QualifiedPackageNameIterable\n"
                "Fetch our package names."
            )

        .def("package_ids", &Repository::package_ids, bp::with_custodian_and_ward_postcall<0, 1>(),
                "package_ids(QualifiedPackageName) -> 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 PackageDatabase::query. If a repository doesn't\n"
                "support, say, InstallAction, a query can skip searching it\n"
                "entirely when looking for installable packages."
            )

        .add_property("use_interface", bp::make_function(&RepositoryWrapper::get_use_interface,
                    bp::return_internal_reference<>()),
                "[ro] RepositoryUseInterface"
                )

        .add_property("sets_interface", bp::make_function(&RepositoryWrapper::get_sets_interface,
                    bp::return_internal_reference<>()),
                "[ro] RepositorySetsInterface"
                )

        .add_property("syncable_interface", bp::make_function(&RepositoryWrapper::get_syncable_interface,
                    bp::return_internal_reference<>()),
                "[ro] RepositorySyncableInterface"
                )

        .add_property("world_interface", bp::make_function(&RepositoryWrapper::get_world_interface,
                    bp::return_internal_reference<>()),
                "[ro] RepositoryWorldInterface"
                )

        .add_property("environment_variable_interface",
                bp::make_function(&RepositoryWrapper::get_environment_variable_interface,
                    bp::return_internal_reference<>()),
                "[ro] RepositoryEnvironmentInterface"
                )

        .add_property("mirrors_interface", bp::make_function(&RepositoryWrapper::get_mirrors_interface,
                    bp::return_internal_reference<>()),
                "[ro] RepositoryMirrorsInterface"
                )

        .add_property("virtuals_interface", bp::make_function(&RepositoryWrapper::get_virtuals_interface,
                    bp::return_internal_reference<>()),
                "[ro] RepositoryVirtualsInterface"
                )

        .add_property("provides_interface", bp::make_function(&RepositoryWrapper::get_provides_interface,
                    bp::return_internal_reference<>()),
                "[ro] RepositoryProvidesInterface"
                )

        .add_property("destination_interface", bp::make_function(&RepositoryWrapper::get_destination_interface,
                    bp::return_internal_reference<>()),
                "[ro] RepositoryDestinationInterface"
                )

        .add_property("e_interface", bp::make_function(&RepositoryWrapper::get_e_interface,
                    bp::return_internal_reference<>()),
                "[ro] RepositoryEInterface"
                )

        .add_property("qa_interface", bp::make_function(&RepositoryWrapper::get_qa_interface,
                    bp::return_internal_reference<>()),
                "[ro] RepositoryQAInterface"
                )
        ;

    /**
     * RepositoryEInterfaceProfilesDescLine
     */
    bp::class_<RepositoryEInterfaceProfilesDescLine>
        (
         "RepositoryEInterfaceProfilesDescLine",
         "A profiles.desc line in a Repository implementing RepositoryEInterface.",
         bp::no_init
        )
        .add_property("path", bp::make_getter(&RepositoryEInterfaceProfilesDescLine::path,
                    bp::return_value_policy<bp::return_by_value>())
                )

        .def_readonly("arch", &RepositoryEInterfaceProfilesDescLine::arch)

        .def_readonly("status", &RepositoryEInterfaceProfilesDescLine::status)
        ;

    /**
     * RepositoryUseInterface
     */
    bp::class_<RepositoryUseInterface, boost::noncopyable>
        (
         "RepositoryUseInterface",
         "Interface for handling USE flags for the Repository class.",
         bp::no_init
        )
        .def("query_use", &RepositoryUseInterface::query_use,
                ("ufn", bp::arg("pid")),
                "query_use(UseFlagName, PackageID) -> UseFlagState\n"
                "Query the state of the specified use flag."
            )

        .def("query_use_mask", &RepositoryUseInterface::query_use_mask,
                ("ufn", bp::arg("pid")),
                "query_use_mask(UseFlagName, PackageID) -> bool\n"
                "Query whether the specified use flag is masked."
            )

        .def("query_use_force", &RepositoryUseInterface::query_use_force,
                ("ufn", bp::arg("pid")),
                "query_use_force(UseFlagName, PackageID) -> bool\n"
                "Query whether the specified use flag is forceed."
            )

        .def("describe_use_flag", &RepositoryUseInterface::describe_use_flag,
                ("ufn", bp::arg("pid")),
                "describe_use_flag(UseFlagName, PackageID) -> string\n"
                "Describe a use flag."
            )
        ;

    /**
     * RepositorySetsInterface
     */
    bp::class_<RepositorySetsInterface, boost::noncopyable>
        (
         "RepositorySetsInterface",
         "Interface for package sets for repositories.",
         bp::no_init
        );

    /**
     * RepositorySyncableInterface
     */
    bp::class_<RepositorySyncableInterface, boost::noncopyable>
        (
         "RepositorySyncableInterface",
         "Interface for syncing for repositories.",
         bp::no_init
        );

    /**
     * RepositoryWorldInterface
     */
    bp::class_<RepositoryWorldInterface, boost::noncopyable>
        (
         "RepositoryWorldInterface",
         "Interface for world handling for repositories.",
         bp::no_init
        );

    /**
     * RepositoryEnvironmentVariableInterface
     */
    bp::class_<RepositoryEnvironmentVariableInterface, boost::noncopyable>
        (
         "RepositoryEnvironmentVariableInterface",
         "Interface for environment variable querying for repositories.",
         bp::no_init
        );

    /**
     * RepositoryMirrorsInterface
     */
    bp::class_<RepositoryMirrorsInterface, boost::noncopyable>
        (
         "RepositoryMirrorsInterface",
         "Interface for mirror querying for repositories.",
         bp::no_init
        );

    /**
     * RepositoryVirtualsInterface
     */
    bp::class_<RepositoryVirtualsInterface, boost::noncopyable>
        (
         "RepositoryVirtualsInterface",
         "Interface for repositories that define virtuals.",
         bp::no_init
        );

    /**
     * RepositoryProvidesInterface
     */
    bp::class_<RepositoryProvidesInterface, boost::noncopyable>
        (
         "RepositoryProvidesInterface",
         "Interface for repositories that provide packages.",
         bp::no_init
        );

    /**
     * RepositoryDestinationInterface
     */
    bp::class_<RepositoryDestinationInterface, boost::noncopyable>
        (
         "RepositoryDestinationInterface",
         "Interface for repositories that can be used as an install destination.",
         bp::no_init
        );

    /**
     * RepositoryEInterface
     */
    bp::class_<RepositoryEInterface, boost::noncopyable>
        (
         "RepositoryEInterface",
         "Interface for handling ERepository specific functionality.",
         bp::no_init
        )
        .add_property("profiles", bp::range(&RepositoryEInterface::begin_profiles,
                    &RepositoryEInterface::end_profiles),
                "[ro] Iterable of Profiles"
                )

        .def("profile_variable", &RepositoryEInterface::profile_variable)

        .def("find_profile", &RepositoryEInterfaceWrapper::my_find_profile,
                "find_profile(path_string) -> RepositoryEInterfaceProfilesDescLine"
            )

        .add_property("profile", bp::object(), &RepositoryEInterfaceWrapper::my_set_profile,
                "[wo] RepositoryEInterfaceProfilesDescLine"
                )
        ;

    /**
     * RepositoryQAInterface
     */
    bp::class_<RepositoryQAInterface, boost::noncopyable>
        (
         "RepositoryQAInterface",
         "Interface for handling QA tasks.",
         bp::no_init
        )
        .def("check_qa", &RepositoryQAInterface::check_qa,
                "check_qa(QAReporter, QACheckProperties, QACheckProperties, QAMessageLevel, path)\n"
                "NEED_DOC"
            )
        ;

    /**
     * FakeRepository
     */
    bp::implicitly_convertible<tr1::shared_ptr<FakeRepository>, tr1::shared_ptr<Repository> >();

    bp::class_<FakeRepository, tr1::shared_ptr<FakeRepository>, bp::bases<Repository>, boost::noncopyable>
        (
         "FakeRepository",
         "Fake repository for use in test cases.",
         bp::init<const Environment * const, const RepositoryName &>("__init__(Environment, RepositoryName)")
        )
        .def("add_category", &FakeRepository::add_category)

        .def("add_package", &FakeRepository::add_package)

        .def("add_version", &FakeRepositoryWrapper::add_version)
        ;
}