aboutsummaryrefslogtreecommitdiff
path: root/python/environment.cc
blob: 369144310fb6336b87de6cc6960b230a3a7e983d (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
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
/* 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/exception.hh>
#include <python/iterable.hh>

#include <paludis/environments/paludis/paludis_environment.hh>
#include <paludis/environments/paludis/paludis_config.hh>

#include <paludis/environments/test/test_environment.hh>

#include <paludis/hook.hh>
#include <paludis/package_id.hh>
#include <paludis/selection.hh>
#include <paludis/spec_tree.hh>
#include <paludis/filter.hh>
#include <paludis/standard_output_manager.hh>
#include <paludis/environment.hh>
#include <paludis/environment_factory.hh>

#include <paludis/util/wrapped_forward_iterator.hh>
#include <paludis/util/tribool.hh>
#include <paludis/util/make_named_values.hh>

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

class EnvironmentImplementationWrapper :
    public EnvironmentImplementation,
    public bp::wrapper<EnvironmentImplementation>
{
    public:
        EnvironmentImplementationWrapper()
        {
        }

        virtual void populate_sets() const
        {
            std::unique_lock<std::recursive_mutex> l(get_mutex());

            if (bp::override f = get_override("populate_sets"))
                f();
            else
                throw PythonMethodNotImplemented("EnvironmentImplementation", "populate_sets");
        }

        virtual bool accept_license(const std::string & s, const std::shared_ptr<const PackageID> & p) const
            PALUDIS_ATTRIBUTE((warn_unused_result))
        {
            std::unique_lock<std::recursive_mutex> l(get_mutex());

            if (bp::override f = get_override("accept_license"))
                return f(s, p);
            else
                throw PythonMethodNotImplemented("EnvironmentImplementation", "accept_license");
        }

        virtual bool accept_keywords(const std::shared_ptr<const KeywordNameSet> & k, const std::shared_ptr<const PackageID> & p) const
            PALUDIS_ATTRIBUTE((warn_unused_result))
        {
            std::unique_lock<std::recursive_mutex> l(get_mutex());

            if (bp::override f = get_override("accept_keywords"))
                return f(k, p);
            else
                throw PythonMethodNotImplemented("EnvironmentImplementation", "accept_keywords");
        }

        virtual const std::shared_ptr<const Mask> mask_for_breakage(const std::shared_ptr<const PackageID> & p) const
            PALUDIS_ATTRIBUTE((warn_unused_result))
        {
            std::unique_lock<std::recursive_mutex> l(get_mutex());

            if (bp::override f = get_override("mask_for_breakage"))
                return f(p);
            else
                throw PythonMethodNotImplemented("EnvironmentImplementation", "mask_for_breakage");
        }

        virtual const std::shared_ptr<const Mask> mask_for_user(const std::shared_ptr<const PackageID> & p, const bool b) const
            PALUDIS_ATTRIBUTE((warn_unused_result))
        {
            std::unique_lock<std::recursive_mutex> l(get_mutex());

            if (bp::override f = get_override("mask_for_user"))
                return f(p, b);
            else
                throw PythonMethodNotImplemented("EnvironmentImplementation", "mask_for_user");
        }

        virtual bool unmasked_by_user(const std::shared_ptr<const PackageID> & p, const std::string & s) const
            PALUDIS_ATTRIBUTE((warn_unused_result))
        {
            std::unique_lock<std::recursive_mutex> l(get_mutex());

            if (bp::override f = get_override("unmasked_by_user"))
                return f(p, s);
            else
                throw PythonMethodNotImplemented("EnvironmentImplementation", "unmasked_by_user");
        }

        virtual std::shared_ptr<const FSPathSequence> bashrc_files() const
            PALUDIS_ATTRIBUTE((warn_unused_result))
        {
            std::unique_lock<std::recursive_mutex> l(get_mutex());

            if (bp::override f = get_override("bashrc_files"))
                return f();
            return EnvironmentImplementation::bashrc_files();
        }

        std::shared_ptr<const FSPathSequence> default_bashrc_files() const
            PALUDIS_ATTRIBUTE((warn_unused_result))
        {
            return EnvironmentImplementation::bashrc_files();
        }

        virtual std::shared_ptr<const FSPathSequence> syncers_dirs() const
            PALUDIS_ATTRIBUTE((warn_unused_result))
        {
            std::unique_lock<std::recursive_mutex> l(get_mutex());

            if (bp::override f = get_override("syncers_dirs"))
                return f();
            return EnvironmentImplementation::syncers_dirs();
        }

        std::shared_ptr<const FSPathSequence> default_syncers_dirs() const
            PALUDIS_ATTRIBUTE((warn_unused_result))
        {
            return EnvironmentImplementation::syncers_dirs();
        }

        virtual std::shared_ptr<const FSPathSequence> fetchers_dirs() const
            PALUDIS_ATTRIBUTE((warn_unused_result))
        {
            std::unique_lock<std::recursive_mutex> l(get_mutex());

            if (bp::override f = get_override("fetchers_dirs"))
                return f();
            return EnvironmentImplementation::fetchers_dirs();
        }

        std::shared_ptr<const FSPathSequence> default_fetchers_dirs() const
            PALUDIS_ATTRIBUTE((warn_unused_result))
        {
            return EnvironmentImplementation::fetchers_dirs();
        }

        virtual std::shared_ptr<const FSPathSequence> hook_dirs() const
            PALUDIS_ATTRIBUTE((warn_unused_result))
        {
            std::unique_lock<std::recursive_mutex> l(get_mutex());

            if (bp::override f = get_override("hook_dirs"))
                return f();
            else
                throw PythonMethodNotImplemented("EnvironmentImplementation", "hook_dirs");
        }

        virtual uid_t reduced_uid() const
        {
            std::unique_lock<std::recursive_mutex> l(get_mutex());

            if (bp::override f = get_override("reduced_uid"))
                return f();
            else
                throw PythonMethodNotImplemented("EnvironmentImplementation", "reduced_uid");
        }

        virtual gid_t reduced_gid() const
        {
            std::unique_lock<std::recursive_mutex> l(get_mutex());

            if (bp::override f = get_override("reduced_gid"))
                return f();
            else
                throw PythonMethodNotImplemented("EnvironmentImplementation", "reduced_gid");
        }


        virtual std::shared_ptr<const MirrorsSequence> mirrors(const std::string & s) const
            PALUDIS_ATTRIBUTE((warn_unused_result))
        {
            std::unique_lock<std::recursive_mutex> l(get_mutex());

            if (bp::override f = get_override("mirrors"))
                return f(s);
            else
                throw PythonMethodNotImplemented("EnvironmentImplementation", "mirrors");
        }

        virtual std::shared_ptr<const SetNameSet> set_names() const
            PALUDIS_ATTRIBUTE((warn_unused_result))
        {
            std::unique_lock<std::recursive_mutex> l(get_mutex());

            if (bp::override f = get_override("set_names"))
                return f();
            return EnvironmentImplementation::set_names();
        }

        std::shared_ptr<const SetNameSet> default_set_names() const
            PALUDIS_ATTRIBUTE((warn_unused_result))
        {
            return EnvironmentImplementation::set_names();
        }

        virtual const std::shared_ptr<const SetSpecTree> set(const SetName & s) const
            PALUDIS_ATTRIBUTE((warn_unused_result))
        {
            std::unique_lock<std::recursive_mutex> l(get_mutex());

            if (bp::override f = get_override("set"))
                return f(boost::cref(s));
            return EnvironmentImplementation::set(s);
        }

        const std::shared_ptr<const SetSpecTree> default_set(const SetName & s) const
            PALUDIS_ATTRIBUTE((warn_unused_result))
        {
            return EnvironmentImplementation::set(s);
        }

        // FIXME - Hooks are not exposed
        virtual HookResult perform_hook(const Hook & h, const std::shared_ptr<OutputManager> &) const
            PALUDIS_ATTRIBUTE((warn_unused_result))
        {
            return make_named_values<HookResult>(n::max_exit_status() = 0, n::output() = "");
        }

        virtual std::string distribution() const
            PALUDIS_ATTRIBUTE((warn_unused_result))
        {
            std::unique_lock<std::recursive_mutex> l(get_mutex());

            if (bp::override f = get_override("distribution"))
                return f();
            return EnvironmentImplementation::distribution();
        }

        std::string default_distribution() const
            PALUDIS_ATTRIBUTE((warn_unused_result))
        {
            return EnvironmentImplementation::distribution();
        }

        virtual bool add_to_world(const QualifiedPackageName & s) const
        {
            std::unique_lock<std::recursive_mutex> l(get_mutex());
            if (bp::override f = get_override("add_to_world"))
                return f(s);
            else
                throw PythonMethodNotImplemented("EnvironmentImplementation", "add_to_world");
        }

        virtual bool add_to_world(const SetName & s) const
        {
            std::unique_lock<std::recursive_mutex> l(get_mutex());
            if (bp::override f = get_override("add_to_world"))
                return f(s);
            else
                throw PythonMethodNotImplemented("EnvironmentImplementation", "add_to_world");
        }

        virtual bool remove_from_world(const QualifiedPackageName & s) const
        {
            std::unique_lock<std::recursive_mutex> l(get_mutex());
            if (bp::override f = get_override("remove_from_world"))
                return f(s);
            else
                throw PythonMethodNotImplemented("EnvironmentImplementation", "remove_from_world");
        }

        virtual bool remove_from_world(const SetName & s) const
        {
            std::unique_lock<std::recursive_mutex> l(get_mutex());
            if (bp::override f = get_override("remove_from_world"))
                return f(s);
            else
                throw PythonMethodNotImplemented("EnvironmentImplementation", "remove_from_world");
        }

        virtual std::shared_ptr<PackageIDSequence> operator[] (const Selection & fg) const
            PALUDIS_ATTRIBUTE((warn_unused_result))
        {
            std::unique_lock<std::recursive_mutex> l(get_mutex());

            if (bp::override f = get_override("__getitem__"))
                return f(fg);
            return EnvironmentImplementation::operator[] (fg);
        }

        virtual std::shared_ptr<PackageIDSequence> default_operator_square_brackets(const Selection & fg) const
            PALUDIS_ATTRIBUTE((warn_unused_result))
        {
            return EnvironmentImplementation::operator[] (fg);
        }

        virtual void need_keys_added() const
        {
            std::unique_lock<std::recursive_mutex> l(get_mutex());

            if (bp::override f = get_override("need_keys_added"))
                f();
            else
                throw PythonMethodNotImplemented("EnvironmentImplementation", "need_keys_added");
        }

        virtual const std::shared_ptr<const MetadataValueKey<std::string> > format_key() const
        {
            std::unique_lock<std::recursive_mutex> l(get_mutex());

            if (bp::override f = get_override("format_key"))
                return f();
            else
                throw PythonMethodNotImplemented("EnvironmentImplementation", "format_key");
        }

        virtual const std::shared_ptr<const MetadataValueKey<FSPath> > config_location_key() const
        {
            std::unique_lock<std::recursive_mutex> l(get_mutex());

            if (bp::override f = get_override("config_location_key"))
                return f();
            else
                throw PythonMethodNotImplemented("EnvironmentImplementation", "config_location_key");
        }

        virtual const std::shared_ptr<const MetadataValueKey<FSPath> > preferred_root_key() const
        {
            std::unique_lock<std::recursive_mutex> l(get_mutex());

            if (bp::override f = get_override("preferred_root_key"))
                return f();
            else
                throw PythonMethodNotImplemented("EnvironmentImplementation", "preferred_root_key");
        }

        virtual const std::shared_ptr<const MetadataValueKey<FSPath> > system_root_key() const
        {
            std::unique_lock<std::recursive_mutex> l(get_mutex());

            if (bp::override f = get_override("system_root_key"))
                return f();
            else
                throw PythonMethodNotImplemented("EnvironmentImplementation", "system_root_key");
        }

        virtual Tribool interest_in_suggestion(
                const std::shared_ptr<const PackageID> &,
                const PackageDepSpec &) const
        {
            throw PythonMethodNotImplemented("EnvironmentImplementation", "interest_in_suggestion");
        }

        virtual const Tribool want_choice_enabled(
                const std::shared_ptr<const PackageID> &,
                const std::shared_ptr<const Choice> &,
                const UnprefixedChoiceName &
                ) const
        {
            throw PythonMethodNotImplemented("EnvironmentImplementation", "want_choice_enabled");
        }

        virtual const std::string value_for_choice_parameter(
                const std::shared_ptr<const PackageID> &,
                const std::shared_ptr<const Choice> &,
                const UnprefixedChoiceName &
                ) const
        {
            throw PythonMethodNotImplemented("EnvironmentImplementation", "value_for_choice_parameter");
        }

        virtual std::shared_ptr<const Set<UnprefixedChoiceName> > known_choice_value_names(
                const std::shared_ptr<const PackageID> &,
                const std::shared_ptr<const Choice> &
                ) const
        {
            throw PythonMethodNotImplemented("EnvironmentImplementation", "known_choice_value_names");
        }

        virtual const std::shared_ptr<OutputManager> create_output_manager(
                const CreateOutputManagerInfo &) const
        {
            return std::make_shared<StandardOutputManager>();
        }

        virtual const std::shared_ptr<Repository> repository_from_new_config_file(
                const FSPath &)
        {
            throw PythonMethodNotImplemented("EnvironmentImplementation", "repository_from_new_config_file");
        }

        virtual void update_config_files_for_package_move(
                const PackageDepSpec &, const QualifiedPackageName &) const
        {
            throw PythonMethodNotImplemented("EnvironmentImplementation", "update_config_files_for_package_move");
        }

        virtual QualifiedPackageName fetch_unique_qualified_package_name(
                const PackageNamePart &, const Filter & = all_filter(), const bool disambiguate = true) const
        {
            throw PythonMethodNotImplemented("EnvironmentImplementation", "fetch_unique_qualified_package_name");
        }
};

BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(fetch_unique_qualified_package_name_overloads, fetch_unique_qualified_package_name, 1, 3)

void expose_environment()
{
    /**
     * Exceptions
     */
    ExceptionRegister::get_instance()->add_exception<paludis_environment::PaludisConfigError>
        ("PaludisConfigError", "ConfigurationError",
         "Thrown if a configuration error is encountered by PaludisConfig.");
    ExceptionRegister::get_instance()->add_exception<paludis_environment::PaludisConfigNoDirectoryError>
        ("PaludisConfigNoDirectoryError", "PaludisConfigError",
         "Thrown if the config directory cannot be found by PaludisConfig.");

    /**
     * StringIterable
     */
    class_iterable<Sequence<std::string> >
        (
         "StringIterable",
         "Iterable of string",
         true
        );

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

        .def("create", &EnvironmentFactory::create,
                "create(spec_string) -> Environment\n"
                "Make Environment from specification."
            )
        ;

    const std::shared_ptr<Repository> (Environment::* fetch_repository_ptr)(const RepositoryName &) = &Environment::fetch_repository;

    /**
     * Environment
     */
    bp::class_<Environment, std::shared_ptr<Environment>, boost::noncopyable>
        (
         "Environment",
         "Represents a working environment, which contains an available packages database\n"
         "and provides various methods for querying package visibility and options.",
         bp::no_init
        )

        .def("set", &Environment::set,
                "set(SetName) -> DepSpec\n"
                "Fetch a named set."
            )

        .add_property("set_names", &Environment::set_names,
                "[ro] SetNamesIterable\n"
                "All known named sets."
            )

        .def("__getitem__", &Environment::operator[],
                "[selection] -> list of PackageID\n"
                "Return PackageID instances matching a given selection."
            )

        .def("fetch_repository", fetch_repository_ptr, bp::with_custodian_and_ward_postcall<0, 1>(),
                "fetch_repository(RepositoryName) -> Repository\n"
                "Fetch a named repository."
            )

        .def("fetch_unique_qualified_package_name", &Environment::fetch_unique_qualified_package_name,
             fetch_unique_qualified_package_name_overloads(
                "fetch_unique_qualified_package_name(PackageNamePart[, Filter[, bool]]) -> QualifiedPackageName\n"
                "Disambiguate a package name.  If a filter is specified, "
                "limit the potential results to packages that match."
                )
            )

        .def("more_important_than", &Environment::more_important_than,
                "more_important_than(RepositoryName, RepositoryName) -> bool\n"
                "Return true if the first repository is more important than the second."
            )

        .def("reduced_uid", &Environment::reduced_uid,
                "reduced_uid() -> int\n"
                "User id to use when reduced privs are permissible."
            )

        .def("reduced_gid", &Environment::reduced_gid,
                "reduced_gid() -> int\n"
                "Group id to use when reduced privs are permissible."
            )

        .add_property("repositories",
                bp::range(&Environment::begin_repositories, &Environment::end_repositories),
                "[ro] Iterable of Repository\n"
                "Our repositories"
                )
        ;

    /**
     * EnvironmentImplementation
     */
    typedef EnvironmentImplementation EnvImp;
    typedef EnvironmentImplementationWrapper EnvImpW;

    bp::class_<EnvironmentImplementationWrapper, std::shared_ptr<EnvironmentImplementationWrapper>,
            bp::bases<Environment>, boost::noncopyable>
        (
         "EnvironmentImplementation",
         "Represents a working environment, which contains an available packages database\n"
         "and provides various methods for querying package visibility and options.\n"
         "This class can be subclassed in Python.",
         bp::init<>()
        )

        .def("accept_license", bp::pure_virtual(&EnvImp::accept_license),
                "accept_license(str, PackageID) -> bool\n"
                "Do we accept a particular license for a particular package?"
            )

        .def("accept_keywords", bp::pure_virtual(&EnvImp::accept_keywords),
                "accept_keywords(KeywordsNameIterable, PackageID)\n"
                "Do we accept any of the specified keywords for a particular package?\n\n"
                "If the collection includes \"*\", should return true."
            )

        .def("mask_for_breakage", bp::pure_virtual(&EnvImp::mask_for_breakage),
                "mask_for_breakage(PackageID) -> Mask\n"
                "Do we have a 'breaks' mask for a particular package?\n\n"
                "Returns None if no."
            )

        .def("mask_for_user", bp::pure_virtual(&EnvImp::mask_for_user),
                "mask_for_user(PackageID, bool) -> Mask\n"
                "Do we have a 'user' mask for a particular package?\n\n"
                "Returns None if no. The second parameter should be true if the mask will be overridden "
                "and false otherwise."
            )

        .def("unmasked_by_user", bp::pure_virtual(&EnvImp::unmasked_by_user),
                "unmasked_by_user(PackageID, String) -> bool\n"
                "Do we have a user unmask for a particular package?\n\n"
                "This is only applied to repository and profile style masks, not\n"
                "keywords, licences etc. If true, user_mask shouldn't be used."
            )

        .def("bashrc_files", &EnvImp::bashrc_files, &EnvImpW::default_bashrc_files,
                "bashrc_files() -> list of paths\n"
                "Return a collection of bashrc files to be used by the various components\n"
                "that are implemented in bash."
            )

        .def("syncers_dirs", &EnvImp::syncers_dirs, &EnvImpW::default_syncers_dirs,
                "syncers_dirs() -> list of paths\n"
                "Return directories to search for syncer scripts."
            )

        .def("fetchers_dirs", &EnvImp::fetchers_dirs, &EnvImpW::default_fetchers_dirs,
                "fetchers_dirs() -> list of paths\n"
                "Return directories to search for fetcher scripts."
            )

        .def("hook_dirs", bp::pure_virtual(&EnvImp::hook_dirs),
                "hook_dirs() -> list of paths\n"
                "Return directories to search for hooks."
            )

        .def("reduced_uid", bp::pure_virtual(&EnvImp::reduced_uid),
                "reduced_uid() -> int\n"
                "User id to use when reduced privs are permissible."
            )

        .def("reduced_gid", bp::pure_virtual(&EnvImp::reduced_gid),
                "reduced_gid() -> int\n"
                "Group id to use when reduced privs are permissible."
            )

        .def("mirrors", bp::pure_virtual(&EnvImp::mirrors),
                "mirrors(str) -> list of str\n"
                "Return the mirror URI prefixes for a named mirror."
            )

        .def("set_names", &EnvImp::set_names, &EnvImpW::default_set_names,
                "set_names() -> list of SetName\n"
                "Return all known named sets."
            )

        .def("set", &EnvImp::set, &EnvImpW::default_set,
                "set(SetName) -> CompositeDepSpec\n"
                "Return a named set.\n\n"
                "If the named set is not known, returns None."
            )

        .def("distribution", &EnvImp::distribution, &EnvImpW::default_distribution,
                "distribution() -> str\n"
                "NEED_DOC"
            )

        .def("__getitem__", &EnvImp::operator[], &EnvImpW::default_operator_square_brackets,
                "[selection] -> list of PackageID\n"
                "Return PackageID instances matching a given selection."
            )

        .def("fetch_repository", fetch_repository_ptr, bp::with_custodian_and_ward_postcall<0, 1>(),
                "fetch_repository(RepositoryName) -> Repository\n"
                "Fetch a named repository."
            )

        .def("fetch_unique_qualified_package_name", &EnvImpW::fetch_unique_qualified_package_name,
             fetch_unique_qualified_package_name_overloads(
                "fetch_unique_qualified_package_name(PackageNamePart[, Filter[, bool]]) -> QualifiedPackageName\n"
                "Disambiguate a package name.  If a filter is specified, "
                "limit the potential results to packages that match."
                )
            )

        .def("more_important_than", &EnvImpW::more_important_than,
                "more_important_than(RepositoryName, RepositoryName) -> bool\n"
                "Return true if the first repository is more important than the second."
            )

        .add_property("repositories",
                bp::range(&EnvImpW::begin_repositories, &EnvImpW::end_repositories),
                "[ro] Iterable of Repository\n"
                "Our repositories"
                )
        ;
        ;

    /**
     * PaludisEnvironment
     */
    bp::class_<PaludisEnvironment, bp::bases<Environment>, boost::noncopyable>
        (
         "PaludisEnvironment",
         "The PaludisEnvironment is an Environment that corresponds to the normal operating evironment.",
         bp::init<const std::string &>("__init__(string)")
        )
        .add_property("config_dir", &PaludisEnvironment::config_dir,
                "[ro] string\n"
                "The config directory."
                )
        ;

    /**
     * TestEnvironment
     */
    bp::class_<TestEnvironment, bp::bases<Environment>, boost::noncopyable>
        (
         "TestEnvironment",
         "A TestEnvironment is an environment used during testing that lets us "
         "control all the options rather than reading them from configuration files.",
         bp::init<>("__init__()")
        );

    ExceptionRegister::get_instance()->add_exception<DuplicateRepositoryError>
        ("DuplicateRepositoryError", "BaseException",
         "Thrown if a Repository with the same name as an existing member is added to an Environment.");

    ExceptionRegister::get_instance()->add_exception<AmbiguousPackageNameError>
        ("AmbiguousPackageNameError", "BaseException",
         "Thrown if an Environment query results in more than one matching Package.");

    ExceptionRegister::get_instance()->add_exception<NoSuchPackageError>
        ("NoSuchPackageError", "BaseException",
         "Thrown if there is no Package in an Environment with the given name.");

    ExceptionRegister::get_instance()->add_exception<NoSuchRepositoryError>
        ("NoSuchRepositoryError", "BaseException",
         "Thrown if there is no Repository in a RepositoryDatabase with the given name.");
}