Browse Source

Changed the documentation in the editorial_model.translator.xmlfile module

Roland Haroutiounian 7 years ago
parent
commit
ce28dc134f
1 changed files with 119 additions and 103 deletions
  1. 119
    103
      lodel/editorial_model/translator/xmlfile.py

+ 119
- 103
lodel/editorial_model/translator/xmlfile.py View File

@@ -11,63 +11,76 @@ LodelContext.expose_modules(globals(), {
11 11
         'EmGroup'],
12 12
     'lodel.utils.mlstring': ['MlString']})
13 13
 
14
-##@package lodel.editorial_model.translator.xmlfile Translator module designed
15
-#to load & save EM in XML
14
+## @package lodel.editorial_model.translator.xmlfile
15
+# This module is a translator toolkit between and editorial model and an XML file.
16 16
 #
17
-# Structure of a xml file which represents an editorial model:
17
+# The XML file representing an editorial is composed by several nodes.
18
+#
19
+# @par \<name\>
20
+# The name of the model. It matches with the <b><em>name</em></b> field of the <b><em>EditorialModel class</em></b>
21
+#
22
+# @par \<description\>
23
+# This is the description of a composed element. Inside this node, we can have as many child node as there are languages in which it is translated. \n
24
+# Each translation is notified by a node, using the following scheme :
18 25
 # <ul>
