cuemsutils 0.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,299 @@
1
+ # DEV: Move to cuems-utils
2
+ import xml.etree.ElementTree as ET
3
+ from enum import Enum
4
+
5
+ from .log import logger
6
+ from .DictParser import GenericDict
7
+
8
+
9
+ PARSER_SUFFIX = 'XmlBuilder'
10
+ GENERIC_BUILDER = 'GenericCueXmlBuilder'
11
+
12
+ SCHEMA_INSTANCE_URI = 'http://www.w3.org/2001/XMLSchema-instance'
13
+ VALUE_TYPES = (str, bool, int, float, Enum)
14
+
15
+ class XmlBuilder():
16
+ def __init__(self, _object, namespace, xsd_path, xml_tree = None, xml_root_tag='CuemsProject'):
17
+ self._object = _object
18
+ self.xml_tree = xml_tree
19
+ self.xml_root_tag = xml_root_tag
20
+ self.class_name = type(_object).__name__
21
+ self.xsd_path = xsd_path
22
+ self.namespace = namespace
23
+ ET.register_namespace(next(iter(self.namespace)), next(iter(self.namespace.values())))
24
+
25
+ def get_builder_class(self, _object):
26
+ object_class_name = type(_object).__name__
27
+ builder_class_name = object_class_name + PARSER_SUFFIX
28
+ try:
29
+ builder_class = globals()[builder_class_name]
30
+ except KeyError as err:
31
+ #logger.debug("Could not find class {0}, reverting to generic builder class".format(err))
32
+ builder_class = globals()[GENERIC_BUILDER]
33
+ return builder_class
34
+
35
+ def build(self):
36
+
37
+ #xml_root = ET.Element(f'{{{next(iter(self.namespace.values()))}}}CuemsProject')
38
+ xml_root = ET.Element(f'{{{next(iter(self.namespace.values()))}}}{self.xml_root_tag}')
39
+ xml_root.attrib= {f'{{{SCHEMA_INSTANCE_URI}}}schemaLocation': next(iter(self.namespace.values())) + " " + self.xsd_path}
40
+ builder_class = self.get_builder_class(self._object)
41
+ self.xml_tree = builder_class(self._object, xml_tree = xml_root).build()
42
+
43
+ self.xml_tree = ET.ElementTree(self.xml_tree)
44
+
45
+ return self.xml_tree
46
+
47
+ class CuemsScriptXmlBuilder(XmlBuilder):
48
+ def __init__(self, _object, xml_tree):
49
+ self._object = _object
50
+ self.xml_tree = xml_tree
51
+ self.class_name = type(_object).__name__
52
+
53
+ def build(self):
54
+ cue_element = ET.SubElement(self.xml_tree, self.class_name)
55
+
56
+
57
+ for key, value in self._object.items():
58
+
59
+ if isinstance(value, VALUE_TYPES):
60
+ cue_subelement = ET.SubElement(cue_element, str(key))
61
+ cue_subelement.text = str(value)
62
+ elif isinstance(value, (type(None))):
63
+ cue_subelement = ET.SubElement(cue_element, str(key))
64
+ else:
65
+ cue_subelement = cue_element
66
+ builder_class = self.get_builder_class(value)
67
+ sub_object_element = builder_class(value, xml_tree = cue_subelement).build()
68
+ return self.xml_tree
69
+
70
+ class CueListXmlBuilder(CuemsScriptXmlBuilder):
71
+
72
+
73
+ def build(self):
74
+ cuelist_element = ET.SubElement(self.xml_tree, self.class_name)
75
+ for key, value in self._object.items():
76
+ cue_subelement = ET.SubElement(cuelist_element, str(key))
77
+ if isinstance(value, VALUE_TYPES):
78
+ cue_subelement.text = str(value)
79
+ elif isinstance(value, (type(None))):
80
+ pass
81
+ elif isinstance(value, list):
82
+ for cuelist_item in value:
83
+ builder_class = self.get_builder_class(cuelist_item)
84
+ sub_object_element = builder_class(cuelist_item, xml_tree = cue_subelement).build()
85
+ else:
86
+ builder_class = self.get_builder_class(value)
87
+ sub_object_element = builder_class(value, xml_tree = cue_subelement).build()
88
+
89
+
90
+ return self.xml_tree
91
+
92
+
93
+ class GenericCueXmlBuilder(CuemsScriptXmlBuilder):
94
+
95
+ def build(self):
96
+ cue_element = ET.SubElement(self.xml_tree, self.class_name)
97
+ for key, value in self._object.items():
98
+ if isinstance(value, VALUE_TYPES):
99
+ cue_subelement = ET.SubElement(cue_element, str(key))
100
+ cue_subelement.text = str(value)
101
+ elif isinstance(value, (type(None))):
102
+ cue_subelement = ET.SubElement(cue_element, str(key))
103
+ elif isinstance(value, list):
104
+ cue_subelement = ET.SubElement(cue_element, str(key))
105
+ for list_item in value:
106
+ builder_class = self.get_builder_class(list_item)
107
+ sub_object_element = builder_class(list_item, xml_tree = cue_subelement).build()
108
+ elif isinstance(value, GenericDict):
109
+ cue_subelement = ET.SubElement(cue_element, str(key))
110
+ for sub_key, sub_value in value.items():
111
+ sub_dict_element = ET.SubElement(cue_subelement, str(sub_key))
112
+ sub_dict_element.text = str(sub_value)
113
+ else:
114
+ cue_subelement = ET.SubElement(cue_element, str(key))
115
+ builder_class = self.get_builder_class(value)
116
+ sub_object_element = builder_class(value, xml_tree = cue_subelement).build()
117
+
118
+ class DmxSceneXmlBuilder(CuemsScriptXmlBuilder):
119
+
120
+ def build(self):
121
+ cue_element = ET.SubElement(self.xml_tree, self.class_name)
122
+ universe_list = list(self._object.items())
123
+ for universe in universe_list:
124
+ builder_class = self.get_builder_class(universe[1])
125
+ sub_object_element = builder_class(universe, xml_tree = cue_element).build()
126
+
127
+
128
+ class DmxUniverseXmlBuilder(CuemsScriptXmlBuilder):
129
+
130
+ def build(self):
131
+ cue_element = ET.SubElement(self.xml_tree, type(self._object[1]).__name__, id=str(self._object[0]))
132
+ channel_list = list(self._object[1].items())
133
+ for channel in channel_list:
134
+ builder_class = self.get_builder_class(channel[1])
135
+ sub_object_element = builder_class(channel, xml_tree = cue_element).build()
136
+
137
+ class DmxChannelXmlBuilder(CuemsScriptXmlBuilder):
138
+
139
+ def build(self):
140
+ cue_element = ET.SubElement(self.xml_tree, type(self._object[1]).__name__, id=str(self._object[0]))
141
+ cue_element.text = str(self._object[1])
142
+
143
+
144
+
145
+ class GenericSimpleSubObjectXmlBuilder(CuemsScriptXmlBuilder):
146
+
147
+ def build(self):
148
+ cue_element = ET.SubElement(self.xml_tree, self.class_name)
149
+ cue_element.text = str(self._object)
150
+
151
+ class GenericComplexSubObjectXmlBuilder(CuemsScriptXmlBuilder):
152
+
153
+ def build(self):
154
+ if isinstance(self._object, dict):
155
+ for key, value in self._object.items():
156
+ if isinstance(value, VALUE_TYPES):
157
+ sub_dict_element = ET.SubElement(self.xml_tree, str(key))
158
+ sub_dict_element.text = str(value)
159
+ elif isinstance(value, (type(None))):
160
+ sub_dict_element = ET.SubElement(self.xml_tree, str(key))
161
+ elif isinstance(value, dict):
162
+ sub_dict_element = ET.SubElement(self.xml_tree, str(key))
163
+ self.recurser(value, sub_dict_element)
164
+ elif isinstance(value, list):
165
+ sub_dict_element = ET.SubElement(self.xml_tree, str(key))
166
+ self.recurser(value, sub_dict_element)
167
+
168
+ def recurser(self, group, xml_tree):
169
+ if isinstance(group, dict):
170
+ for key, value in group.items():
171
+ if isinstance(value, VALUE_TYPES):
172
+ cue_subelement = ET.SubElement(xml_tree, key)
173
+ cue_subelement.text = str(value)
174
+ elif isinstance(value, (type(None))):
175
+ cue_subelement = ET.SubElement(xml_tree, key)
176
+ elif isinstance(value, dict):
177
+ cue_subelement = ET.SubElement(xml_tree, key)
178
+ self.recurser(value, cue_subelement)
179
+ elif isinstance(group, list):
180
+ for item in group:
181
+ if isinstance(item, dict):
182
+ self.recurser(item, xml_tree)
183
+
184
+ class CTimecodeXmlBuilder(GenericSimpleSubObjectXmlBuilder):
185
+ pass
186
+
187
+ class MediaXmlBuilder(GenericComplexSubObjectXmlBuilder):
188
+ def build(self):
189
+
190
+
191
+ if isinstance(self._object, dict):
192
+
193
+
194
+ for key, value in self._object.items():
195
+ if isinstance(value, VALUE_TYPES):
196
+ cue_subelement = ET.SubElement(self.xml_tree, key)
197
+ cue_subelement.text = str(value)
198
+ elif isinstance(value, (type(None))):
199
+ cue_subelement = ET.SubElement(self.xml_tree, key)
200
+ elif isinstance(value, dict):
201
+ cue_subelement = ET.SubElement(self.xml_tree, key)
202
+ self.recurser(value, cue_subelement)
203
+ elif isinstance(value, list):
204
+ cue_subelement = ET.SubElement(self.xml_tree, key)
205
+ for list_item in value:
206
+ builder_class = self.get_builder_class(list_item)
207
+ sub_object_element = builder_class(list_item, xml_tree =cue_subelement).build()
208
+
209
+
210
+
211
+
212
+
213
+ class UI_propertiesXmlBuilder(GenericComplexSubObjectXmlBuilder):
214
+ pass
215
+
216
+ class OutputsXmlBuilder(GenericComplexSubObjectXmlBuilder):
217
+ def build(self):
218
+ if isinstance(self._object, dict):
219
+ for key, value in self._object.items():
220
+ if isinstance(value, VALUE_TYPES):
221
+ sub_dict_element = ET.SubElement(self.xml_tree, str(key))
222
+ sub_dict_element.text = str(value)
223
+ elif isinstance(value, (type(None))):
224
+ sub_dict_element = ET.SubElement(self.xml_tree, str(key))
225
+ elif isinstance(value, dict):
226
+ sub_dict_element = ET.SubElement(self.xml_tree, str(key))
227
+ self.recurser(value, sub_dict_element)
228
+ elif isinstance(value, list):
229
+ sub_dict_element = ET.SubElement(self.xml_tree, str(key))
230
+ for item in value:
231
+ self.recurser(item, sub_dict_element)
232
+
233
+ return self.xml_tree
234
+
235
+ def recurser(self, group, xml_tree):
236
+ if isinstance(group, dict):
237
+ for key, value in group.items():
238
+ if isinstance(value, VALUE_TYPES):
239
+ output_subelement = ET.SubElement(xml_tree, key)
240
+ output_subelement.text = str(value)
241
+ elif isinstance(value, (type(None))):
242
+ output_subelement = ET.SubElement(xml_tree, key)
243
+ elif isinstance(value, dict):
244
+ output_subelement = ET.SubElement(xml_tree, key)
245
+ self.recurser(value, output_subelement)
246
+ elif isinstance(value, list):
247
+ for item in value:
248
+ output_subelement = ET.SubElement(xml_tree, key)
249
+ self.recurser(item, output_subelement)
250
+ elif isinstance(group, list):
251
+ for item in group:
252
+ if isinstance(value, VALUE_TYPES):
253
+ xml_tree.text = str(item)
254
+ if isinstance(item, dict):
255
+ self.recurser(item, xml_tree)
256
+ elif isinstance(group, VALUE_TYPES):
257
+ xml_tree.text = str(group)
258
+
259
+ class CueOutputsXmlBuilder(GenericComplexSubObjectXmlBuilder):
260
+
261
+ def build(self):
262
+ cue_element = ET.SubElement(self.xml_tree, self.class_name)
263
+
264
+ if isinstance(self._object, dict):
265
+
266
+
267
+ for key, value in self._object.items():
268
+ if isinstance(value, VALUE_TYPES):
269
+ cue_subelement = ET.SubElement(cue_element, key)
270
+ cue_subelement.text = str(value)
271
+ elif isinstance(value, (type(None))):
272
+ cue_subelement = ET.SubElement(cue_element, key)
273
+ elif isinstance(value, dict):
274
+ cue_subelement = ET.SubElement(cue_element, key)
275
+ self.recurser(value, cue_subelement)
276
+ elif isinstance(value, list):
277
+ cue_subelement = ET.SubElement(cue_element, key)
278
+ self.recurser(value, cue_subelement)
279
+
280
+ else:
281
+ cue_element.text = str(self._object)
282
+
283
+
284
+ class AudioCueOutputXmlBuilder(CueOutputsXmlBuilder):
285
+ pass
286
+
287
+ class VideoCueOutputXmlBuilder(CueOutputsXmlBuilder):
288
+ pass
289
+
290
+ class DmxCueOutputXmlBuilder(CueOutputsXmlBuilder):
291
+ pass
292
+
293
+
294
+ class CuemsNodeDictXmlBuilder(CuemsScriptXmlBuilder):
295
+ pass
296
+
297
+
298
+ class NoneTypeXmlBuilder(GenericSimpleSubObjectXmlBuilder): # TODO: clean, not need anymore?
299
+ pass
@@ -0,0 +1,84 @@
1
+ # DEV: Move to cuems-utils
2
+ """ For the moment it works with pip3 install xmlschema==1.2.2
3
+ """
4
+
5
+ import os
6
+
7
+ from ..log import logger
8
+ from .CMLCuemsConverter import CMLCuemsConverter
9
+ from .DictParser import CuemsParser
10
+ from .XmlBuilder import XmlBuilder
11
+
12
+ class CuemsXml():
13
+ def __init__(self, schema, xmlfile=None, namespace={'cms':'http://stagelab.net/cuems'}, xml_root_tag='CuemsProject'):
14
+ self.converter = CMLCuemsConverter
15
+ self.schema_object = None
16
+ self._xmlfile = None
17
+ self._schema = None
18
+ self.schema = schema
19
+ self.xmlfile = xmlfile
20
+ self.xmldata = None
21
+ self.namespace = namespace
22
+ self.xml_root_tag = xml_root_tag
23
+
24
+
25
+ @property
26
+ def schema(self):
27
+ return self._schema
28
+
29
+
30
+ @schema.setter
31
+ def schema(self, path):
32
+ if path is not None:
33
+ if os.path.isfile(path):
34
+ self._schema = path
35
+ self.schema_object = xmlschema.XMLSchema11(self._schema, converter=self.converter)
36
+ else:
37
+ raise FileNotFoundError("schema file not found")
38
+
39
+
40
+ @property
41
+ def xmlfile(self):
42
+ return self._xmlfile
43
+
44
+ @xmlfile.setter
45
+ def xmlfile(self, path):
46
+ self._xmlfile = path
47
+
48
+ def validate(self):
49
+ return self.schema_object.validate(self.xmlfile)
50
+
51
+ class XmlWriter(CuemsXml):
52
+
53
+ def write(self, xml_data, ):
54
+ self.schema_object.validate(xml_data)
55
+ xml_data.write(self.xmlfile, encoding="utf-8", xml_declaration=True)
56
+
57
+ def write_from_dict(self, project_dict):
58
+ project_object = CuemsParser(project_dict).parse()
59
+ xml_data = XmlBuilder(project_object, namespace=self.namespace, xsd_path=self.schema, xml_root_tag=self.xml_root_tag).build()
60
+ self.write(xml_data)
61
+
62
+ def write_from_object(self, project_object):
63
+ xml_data = XmlBuilder(project_object, namespace=self.namespace, xsd_path=self.schema, xml_root_tag=self.xml_root_tag).build()
64
+ self.write(xml_data)
65
+
66
+
67
+ class XmlReader(CuemsXml):
68
+
69
+
70
+ def read(self):
71
+ xml_dict = self.schema_object.to_dict(self.xmlfile, validation='strict', strip_namespaces=False)
72
+ # remove namespace info from xml
73
+ try:
74
+ del xml_dict['xmlns:cms']
75
+ del xml_dict['xmlns:xsi']
76
+ del xml_dict['xsi:schemaLocation']
77
+ except KeyError:
78
+ logger.warning('Error triying to remove namespace info on read')
79
+
80
+ return xml_dict
81
+
82
+ def read_to_objects(self):
83
+ xml_dict = self.read()
84
+ return CuemsParser(xml_dict).parse()
File without changes
@@ -0,0 +1,47 @@
1
+ Metadata-Version: 2.4
2
+ Name: cuemsutils
3
+ Version: 0.0.1
4
+ Summary: Reusable classes and methods for CueMS system
5
+ Project-URL: Documentation, https://github.com/stagesoft/cuemsutils#readme
6
+ Project-URL: Issues, https://github.com/stagesoft/cuemsutils/issues
7
+ Project-URL: Source, https://github.com/stagesoft/cuemsutils
8
+ Author-email: Adrià Masip <adria.back@gmail.com>, Ion Reguera <ion@stagelab.com>
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Programming Language :: Python
13
+ Classifier: Programming Language :: Python :: 3.8
14
+ Classifier: Programming Language :: Python :: 3.9
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: Implementation :: CPython
19
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
20
+ Requires-Python: >=3.8
21
+ Provides-Extra: test
22
+ Requires-Dist: pytest; extra == 'test'
23
+ Requires-Dist: pytest-cov; extra == 'test'
24
+ Description-Content-Type: text/markdown
25
+
26
+ # cuems-utils
27
+ Reusable classes and methods for CueMS system
28
+
29
+ [![PyPI - Version](https://img.shields.io/pypi/v/cuems-utils.svg)](https://pypi.org/project/cuems-utils)
30
+ [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/cuems-utils.svg)](https://pypi.org/project/cuems-utils)
31
+
32
+ -----
33
+
34
+ ## Table of Contents
35
+
36
+ - [Installation](#installation)
37
+ - [License](#license)
38
+
39
+ ## Installation
40
+
41
+ ```console
42
+ pip install cuems-utils
43
+ ```
44
+
45
+ ## License
46
+
47
+ `cuems-utils` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.
@@ -0,0 +1,26 @@
1
+ cuemsutils/CTimecode.py,sha256=Ea9eePqljup5AyEgpl4MEcLMJ_54CjJQniW85ulHAQU,5835
2
+ cuemsutils/__init__.py,sha256=ogP__hgeGiNsk04sZO9r2xALhMYJTDMJj9tJmF4UDYs,132
3
+ cuemsutils/log.py,sha256=1iTMEPVg3A11iNSJE-M7aslRhNA2UVRN1nycMsdjo8s,2348
4
+ cuemsutils/cues/ActionCue.py,sha256=MVYsh77_DWRk_9q5B_SUB7HICtNNi1N-JOJQC4KM3UY,3845
5
+ cuemsutils/cues/AudioCue.py,sha256=-9iPjztzEN25ZvDG2FTYCFAOv0vFHdB0mR96a6-UMXo,10279
6
+ cuemsutils/cues/Cue.py,sha256=-9sHQgUz2RGGSmdM-9MkGljrTv0U8vYlhV0uF1_OjKA,6629
7
+ cuemsutils/cues/CueList.py,sha256=PoeLnOqsujMxUmmRmKZtjHkDuxgVXNEH-wLO1pioVhs,4663
8
+ cuemsutils/cues/CueOutput.py,sha256=IrFFsYSolc5UxHDX5TEC8Kqs-e8np77iGRYoNvhb_zI,254
9
+ cuemsutils/cues/CuemsScript.py,sha256=JKq1_wWDaqW277k4TR8F1giwn02OwiK3d6Ytqwe_Y9M,3743
10
+ cuemsutils/cues/DmxCue.py,sha256=SSGrpLV2wVrmtUKeEYvFk5q4_Mse56098B3c3ce_ono,9758
11
+ cuemsutils/cues/VideoCue.py,sha256=H7Qt90qCSsQyxCAYMr8bBJBoNY3loDpmPlT40yvMjgs,11057
12
+ cuemsutils/cues/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
+ cuemsutils/schemas/outputs.xsd,sha256=c1VYTMz3ypxdHDJq0X6SeZ1SBY4NZMC02yK3-sbE_s0,884
14
+ cuemsutils/schemas/project_mappings.xsd,sha256=cPeudrez29lQye-XJ4r3nXSP_Al8RrTy9wjENwEXtO8,3566
15
+ cuemsutils/schemas/project_settings.xsd,sha256=UCao5tY9YaSXfT_KEBY3owsOeAgLWZwywZMuZoqdvq4,915
16
+ cuemsutils/schemas/script.xsd,sha256=0H1TQr_tmPmAsadR00Xq-zczo_U7K4FNoG02Zqw1wL4,15089
17
+ cuemsutils/schemas/settings.xsd,sha256=6B9CZ8wiRbAn5Vuw4OdFTKehxJtNGy0SUJkRmuzM9Ys,4786
18
+ cuemsutils/xml/CMLCuemsConverter.py,sha256=Pr1Zvqd_aAs7MybWNimNyNM_MFVGUJrMncs-N3FBrYM,8525
19
+ cuemsutils/xml/DictParser.py,sha256=uk0mp_pDGy3Ug4Htct0_chMO1wH6zZZ6cQ8efX4H25U,9860
20
+ cuemsutils/xml/XmlBuilder.py,sha256=S_6uJHJm_5lviGkB47sbP9s7ubJL_HEGh5ixX9HAyLc,12495
21
+ cuemsutils/xml/XmlReaderWriter.py,sha256=Z2lhEKik4CpdVnZ0h09-LaiVVLNWCGk0yy7GQ28rb7g,2592
22
+ cuemsutils/xml/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
23
+ cuemsutils-0.0.1.dist-info/METADATA,sha256=QLs2FV2p44xJvzUHw4GIkULoQxxvv_hBHtgkHESAqEA,1632
24
+ cuemsutils-0.0.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
25
+ cuemsutils-0.0.1.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
26
+ cuemsutils-0.0.1.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.27.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any