aboutsummaryrefslogtreecommitdiff
path: root/python/environment.cc
blob: f344d1f533cc5bb38df9b59ec8c8384b9b668777 (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
/* 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/environment.hh>
#include <paludis/environments/environment_maker.hh>
#include <paludis/environments/adapted/adapted_environment.hh>
#include <paludis/environments/paludis/paludis_environment.hh>
#include <paludis/environments/paludis/paludis_config.hh>
#include <paludis/environments/no_config/no_config_environment.hh>
#include <paludis/environments/test/test_environment.hh>
#include <paludis/package_id.hh>

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

struct NoConfigEnvironmentWrapper :
    NoConfigEnvironment
{
    NoConfigEnvironmentWrapper(const FSEntry & env_dir, const FSEntry & cache_dir,
            const FSEntry & master_repo_dir) :
        NoConfigEnvironment(no_config_environment::Params(env_dir, cache_dir, false,
                    no_config_environment::ncer_auto, master_repo_dir)
                )
    {
    }
};

void PALUDIS_VISIBLE expose_environment()
{
    /**
     * Exceptions
     */
    ExceptionRegister::get_instance()->add_exception<NoSuchEnvironmentTypeError>
        ("NoSuchEnvironmentTypeError", "ConfigurationError",
         "Thrown if an environment of the specified type does not exist.");
    ExceptionRegister::get_instance()->add_exception<PaludisEnvironmentSoDirNotADirectoryError>
        ("PaludisEnvironmentSoDirNotADirectoryError", "BaseException",
         "Thrown if PALUDIS_ENVIRONMENT_SO_DIR is not a directory.");
    ExceptionRegister::get_instance()->add_exception<PaludisEnvironmentSoDirCannotDlopenError>
        ("PaludisEnvironmentSoDirCannotDlopenError", "BaseException",
         "Thrown if a repository .so cannot be used.");
    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.");

    /**
     * Enums
     */
    enum_auto("MaskReasonsOption", last_mro,
            "Options for Environment.mask_reasons().");

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

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

    /**
     * MaskReasonsOptions
     */
    class_options<MaskReasonsOptions>
        (
         "MaskReasonsOptions", "MaskReasonsOption",
         "Options for Environment.mask_reasons()."
        );

    /**
     * Environment
     */
    tr1::shared_ptr<PackageDatabase> (Environment::* package_database)() =
        &Environment::package_database;
    bp::class_<Environment, tr1::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
        )
        .add_property("default_destinations", &Environment::default_destinations,
                "[ro] DestinationsIterable\n"
                "Default destination candidates for installing packages."
            )

        .add_property("package_database", bp::make_function(package_database,
                    bp::with_custodian_and_ward_postcall<0, 1>()),
                "[ro] PackageDatabase\n"
                "Our package databas."
                )

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

        .def("query_use", &Environment::query_use,
                "query_use(UseFlagName, PackageID) -> bool\n"
                "Is a particular use flag enabled for a particular package?"
            )

        .def("mask_reasons", &Environment::mask_reasons,
                (bp::arg("PackageID"), bp::arg("MaskReasonOptions")=MaskReasonsOptions()),
                "mask_reasons(PackageID, MaskReasonsOptions=MaskReasonsOptions())"
                " -> set of MaskReason\n"
                "Return the reasons for a package being masked."
            )

        .add_property("root", &Environment::root,
                "[ro] string\n"
                "Our root location for installs."
            )

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

    /**
     * AdaptedEnvironment
     */
    bp::class_<AdaptedEnvironment, bp::bases<Environment>, boost::noncopyable>
        (
         "AdaptedEnvironment",
         "An Environment that allows you to change aspects of an existing Environment,"
         " e.g. the state of a USE flag for a package.",
         bp::init<tr1::shared_ptr<Environment> >("__init__(Environment)")
        )
        .def("adapt_use", &AdaptedEnvironment::adapt_use,
                "adapt_use(PackageDepSpeec, UseFlagName, UseFlagState)\n"
                "Set the state of a USE flag for the given PackageDepSpec."
            )

        .def("clear_adaptions", &AdaptedEnvironment::clear_adaptions,
                "clear_adaptions()\n"
                "Clear all adaptions from this Environemnt."
            )
        ;

    /**
     * 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."
                )
        ;

    /**
     * NoConfigEnvironment
     */
    tr1::shared_ptr<Repository> (NoConfigEnvironment::*main_repository)()
        = &NoConfigEnvironment::main_repository;
    tr1::shared_ptr<Repository> (NoConfigEnvironment::*master_repository)()
        = &NoConfigEnvironment::master_repository;
    bp::class_<NoConfigEnvironmentWrapper, bp::bases<Environment>, boost::noncopyable>
        (
         "NoConfigEnvironment",
         "An environment that uses a single repository, with no user configuration.",
         bp::init<const FSEntry &, const FSEntry &, const FSEntry &>(
             (bp::arg("environment_dir"), bp::arg("write_cache_dir")="/var/empty",
              bp::arg("master_repository_dir")="/var/empty"),
             "__init__(environment_dir, write_cache_dir=\"/var/empty\", "
             "master_repository_dir=\"/var/empty\")"
             )
        )
        .add_property("main_repository", main_repository,
                "[ro] Repository\n"
                "Main repository."
                )

        .add_property("master_repository", master_repository,
                "[ro] Repository\n"
                "Master repository."
                )

        .add_property("accept_unstable", bp::object(), &NoConfigEnvironment::set_accept_unstable,
                "[wo] bool\n"
                "Should we accept unstable keywords?"
                )
        ;

    /**
     * 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__()")
        );

}