aboutsummaryrefslogtreecommitdiff
path: root/python/name.cc
blob: 0df086c68712cc2d736d0e7156a1db7b643d3fcf (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
/* 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 <libwrapiter/libwrapiter_forward_iterator.hh>
#include <paludis/name.hh>

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

void PALUDIS_VISIBLE expose_name()
{
    ExceptionRegister::get_instance()->add_exception<PackageNamePartError>
        ("PackageNamePartError", "NameError");
    ExceptionRegister::get_instance()->add_exception<CategoryNamePartError>
        ("CategoryNamePartError", "NameError");
    ExceptionRegister::get_instance()->add_exception<QualifiedPackageNameError>
        ("QualifiedPackageNameError", "NameError");
    ExceptionRegister::get_instance()->add_exception<UseFlagNameError>
        ("UseFlagNameError", "NameError");
    ExceptionRegister::get_instance()->add_exception<IUseFlagNameError>
        ("IUseFlagNameError", "NameError");
    ExceptionRegister::get_instance()->add_exception<SlotNameError>
        ("SlotNameError", "NameError");
    ExceptionRegister::get_instance()->add_exception<RepositoryNameError>
        ("RepositoryNameError", "NameError");
    ExceptionRegister::get_instance()->add_exception<KeywordNameError>
        ("KeywordNameError", "NameError");
    ExceptionRegister::get_instance()->add_exception<SetNameError>
        ("SetNameError", "NameError");

    class_validated<PackageNamePart>
        pnp("PackageNamePart",
                "Holds a string that is a valid name for the package part of a QualifiedPackageName."
           );
    register_shared_ptrs_to_python<PackageNamePart>();

    class_collection<PackageNamePartCollection>
        pnpc("PackageNamePartCollection",
                "Iterable of PackageNamePart.\n"
                "A collection of PackageNamePart instances."
            );

    class_validated<CategoryNamePart>
        cnp("CategoryNamePart",
                "Holds a string that is a valid name for the category part of a QualifiedPackageName."
           );
    // CategoryNamePart + PackageNamePart = QualifiedPackageName
    cnp.def(bp::self + bp::other<PackageNamePart>());
    register_shared_ptrs_to_python<CategoryNamePart>();

    class_collection<CategoryNamePartCollection>
        cnpc("CategoryNamePartCollection",
                "Iterable of CategoryNamePart.\n"
                "A collection of CategoryNamePart instances."
            );

    class_validated<UseFlagName>
        ufn("UseFlagName",
                "Holds a string that is a valid name for a USE flag."
           );

    class_collection<UseFlagNameCollection>
        ufnc("UseFlagNameCollection",
                "Iterable of UseFlagName.\n"
                "A collection of UseFlagName instances."
            );

    class_validated<SlotName>
        sln("SlotName",
                "Holds a string that is a valid name for a SLOT."
           );
    register_shared_ptrs_to_python<SlotName>();

    class_validated<RepositoryName>
        rn("RepositoryName",
                "Holds a string that is a valid name for a Repository."
          );
    register_shared_ptrs_to_python<RepositoryName>();

    class_collection<RepositoryNameCollection>
        rnc("RepositoryNameCollection",
                "Iterable of RepositoryName\n"
                "A collection of RepositoryName instances."
            );

    class_validated<KeywordName>
        kn("KeywordName",
                "Holds a string that is a valid name for a KEYWORD."
          );

    class_collection<KeywordNameCollection>
        knc("KeywordNameCollection",
                "Iterable of KeywordName\n"
                "A collection of KeywordName instances."
            );

    class_validated<SetName>
        stn("SetName",
                "Holds a string that is a valid name for a set."
           );

    class_collection<SetNameCollection>
        sc("SetNameCollection",
                "Iterable of SetName\n"
                "A collection of set names."
          );

    class_collection<InheritedCollection>
        ic("InheritedCollection",
                "Iterable of string\n"
                "A collection of inherited packages."
          );

    register_shared_ptrs_to_python<QualifiedPackageName>();
    bp::class_<QualifiedPackageName>
        qpn("QualifiedPackageName",
                "Represents a category plus package name.",
                bp::init<const std::string &>("__init__(string)")
           );
    qpn.def(bp::init<const CategoryNamePart &, const PackageNamePart &>());
    qpn.def_readwrite("category", &QualifiedPackageName::category);
    qpn.def_readwrite("package", &QualifiedPackageName::package);
    qpn.def("__cmp__", &py_cmp<QualifiedPackageName>);
    qpn.def(bp::self_ns::str(bp::self));
    bp::implicitly_convertible<std::string, QualifiedPackageName>();

    class_collection<QualifiedPackageNameCollection>
        qpnc("QualifiedPackageNameCollection",
                "Iterable of QualifiedPackageName\n"
                "A collection of QualifiedPackageName instances."
            );

    bp::class_<IUseFlag>
        iuf("IUseFlag",
                "Represents an IUse flag.",
                bp::init<const std::string &, IUseFlagParseMode>("__init__(string, IUseFlagParseMode")
           );
    iuf.def(bp::init<const UseFlagName &, const UseFlagState &>("__init__(UseFlagName, UseFlagState)"));
    iuf.def("__cmp__", &py_cmp<IUseFlag>);
    iuf.def(bp::self_ns::str(bp::self));
    iuf.def_readwrite("flag", &IUseFlag::flag,
            "[rw] UseFlagName"
            );
    iuf.def_readwrite("state", &IUseFlag::state,
            "[rw] UseFlagState"
            );

    class_collection<IUseFlagCollection>
        iufc("IUseFlagCollection",
                "Iterable of IUseFlag\n"
                "A collection of use flags."
            );

    enum_auto("UseFlagState", last_use);
    enum_auto("IUseFlagParseMode", last_iuse_pm);
}