64
62
Each key references another dict with saved data from a specific script.\n";
66
64
char M_Registry_GetKey_doc[] =
67
"(name) - Get a specific entry (dict) from the Registry dictionary\n\
68
(name) - a string that references a specific script.\n";
65
"(name, disk = False) - Get an entry (a dict) from the Registry dictionary\n\
66
(name) - a string that references a specific script;\n\
67
(disk = False) - search on the user (if available) or default scripts config\n\
70
70
char M_Registry_SetKey_doc[] =
71
"(key, dict) - Store an entry in the Registry dictionary.\n\
71
"(key, dict, disk = False) - Store an entry in the Registry dictionary.\n\
72
72
If an entry with the same 'key' already exists, it is substituted.\n\
73
73
(key) - the string to use as a key for the dict being saved.\n\
74
(dict) - a dictionary with the data to be stored.\n";
74
(dict) - a dictionary with the data to be stored.\n\
75
(disk = False) - also write data as a config file inside the user (if\n\
76
available) or default scripts config data dir.\n";
76
78
char M_Registry_RemoveKey_doc[] =
77
"(key) - Remove the dict with key 'key' from the Registry.\n";
79
"(key, disk = False) - Remove the dict with key 'key' from the Registry.\n\
80
(key) - the name of the key to delete;\n\
81
(disk = False) - if True the respective config file is also deleted.\n";
79
83
/*****************************************************************************/
80
84
/* Python method structure definition for Blender.Registry module: */
119
123
PyObject *pyentry = NULL;
120
124
PyObject *pydict = NULL;
122
127
if( !bpy_registryDict )
123
128
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
124
"No Registry dictionary found!" );
129
"No Registry dictionary found!" );
126
if( !PyArg_ParseTuple( args, "O!", &PyString_Type, &pyentry ) )
131
if( !PyArg_ParseTuple( args, "O!|i", &PyString_Type, &pyentry, &disk ) )
127
132
return EXPP_ReturnPyObjError( PyExc_AttributeError,
128
"expected a string" );
133
"expected a string and optionally a bool" );
130
135
pydict = PyDict_GetItem( bpy_registryDict, pyentry ); /* borrowed ... */
133
/* return EXPP_ReturnPyObjError (PyExc_KeyError,
134
"no such key in the Registry"); */
135
pydict = Py_None; /* better to return None than an error */
137
Py_INCREF( pydict ); /* ... so we incref it */
138
/* should we copy the dict instead? */
139
/* try to get data from disk */
141
PyOS_snprintf(buf, sizeof(buf),
142
"import Blender, BPyRegistry; BPyRegistry.LoadConfigData('%s')",
143
PyString_AsString(pyentry));
144
if (!PyRun_SimpleString(buf))
145
pydict = PyDict_GetItem(bpy_registryDict, pyentry);
149
if (!pydict) /* no need to return a KeyError, since without doubt */
150
pydict = Py_None; /* Py_None means no key (all valid keys are dicts) */
153
return EXPP_incr_ret (pydict); /* ... so we incref it */
142
156
/*****************************************************************************/
148
162
PyObject *pystr = NULL;
149
163
PyObject *pydict = NULL;
151
166
if( !bpy_registryDict )
152
167
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
153
168
"No Registry dictionary found!" );
155
if( !PyArg_ParseTuple( args, "O!O!",
170
if( !PyArg_ParseTuple( args, "O!O!|i",
156
171
&PyString_Type, &pystr, &PyDict_Type,
158
173
return EXPP_ReturnPyObjError( PyExc_AttributeError,
159
174
"expected a string and a dictionary" );
162
177
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
163
178
"Registry_SetKey: couldn't update the Registry dict" );
181
/* try to save data to disk */
183
PyOS_snprintf(buf, sizeof(buf),
184
"import Blender, BPyRegistry; BPyRegistry.SaveConfigData('%s')",
185
PyString_AsString(pystr));
186
if (PyRun_SimpleString(buf) != 0) {
189
fprintf(stderr, "\nCan't save script configuration data!\n");
165
193
Py_INCREF( Py_None );
173
201
static PyObject *M_Registry_RemoveKey( PyObject * self, PyObject * args )
175
203
PyObject *pystr = NULL;
177
206
if( !bpy_registryDict )
178
207
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
179
208
"No Registry dictionary found!" );
181
if( !PyArg_ParseTuple( args, "O!", &PyString_Type, &pystr ) )
210
if( !PyArg_ParseTuple( args, "O!|i", &PyString_Type, &pystr, &disk ) )
182
211
return EXPP_ReturnPyObjError( PyExc_AttributeError,
183
"expected a string" );
212
"expected a string and optionally a bool" );
185
214
if( PyDict_DelItem( bpy_registryDict, pystr ) ) /* returns 0 on success */
186
215
return EXPP_ReturnPyObjError( PyExc_KeyError,
187
216
"no such key in the Registry" );
218
/* try to delete from disk too */
220
PyOS_snprintf(buf, sizeof(buf),
221
"import Blender, BPyRegistry; BPyRegistry.RemoveConfigData('%s')",
222
PyString_AsString(pystr));
223
if (PyRun_SimpleString(buf) != 0) {
226
fprintf(stderr, "\nCan't remove script configuration data file!\n");
189
230
Py_INCREF( Py_None );