19
-# <li>\<name\>: name of the model, field <b><em>name</em></b>  in class <b><em>EditorialModel</em></b> 
20
-# <li>\<description\>: field <b><em>description</em></b>  of a composed element, one for each language translation named 
21
-#               <ul><li>\<fre\> for french, 
22
-#               <li>\<eng\> for english,
23
-#               <li>\<esp\> for spanish,
24
-#               <li>\<ger\> for german</ul>
25
-# <li>\<classes\>: set of all <b><em>EmClass</em></b> in the model \n
26
-#    for each classe: \n
27
-#       \<class\><ul>
28
-#       <li>\<uid\>the class's id
29
-#       <li>\<display_name\> The name of the class, field <b><em>display_name</em></b>  of the <b><em>EmClass</em></b> , in different languages if they're available :
30
-#               <ul><li>\<fre\> for french, 
31
-#               <li>\<eng\> for english,
32
-#               <li>\<esp\> for spanish,
33
-#               <li>\<ger> for german</ul>
34
-#       <li>\<help_text\> Short explanation of the class's purpose, in different languages, as above
35
-#       <li>\<abstract\> True or False, field <b><em>abstract</em></b> of the <b><em>EmClass</em></b> 
36
-#       <li>\<pure_abstract\> True or False, field <b><em>pure_bastract</em></b> of the <b><em>EmClass</em></b>
37
-#       <li>\<group\><b><em>uid</em></b> of the group of the field <b><em>group</em></b> of the <b><em>EmClass</em></b>
38
-#       <li>\<fields\>: set of all the <b><em>EmField</em></b> of the <b><em>EmClass</em></b>\n
39
-#         for each field: \n
40
-#           \<field\>
41
-#               <ul><li>\<uid\> uid of the <b><em>EmField</em></b>
42
-#               <li>\<display_name\> field <b><em>display_name</em></b>  of the <b><em>EmField</em></b>, in different languages, as above
43
-#               <li>\<help_text\> Short explanation of the class's purpose, in different languages, as above
44
-#               <li>\<group\><b><em>uid</em></b> of the group of the field <b><em>group</em></b> of the <b><em>EmClass</em></b>
45
-#               <li>\<datahandler_name\> field <b><em>datahandler_name</em></b> of the Emfield, the name of a datahandler
46
-#               <li>\<datahandler_options\>, a list of xml items, each of them named with an option name and contains its value</ul></ul>
47
-# <li>\<groups\>: set of all the groups <b><em>EmGroup</em></b> in the model\n
48
-#    for each group:\n
49
-#       <ul><li>\<uid\> uid of the <b><em>EmField</em></b>
50
-#       <li>\<display_name\> field <b><em>display_name</em></b>  of the <b><em>EmField</em></b>, in different languages, as above
51
-#       <li>\<help_text\> Short explanation of the class's purpose, in different languages, as above
52
-#       <li>\<requires\> all uids of the <b><em>EmGroups</em></b> required by this group and which are in the fields <b><em>require</em></b>
53
-#       <li>\<components\> Set of all components of the <b><em>EmGroups</em></b>, representation of the field <b><em>__components</em></b> \n
54
-#         this item is splitted in two parts :\
55
-#           <ul><li>\<emfields\> all the emfields with, for each of them:\n
56
-#               \<emfield\> \n
57
-#                  <ul><li> \<uid\> <b><em>uid</em></b> of the <b><em>EmField</em></b></ul>
58
-#           <li>\<emclasses\> all the emclasses with, for each of them:\n
59
-#               \<emclass\> \n
60
-#                   <ul><li> \<uid\> <b><em>uid</em></b> of the <b><em>EmClass</em></b></ul></ul></ul>
61
-
62
-
63
-
64
-
26
+#   <li><b>\<fre\></b> : french
27
+#   <li><b>\<eng\></b> : english
28
+#   <li><b>\<esp\></b> : spanish
29
+#   <li><b>\<ger\></b> : german
30
+# </ul>
31
+#
32
+# @par \<classes\>
33
+# This node contains a set of all the <b><em>EmClass</em></b> classes we can find in the model, each represented by a <b>\<class\></b> child node.
34
+#
35
+# @par \<class\>
36
+# It is the representation of a single <b><em>EmClass</em></b> class. It is contained in the <b><em>\<classes\></em></b> node. It contains the following child nodes :
37
+# <ul>
38
+# <li><b>\<uid\></b> : The identifier of the class.
39
+# <li><b>\<display_name\></b> : The class' name, given by the <b><em>display_name</em></b> field of the <b><em>EmClass</em></b> class. This node contains the same language child nodes as the \<description\> node.
40
+# <li><b>\<help_text\></b> : A short description of the purpose of this class, using the same child nodes for each language, as above.
41
+# <li><b>\<abstract\></b> : Boolean node, with True or False as values, corresponding to the field <b><em>abstract</em></b> of the <b><em>EmClass</em></b> object.
42
+# <li><b>\<abstract\></b> : Boolean node, with True or False as values, corresponding to the field <b><em>pure_abstract</em></b> of the <b><em>EmClass</em></b> object.
43
+# <li><b>\<group\></b> : The unique identifier of the group stored in the <b><em>group</em></b> field of the <b><em>EmClass</em></b> object.
44
+# <li><b>\<fields\></b> : A set of all the <b><em>EmField</em></b> fields attached to an <b></em>EmClass</em></b> class. Each of them is represented by a <b>\<field\></b> child node.
45
+# </ul>
46
+#
47
+# @par \<field\>
48
+# This node is the XML representation of an <b><em>EmField</em></b> class. It contains the following child nodes :
49
+# <ul>
50
+# <li><b>\<uid\></b> : The identifier of the field.
51
+# <li><b>\<display_name\></b> : Displayed name, in different languages (same child nodes as above), corresponding to the <b><em>display_name</em></b> property of the <b><em>EmField</em></b>.
52
+# <li><b>\<help_text\></b> : Short explanation of the purpose of the field, in different languages (one child node for each translation, see above).
53
+# <li><b>\<group\></b> : <b><em>uid</em></b> of the group of the field <b><em>group</em></b> in the <b><em>EmField</em></b>
54
+# <li><b>\<datahandler_name\></b> : The name of the datahandler attached to this field (corresponds to the field <b><em>datahandler_name</em></b> of the Emfield)
55
+# <li><b>\<datahandler_options\></b> : A list of xml items, each of them named with an option name and containing its value
56
+# </ul>
57
+#
58
+# @par \<groups\>
59
+# This node contains a set of all the groups in the model (represented by <b><em>EmGroup</em></b> objects) with a <b>\<group\></b> child node for each one.
60
+#
61
+# @par \<group\>
62
+# Represents a single group. This node contains the following child nodes :
63
+# <ul>
64
+# <li><b>\<uid\></b> : unique id of the <b><em>EmField</em></b>.
65
+# <li><b>\<display_name\></b> : Corresponds to the <b><em>display_name</em></b>  property of the <b><em>EmField</em></b>, in different languages (see above)
66
+# <li><b>\help_text\></b> : Short explanation of the group's purpose, in different languages (see above)
67
+# <li><b>\<requires\></b> : All the unique identifiers of the <b><em>EmGroups</em></b> required by this group and which are in the fields <b><em>require</em></b>.
68
+# <li><b>\<components\></b> : A set of all components of the <b><em>EmGroups</em></b>, representation of the field <b><em>__components</em></b>. This node is splitted in two parts :
69
+#     <ul>
70
+#         <li><b>\<emfields\></b> : all the emfields with, for each of them:\n
71
+#               <b>\<emfield\></b> \n
72
+#                  <b>\<uid\></b> : <b><em>uid</em></b> of the <b><em>EmField</em></b>
73
+#           <li><b>\<emclasses\></b> : all the emclasses with, for each of them:\n
74
+#               <b>\<emclass\></b> \n
75
+#                  <b>\<uid\></b> : <b><em>uid</em></b> of the <b><em>EmClass</em></b>
76
+#     </ul>
77
+# </ul>
65 78
 
66 79
 
67
-##@brief Saves a model in a xml file
80
+## @brief Saves a model in a XML file
68 81
 # @param model EditorialModel : the model to save
