-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathgeanypy-project.c
111 lines (90 loc) · 3.21 KB
/
geanypy-project.c
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
#if defined(HAVE_CONFIG_H) && !defined(GEANYPY_WINDOWS)
# include "config.h"
#endif
#include "geanypy.h"
static void
Project_dealloc(Project *self)
{
g_return_if_fail(self != NULL);
self->ob_type->tp_free((PyObject *) self);
}
static int
Project_init(Project *self, PyObject *args, PyObject *kwds)
{
g_return_val_if_fail(self != NULL, -1);
self->project = geany_data->app->project;
return 0;
}
static PyObject *
Project_get_property(Project *self, const gchar *prop_name)
{
g_return_val_if_fail(self != NULL, NULL);
g_return_val_if_fail(prop_name != NULL, NULL);
if (!self->project)
Py_RETURN_NONE;
if (g_str_equal(prop_name, "base_path") && self->project->base_path)
return PyString_FromString(self->project->base_path);
else if (g_str_equal(prop_name, "description") && self->project->description)
return PyString_FromString(self->project->description);
else if (g_str_equal(prop_name, "file_name") && self->project->file_name)
return PyString_FromString(self->project->file_name);
else if (g_str_equal(prop_name, "file_patterns") && self->project->file_patterns)
{
guint i, len;
PyObject *set;
len = g_strv_length(self->project->file_patterns);
set = PyFrozenSet_New(NULL);
for (i = 0; i < len; i++)
PySet_Add(set, PyString_FromString(self->project->file_patterns[i]));
return set;
}
else if (g_str_equal(prop_name, "name") && self->project->name)
return PyString_FromString(self->project->name);
else if (g_str_equal(prop_name, "type") && self->project->type)
return Py_BuildValue("i", self->project->type);
Py_RETURN_NONE;
}
GEANYPY_PROPS_READONLY(Project);
static PyGetSetDef Project_getseters[] = {
GEANYPY_GETSETDEF(Project, "base_path",
"Base path of the project directory (maybe relative)."),
GEANYPY_GETSETDEF(Project, "description",
"Short description of the project."),
GEANYPY_GETSETDEF(Project, "file_name",
"Where the project file is stored."),
GEANYPY_GETSETDEF(Project, "file_patterns",
"Sequence of filename extension patterns."),
GEANYPY_GETSETDEF(Project, "name",
"The name of the project."),
GEANYPY_GETSETDEF(Project, "type",
"Identifier whether it is a pure Geany project or modified/"
"extended by a plugin."),
{ NULL }
};
PyTypeObject ProjectType = {
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
"geany.project.Project", /* tp_name */
sizeof(Project), /* tp_basicsize */
0, /* tp_itemsize */
(destructor) Project_dealloc, /* tp_dealloc */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* tp_print - tp_as_buffer */
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
"Wrapper around a GeanyProject structure.", /* tp_doc */
0, 0, 0, 0, 0, 0, 0, 0, /* tp_traverse - tp_members */
Project_getseters, /* tp_getset */
0, 0, 0, 0, 0, /* tp_base - tp_dictoffset */
(initproc) Project_init, /* tp_init */
0, 0, /* tp_alloc - tp_new */
};
static PyMethodDef ProjectModule_methods[] = { { NULL } };
PyMODINIT_FUNC initproject(void)
{
PyObject *m;
ProjectType.tp_new = PyType_GenericNew;
if (PyType_Ready(&ProjectType) < 0)
return;
m = Py_InitModule3("project", ProjectModule_methods, "Project information");
Py_INCREF(&ProjectType);
PyModule_AddObject(m, "Project", (PyObject *)&ProjectType);
}