aboutsummaryrefslogtreecommitdiff
path: root/python/action.cc
blob: 0b4524a3bf84b886a946407ecf311b2b20615bb4 (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
/* 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 <paludis/action.hh>
#include <paludis/util/make_named_values.hh>
#include <paludis/util/make_shared_ptr.hh>
#include <paludis/util/sequence.hh>
#include <paludis/standard_output_manager.hh>
#include <paludis/repository.hh>
#include <tr1/memory>

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

template <typename A_>
class class_supports_action_test :
    public bp::class_<SupportsActionTest<A_>, bp::bases<SupportsActionTestBase> >
{
    public:
        class_supports_action_test(const std::string & action) :
            bp::class_<SupportsActionTest<A_>, bp::bases<SupportsActionTestBase> >(
                    ("Supports" + action + "ActionTest").c_str(),
                    "SupportsActionTest is used by PackageID::supports_action and\n"
                    "Repository::some_ids_might_support_action to query whether a\n"
                    "particular action is supported by that PackageID or potentially\n"
                    "supported by some IDs in that Repository.",
                    bp::init<>("__init__()")
                    )
        {
        }
};

namespace
{
    WantPhase want_all_phases(const std::string &)
    {
        return wp_yes;
    }

    std::tr1::shared_ptr<OutputManager> make_standard_output_manager(const Action &)
    {
        return make_shared_ptr(new StandardOutputManager);
    }

    void cannot_perform_uninstall(const std::tr1::shared_ptr<const PackageID> & id, const UninstallActionOptions &)
    {
        throw InternalError(PALUDIS_HERE, "Can't uninstall '" + stringify(*id) + "'");
    }

    bool ignore_nothing(const FSEntry &)
    {
        return false;
    }

    InstallActionOptions * make_install_action_options(
            const std::tr1::shared_ptr<paludis::Repository> & r)
    {
        return new InstallActionOptions(make_named_values<InstallActionOptions>(
                    value_for<n::destination>(r),
                    value_for<n::make_output_manager>(&make_standard_output_manager),
                    value_for<n::perform_uninstall>(&cannot_perform_uninstall),
                    value_for<n::replacing>(make_shared_ptr(new PackageIDSequence)),
                    value_for<n::want_phase>(&want_all_phases)
                    ));
    }

    UninstallActionOptions * make_uninstall_action_options(
            const std::string & c)
    {
        return new UninstallActionOptions(make_named_values<UninstallActionOptions>(
                    value_for<n::config_protect>(c),
                    value_for<n::if_for_install_id>(make_null_shared_ptr()),
                    value_for<n::ignore_for_unmerge>(&ignore_nothing),
                    value_for<n::is_overwrite>(false),
                    value_for<n::make_output_manager>(&make_standard_output_manager)
                    ));
    }

    InfoActionOptions * make_info_action_options()
    {
        return new InfoActionOptions(make_named_values<InfoActionOptions>(
                    value_for<n::make_output_manager>(&make_standard_output_manager)
                    ));
    }

    ConfigActionOptions * make_config_action_options()
    {
        return new ConfigActionOptions(make_named_values<ConfigActionOptions>(
                    value_for<n::make_output_manager>(&make_standard_output_manager)
                    ));
    }

    PretendActionOptions * make_pretend_action_options()
    {
        return new PretendActionOptions(make_named_values<PretendActionOptions>(
                    value_for<n::make_output_manager>(&make_standard_output_manager)
                    ));
    }

    FetchActionOptions * make_fetch_action_options(
            const bool exclude_unmirrorable,
            const bool fetch_unneeded,
            const bool safe_resume
            )
    {
        FetchParts parts;
        parts = parts + fp_regulars + fp_extras;
        if (fetch_unneeded)
            parts += fp_unneeded;

        return new FetchActionOptions(make_named_values<FetchActionOptions>(
                    value_for<n::errors>(make_shared_ptr(new Sequence<FetchActionFailure>)),
                    value_for<n::exclude_unmirrorable>(exclude_unmirrorable),
                    value_for<n::fetch_parts>(parts),
                    value_for<n::ignore_unfetched>(false),
                    value_for<n::make_output_manager>(&make_standard_output_manager),
                    value_for<n::safe_resume>(safe_resume),
                    value_for<n::ignore_not_in_manifest>(false)
                    ));
    }

}

void expose_action()
{
    /**
     * Exceptions
     */
    ExceptionRegister::get_instance()->add_exception<ActionFailedError>
        ("ActionFailedError", "BaseException",
         "Thrown if an action fails.");
    ExceptionRegister::get_instance()->add_exception<ActionAbortedError>
        ("ActionAbortedError", "BaseException",
         "Thrown if an action is aborted.");

    /**
     * InstallActionOptions
     */
    bp::class_<InstallActionOptions>
        (
         "InstallActionOptions",
         "Options for InstallAction.",
         bp::no_init
        )

        .def("__init__",
                bp::make_constructor(&make_install_action_options),
                "__init__(Repository)"
            )

        .add_property("destination",
                &named_values_getter<InstallActionOptions, n::destination, std::tr1::shared_ptr<Repository>, &InstallActionOptions::destination>,
                &named_values_setter<InstallActionOptions, n::destination, std::tr1::shared_ptr<Repository>, &InstallActionOptions::destination>,
                "[rw] Repository"
                )
        ;

    /**
     * UninstallActionOptions
     */
    bp::class_<UninstallActionOptions>
        (
         "UninstallActionOptions",
         "Options for UninstallAction.",
         bp::no_init
        )

        .def("__init__",
                bp::make_constructor(&make_uninstall_action_options),
                "__init__(String)"
            )

        .add_property("config_protect",
                &named_values_getter<UninstallActionOptions, n::config_protect, std::string, &UninstallActionOptions::config_protect>,
                &named_values_setter<UninstallActionOptions, n::config_protect, std::string, &UninstallActionOptions::config_protect>,
                "[rw] String"
                )
        ;

    /**
     * ConfigActionOptions
     */
    bp::class_<ConfigActionOptions>
        (
         "ConfigActionOptions",
         "Options for ConfigAction.",
         bp::no_init
        )

        .def("__init__",
                bp::make_constructor(&make_config_action_options),
                "__init__()"
            )
        ;

    /**
     * InfoActionOptions
     */
    bp::class_<InfoActionOptions>
        (
         "InfoActionOptions",
         "Options for InfoAction.",
         bp::no_init
        )

        .def("__init__",
                bp::make_constructor(&make_info_action_options),
                "__init__()"
            )
        ;

    /**
     * PretendActionOptions
     */
    bp::class_<PretendActionOptions>
        (
         "PretendActionOptions",
         "Options for PretendAction.",
         bp::no_init
        )

        .def("__init__",
                bp::make_constructor(&make_pretend_action_options),
                "__init__()"
            )
        ;

    /**
     * FetchActionOptions
     */
    bp::class_<FetchActionOptions>
        (
         "FetchActionOptions",
         "Options for FetchAction.",
         bp::no_init
        )

        .def("__init__",
                bp::make_constructor(&make_fetch_action_options),
                "__init__(exclude_unmirrorable, fetch_uneeded, safe_resume)"
            )

        .add_property("exclude_unmirrorable",
                &named_values_getter<FetchActionOptions, n::exclude_unmirrorable, bool, &FetchActionOptions::exclude_unmirrorable>,
                &named_values_setter<FetchActionOptions, n::exclude_unmirrorable, bool, &FetchActionOptions::exclude_unmirrorable>,
                "[rw] bool"
                )

        .add_property("safe_resume",
                &named_values_getter<FetchActionOptions, n::safe_resume, bool, &FetchActionOptions::safe_resume>,
                &named_values_setter<FetchActionOptions, n::safe_resume, bool, &FetchActionOptions::safe_resume>,
                "[rw] bool"
                )
        ;

   /**
     * Action
     */
    bp::class_<Action, boost::noncopyable>
        (
         "Action",
         "An Action represents an action that can be executed by a PackageID via\n"
         "PackageID::perform_action.",
         bp::no_init
        );

    /**
     * InstallAction
     */
    bp::class_<InstallAction, bp::bases<Action>, boost::noncopyable>
        (
         "InstallAction",
         "An InstallAction is used by InstallTask to perform a build / install on a\n"
         "PackageID.",
         bp::init<const InstallActionOptions &>("__init__(InstallActionOptions)")
        );

    /**
     * FetchAction
     */
    bp::class_<FetchAction, bp::bases<Action>, boost::noncopyable>
        (
         "FetchAction",
         "A FetchAction can be used to fetch source files for a PackageID using\n"
         "PackageID::perform_action.",
         bp::init<const FetchActionOptions &>("__init__(FetchActionOptions)")
        );

    /**
     * UninstallAction
     */
    bp::class_<UninstallAction, bp::bases<Action>, boost::noncopyable>
        (
         "UninstallAction",
         "An UninstallAction is used by UninstallTask to uninstall a PackageID.",
         bp::init<const UninstallActionOptions &>("__init__(UninstallActionOptions)")
        );

    /**
     * PretendAction
     */
    bp::class_<PretendAction, bp::bases<Action>, boost::noncopyable>
        (
         "PretendAction",
         "A PretendAction is used by InstallTask to handle install-pretend-phase\n"
         "checks on a PackageID.",
         bp::init<const PretendActionOptions &>("__init__(PretendActionOptions)")
        )
        .add_property("failed", &PretendAction::failed,
                "[ro] bool\n"
                "Did our pretend phase fail?"
                )
        ;

    /**
     * ConfigAction
     */
    bp::class_<ConfigAction, bp::bases<Action>, boost::noncopyable>
        (
         "ConfigAction",
         "A ConfigAction is used via PackageID::perform_action to execute\n"
         "post-install configuration (for example, via 'paludis --config')\n"
         "on a PackageID.",
         bp::init<ConfigActionOptions>("__init__(ConfigActionOptions)")
        );

    /**
     * InfoAction
     */
    bp::class_<InfoAction, bp::bases<Action>, boost::noncopyable>
        (
         "InfoAction",
         "An InfoAction is used via PackageID::perform_action to execute\n"
         "additional information (for example, via 'paludis --info')\n"
         "on a PackageID.",
         bp::init<InfoActionOptions>("__init__(InfoActionOptions)")
        );

    /**
     * SupportActionTestBase
     */
    bp::class_<SupportsActionTestBase, boost::noncopyable>
        (
         "SupportsActionTestBase",
         "Base class for SupportsActionTests.",
         bp::no_init
        );

    /**
     * SupportActionTests
     */
    class_supports_action_test<InstallAction>("Install");
    class_supports_action_test<FetchAction>("Fetch");
    class_supports_action_test<UninstallAction>("Uninstall");
    class_supports_action_test<PretendAction>("Pretend");
    class_supports_action_test<ConfigAction>("Config");
    class_supports_action_test<InfoAction>("Info");
}