69
-# @param filename str|None : if None display on stdout else writes in the file filename
70
-
82
+# @param kwargs dict : additional options.
83
+#                     - filename str|None : if None display on stdout else writes in the file filename
71 84
 def save(model, **kwargs):
72 85
     Em = etree.Element("editorial_model")
73 86
     em_name = etree.SubElement(Em, 'name')
@@ -100,19 +113,19 @@ def save(model, **kwargs):
100 113
         outfile.close()
101 114
     
102 115
     
103
-##@brief Writes a representation of a MlString in xml
104
-# @param etree : the xml object
105
-# @param elem : the element which represents a MlString
106
-# @param mlstr : the mlstr to write
116
+## @brief Writes a representation of a MlString in XML
117
+# @param etree Element : the XML object
118
+# @param elem Element : the element which represents a MlString
119
+# @param mlstr MlString: the mlstr to write
107 120
 def write_mlstring_xml(etree, elem, mlstr):
108 121
     for lang in mlstr.values:
109 122
         ss_mlstr = etree.SubElement(elem,lang)
110 123
         ss_mlstr.text = mlstr.get(lang)
111 124
         
112
-##@brief Writes the definition of a datahandler in xml
125
+## @brief Writes the definition of a datahandler in xml
113 126
 # @param etree : the xml object
114
-# @param elem : the element which defines a datahandler
115
-# @param dhdl_name : the name of the datahandler
127
+# @param elem Element : the element which defines a datahandler
128
+# @param dhdl_name str : the name of the datahandler
116 129
 # @param kwargs : the options of the datahandler
117 130
 def write_datahandler_xml(etree, elem, dhdl_name, **kwargs):
118 131
     dhdl = etree.SubElement(elem,'datahandler_name')
@@ -138,15 +151,15 @@ def write_datahandler_xml(etree, elem, dhdl_name, **kwargs):
138 151
                     opt_val = str(argu)
139 152
         arg.text = opt_val
140 153
         
141
-##@brief Writes a representation in xml of a EmField
154
+## @brief Writes a representation in xml of a EmField
142 155
 # @param etree : the xml object
143
-# @param elem : the element for the EmField
144
-# @param uid : the uid of the EmField
145
-# @param name : the name of the field
146
-# @param help_text : explanations of the EmField
147
-# @param group_uid : the uid of a group, can be None
148
-# @datahandler_name
149
-# @**kwargs : options of the datahandler
156
+# @param elem Element: the element for the EmField
157
+# @param uid str : the uid of the EmField
158
+# @param name str : the name of the field
159
+# @param help_text MlString: explanations of the EmField
160
+# @param group str|None: the uid of a group, can be None
161
+# @param datahandler_name str: Name of the datahandler attached to the field
162
+# @param **kwargs dict : options of the datahandler
150 163
 def write_emfield_xml(etree, elem, uid, name, help_text, group, datahandler_name, **kwargs):
151 164
     emfield = etree.SubElement(elem,'field')
152 165
     emfield_uid = etree.SubElement(emfield, 'uid')
