|
1 .. _cone-api-howto: |
|
2 |
1 How to use cone APIs |
3 How to use cone APIs |
2 ==================== |
4 ==================== |
3 |
5 |
4 The ConE public usage is described here with few common use cases as HowTo guides. |
6 The ConE public usage is described here with few common use cases as HowTo guides. |
5 |
7 |
|
8 * See `Cone API epydoc <../epydoc/index.html>`_ for reference guide of api functions. |
|
9 |
6 How to open a Configuration project |
10 How to open a Configuration project |
7 ----------------------------------- |
11 ----------------------------------- |
|
12 |
|
13 * See reference of `Project class <../epydoc/cone.public.api.Project-class.html>`_ |
8 |
14 |
9 To open a project with ConE the api offers a Storage and Project classes. The Storage is the storage |
15 To open a project with ConE the api offers a Storage and Project classes. The Storage is the storage |
10 agostic implemenetation for cpf/zip, filestorage and soon also a webstorage. To access anything in ConE |
16 agostic implemenetation for cpf/zip, filestorage and soon also a webstorage. To access anything in ConE |
11 you must a project open. |
17 you must a project open. |
|
18 |
12 |
19 |
13 .. code-block:: python |
20 .. code-block:: python |
14 |
21 |
15 from cone.public import api,exceptions |
22 from cone.public import api,exceptions |
16 """ |
23 """ |
30 prj = api.Project(api.Storage.open('test.cpf', 'w')) |
37 prj = api.Project(api.Storage.open('test.cpf', 'w')) |
31 |
38 |
32 |
39 |
33 How to access and manipulate Configurations |
40 How to access and manipulate Configurations |
34 ------------------------------------------- |
41 ------------------------------------------- |
|
42 |
|
43 * See reference of `Configuration class <../epydoc/cone.public.api.Configuration-class.html>`_ |
35 |
44 |
36 A Configuration normally is presented inside the Configuration project as a .confml file. So when you |
45 A Configuration normally is presented inside the Configuration project as a .confml file. So when you |
37 are accessing configurations your are actually accessing confml files. The project offers funtionality to |
46 are accessing configurations your are actually accessing confml files. The project offers funtionality to |
38 get,add, remove configurations, which acts on root configurations inside the given project. |
47 get,add, remove configurations, which acts on root configurations inside the given project. |
39 |
48 |
90 .. code-block:: python |
99 .. code-block:: python |
91 |
100 |
92 myconfig = prj.get_configuration('myconfig.confml') |
101 myconfig = prj.get_configuration('myconfig.confml') |
93 myconfig.include_configuration('../data.confml') |
102 myconfig.include_configuration('../data.confml') |
94 |
103 |
|
104 |
|
105 How to set / write metadata to a Configuration root file |
|
106 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
|
107 |
|
108 The metadata element is currently confml model specific, so you need to import the confml.model to enable metadata writing. |
|
109 The ConfmlMeta element is desinged so that it can contain several ConfmlMetaProperty elements, each of which can be in |
|
110 different xml namespaces. |
|
111 |
|
112 .. code-block:: python |
|
113 |
|
114 from cone.public import api |
|
115 from cone.confml import model |
|
116 |
|
117 store = api.Storage.open(".","w") |
|
118 prj = api.Project(store) |
|
119 config = prj.create_configuration("test_meta.confml") |
|
120 |
|
121 prop1 = model.ConfmlMetaProperty("test", 'testing string') |
|
122 prop2 = model.ConfmlMetaProperty("testName", 'testing string2', \ |
|
123 "http://www.nokia.com/xml/cpf-id/1", \ |
|
124 attrs={"name":"name1", "value": "value1"}) |
|
125 prop3 = model.ConfmlMetaProperty("configuration-property", None, \ |
|
126 "http://www.nokia.com/xml/cpf-id/1", \ |
|
127 attrs={"name":"sw_version", "value": "1.0.0"}) |
|
128 metaelem = model.ConfmlMeta([prop1, prop2, prop3]) |
|
129 |
|
130 config.meta = metaelem |
|
131 config.save() |
|
132 prj.close() |
|
133 |
|
134 The output file *test_meta.confml* should look like this.. |
|
135 |
|
136 .. code-block:: xml |
|
137 |
|
138 <configuration name="test_meta_confml" xmlns="http://www.s60.com/xml/confml/2" ...> |
|
139 <meta xmlns:cv="http://www.nokia.com/xml/cpf-id/1"> |
|
140 <test>testing string</test> |
|
141 <cv:testName name="name1" value="value1">testing string2</cv:testName> |
|
142 <cv:configuration-property name="sw_version" value="1.0.0" /> |
|
143 </meta> |
|
144 </configuration> |
|
145 |
95 Feature Access and manipulation |
146 Feature Access and manipulation |
96 ------------------------------- |
147 ------------------------------- |
|
148 * See reference of `Feature class <../epydoc/cone.public.api.Feature-class.html>`_ |
97 |
149 |
98 How to add a Feature to Configuration |
150 How to add a Feature to Configuration |
99 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
151 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
100 |
152 |
101 To add a Feature to Configuration ``add_feature()`` method can be used. |
153 To add a Feature to Configuration ``add_feature()`` method can be used. |
128 conf1.remove_feature('feature1.feature12') # and then remove it |
180 conf1.remove_feature('feature1.feature12') # and then remove it |
129 """ finally save and close project """ |
181 """ finally save and close project """ |
130 prj.save() |
182 prj.save() |
131 prj.close() |
183 prj.close() |
132 |
184 |
|
185 |
|
186 Feature acces via Views |
|
187 ----------------------- |
|
188 * See reference of `View class <../epydoc/cone.public.api.View-class.html>`_ |
|
189 * See reference of `Group class <../epydoc/cone.public.api.Group-class.html>`_ |
|
190 * See reference of `FeatureLink class <../epydoc/cone.public.api.FeatureLink-class.html>`_ |
133 |
191 |
134 How to get a Feature from Configuration |
192 How to get a Feature from Configuration |
135 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
193 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
136 |
194 |
137 Features can be accessed through View: |
195 Features can be accessed through View: |
267 feature2.value = "my_value" |
325 feature2.value = "my_value" |
268 """ finally save and close project """ |
326 """ finally save and close project """ |
269 prj.save() |
327 prj.save() |
270 prj.close() |
328 prj.close() |
271 |
329 |
|
330 |
|
331 How to Create a View |
|
332 ^^^^^^^^^^^^^^^^^^^^ |
|
333 |
|
334 .. code-block:: python |
|
335 |
|
336 from cone.public import api |
|
337 from cone.confml import model |
|
338 |
|
339 store = api.Storage.open(".","w") |
|
340 prj = api.Project(store) |
|
341 """ First create the configuration with two features """ |
|
342 if prj.is_configuration("test_override.confml"): |
|
343 config = prj.get_configuration("test_override.confml") |
|
344 else: |
|
345 config = prj.create_configuration("test_override.confml") |
|
346 fea1 = config.create_feature("foo", name="foo name") |
|
347 fea2 = fea1.create_feature("bar", name="bar name") |
|
348 |
|
349 """ Create the view and group to it """ |
|
350 view = config.create_view('testview') |
|
351 group = view.create_group('group1') |
|
352 |
|
353 """ |
|
354 Create a featurelink. |
|
355 Note! the featurelink now overrides the name attribute of the original feature. |
|
356 """ |
|
357 link = group.create_featurelink('foo', name="foo name overridden") |
|
358 """ override the description attribute of the view link """ |
|
359 link.desc = "override desc" |
|
360 config.save() |
|
361 |
|
362 How to Get a view and test attribute overrides |
|
363 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
|
364 In this example we assume that the previous example was stored to a file *test_override.confml*. |
|
365 |
|
366 .. code-block:: python |
|
367 |
|
368 from cone.public import api |
|
369 from cone.confml import model |
|
370 |
|
371 store = api.Storage.open(".","w") |
|
372 prj = api.Project(store) |
|
373 config = prj.get_configuration("test_override.confml") |
|
374 """ get the view and a feature from it """ |
|
375 view = config.get_view('testview') |
|
376 fea = view.get_feature('group1.foo') |
|
377 """ assert that the feature attributes have been overridden in the view """ |
|
378 assert(fea.has_attribute('name')) |
|
379 assert(fea.has_attribute('desc')) |
|
380 assert(fea.has_attribute('minLength') == False) |
|
381 assert(fea._obj.name == 'foo name') |
|
382 prj.close() |
|
383 |
|
384 |
272 Data access and manipulation |
385 Data access and manipulation |
273 ---------------------------- |
386 ---------------------------- |
274 The data access inside a configuration is possible, but basically this can be avoided by manipulating the values |
387 The data access inside a configuration is possible, but basically this can be avoided by manipulating the values |
275 of features, which actually modify the data elements inside the configuration. |
388 of features, which actually modify the data elements inside the configuration. |
276 However if direct data element access is needed, here's how you can do it. |
389 However if direct data element access is needed, here's how you can do it. |