@@ -169,10 +182,12 @@ def write_emfield_xml(etree, elem, uid, name, help_text, group, datahandler_name
169 182
 
170 183
 ##@brief Writes a representation of a EmGroup in xml
171 184
 # @param etree : the xml object
172
-# @param elem : the element for the EmGroup
173
-# @param name  : the name of the group
174
-# @param help_text : explanations of the EmGroup
175
-# @param requires : a list of the group's uids whose this group depends
185
+# @param elem Element : the element for the EmGroup
186
+# @param uid str : the uid of the EmGroup
187
+# @param name str : the name of the group
188
+# @param help_text MlString : explanations of the EmGroup
189
+# @param requires list : a list of the group's uids whose this group depends
190
+# @param components list : a list of the EmComponent objects contained in the group
176 191
 def write_emgroup_xml(etree, elem, uid, name, help_text, requires, components):
177 192
     emgroup = etree.SubElement(elem, 'group')
178 193
     emgroup_uid = etree.SubElement(emgroup, 'uid')
@@ -204,15 +219,16 @@ def write_emgroup_xml(etree, elem, uid, name, help_text, requires, components):
204 219
             em_group_comp_cls_ins = etree.SubElement(emgroup_comp_cls, 'emclass')
205 220
             em_group_comp_cls_ins.text = component.uid
206 221
 
207
-##@brief Writes a representation of a EmClass in xml
208
-# @param etree : the xml object
209
-# @param elem : the element for the EmClass
210
-# @param name  : the name of the group
211
-# @param help_text : explanations of the EmClass
212
-# @param fields : a dict
213
-# @param parents : a list of EmClass uids
214
-# @param abstract : a boolean
215
-# @param pure_abstract : a boolean
222
+## @brief Writes a representation of a EmClass in XML
223
+# @param etree : the XML object
224
+# @param elem Element : the element for the EmClass
225
+# @param uid str : the unique identifier of the EmClass
226
+# @param name str : the name of the group
227
+# @param help_text MlString : explanations of the EmClass
228
+# @param fields dict : a dict representing all the fields of the class
229
+# @param parents list : a list of the EmClass uids of this class' parents
230
+# @param abstract bool : a boolean
231
+# @param pure_abstract bool : a boolean
216 232
 def write_emclass_xml(etree, elem, uid, name, help_text, group, fields, parents, abstract = False, pure_abstract = False):
217 233
     emclass = etree.SubElement(elem, 'class')
218 234
     emclass_uid  = etree.SubElement(emclass, 'uid')
@@ -244,11 +260,10 @@ def write_emclass_xml(etree, elem, uid, name, help_text, group, fields, parents,
244 260
     emclass_parents = etree.SubElement(emclass, 'parents')
245 261
     emclass_parents.text = ",".join(parents_list)
246 262
 
247
-##@brief Loads a model from a xml file
248
-# @param model EditorialModel : the model to load
263
+## @brief Loads a model from a XML file
264
+# @param filename str : The file from which the editorial model will be loaded
249 265
 # @return a new EditorialModel object
250 266
 def load(filename):
251
-
252 267
     Em = etree.parse(filename)
253 268
     emodel = Em.getroot()
254 269
     name = emodel.find('name')
@@ -270,9 +285,10 @@ def load(filename):
270 285
             grp = model.add_group(grp)
271 286
     return model
272 287
 
273
-##@brief Creates a EmClass from a xml description
274
-# @param elem : the element which represents the EmClass
275
-# @param model  : the model which will contain the new class
288
+
289
+## @brief Creates a EmClass from a xml description
290
+# @param model EditorialModel : the model which will contain the new class
291
+# @param elem Element: the element which represents the EmClass
276 292
 # @return a new EmClass object
277 293
 def load_class_xml(model, elem):
278 294
     uid = elem.find('uid').text
@@ -332,11 +348,11 @@ def load_class_xml(model, elem):
332 348
             
333 349
     return emclass
334 350
     
335
-##@brief Creates a EmField from a xml description
336
-#@param elem : the element which represents the EmField
337
-#@param model  : the model which will contain the new field
338
-#@param emclass EmClass : the EmClass of the field
339
-#@return a new EmField object
351
+## @brief Creates a EmField from a XML description
352
+# @param model EditorialModel: the model which will contain the new field
353
+# @param elem Element : the element which represents the EmField
354
+# @param emclass EmClass : the EmClass of the field
355
+# @return a new EmField object
340 356
 def load_field_xml(model, elem, emclass):
341 357
     uid = elem.find('uid').text
342 358
     if elem.find('display_name').text is None:
@@ -369,10 +385,11 @@ def load_field_xml(model, elem, emclass):
369 385
     
370 386
     return emfield
371 387
 
372
-##@brief Returns datahandler options from a xml description
373
-# @param elem : the element which represents the datahandler
374
-# @param model  : the model which will contain the new field
375
-# @return datahandler options
388
+
389
+## @brief Returns datahandler options from a XML description
390
+# @param elem Element : the element which represents the datahandler
391
+# @param model EditorialModel : the model which will contain the new field
392
+# @return dict
376 393
 def load_dhdl_options_xml(model, elem):
377 394
     dhdl_options=dict()
378 395
     for opt in elem:
@@ -396,10 +413,10 @@ def load_dhdl_options_xml(model, elem):
396 413
     return dhdl_options
397 414
              
398 415
     
399
-##@brief Creates a EmGroup from a xml description
400
-# @param elem : the element which represents the EmGroup
401
-# @param model  : the model which will contain the new group
402
-# @return a new EmGroup object
416
+## @brief Creates a EmGroup from a XML description
417
+# @param model EditorialModel : the model which will contain the new group
418
+# @param elem Element : the element which represents the EmGroup
419
+# @return EmGroup
403 420
 def load_group_xml(model, elem):
404 421
     uid = elem.find('uid')
405 422
     
@@ -450,10 +467,9 @@ def load_group_xml(model, elem):
450 467
     group.add_components(comp)     
451 468
     return group
452 469
 
453
-##@brief Constructs a MlString from a xml description
454
-# @param elem : the element which represents the MlString
455
-# @param model  : the model which will contain the new group
456
-# @return a new MlString object
470
+## @brief Constructs a MlString from a XML description
471
+# @param elem Element : the element which represents the MlString
472
+# @return MlString
457 473
 def load_mlstring_xml(elem):
458 474
     mlstr = dict()
459 475
     for lang in elem:

Loading…
Cancel
Save