rts_profile.py
Go to the documentation of this file.
1 # -*- Python -*-
2 # -*- coding: utf-8 -*-
3 
4 '''rtsprofile
5 
6 Copyright (C) 2009-2010
7  Geoffrey Biggs
8  RT-Synthesis Research Group
9  Intelligent Systems Research Institute,
10  National Institute of Advanced Industrial Science and Technology (AIST),
11  Japan
12  All rights reserved.
13 Licensed under the Eclipse Public License -v 1.0 (EPL)
14 http://www.opensource.org/licenses/eclipse-1.0.txt
15 
16 File: rtsystem.py
17 
18 Object representing an RT system. The object constructs itself using an XML
19 parser and an XML specification meeting the RtsProfile schema.
20 
21 '''
22 
23 __version__ = '$Revision: $'
24 # $Source$
25 
26 
27 from datetime import datetime, MINYEAR
28 import xml.dom
29 import xml.dom.minidom
30 import yaml
31 
32 from rtsprofile import RTS_NS, RTS_NS_S, RTS_EXT_NS, RTS_EXT_NS_S, \
33  RTS_EXT_NS_YAML
34 from rtsprofile.component import Component
35 from rtsprofile.component_group import ComponentGroup
36 from rtsprofile.exceptions import MultipleSourcesError, \
37  InvalidRtsProfileNodeError, RtsProfileError
38 from rtsprofile.message_sending import StartUp, ShutDown, Activation, \
39  Deactivation, Resetting, Initialize, \
40  Finalize
41 from rtsprofile.port_connectors import DataPortConnector, ServicePortConnector
42 from rtsprofile.utils import date_to_dict, get_direct_child_elements_xml, \
43  indent_string, parse_properties_xml, \
44  properties_to_xml, validate_attribute
45 
46 
47 ##############################################################################
48 ## RtsProfile object
49 
50 class RtsProfile:
51  def __init__(self, xml_spec=None, yaml_spec=None):
52  '''Constructor.
53 
54  Pass in an RTSProfile specification either in a string or a file
55  object, and the RtsProfile will be loaded from that.
56 
57  If no specification is provided, the RtsProfile will be constructed
58  from the default values. Use the properties to set the values you need.
59 
60  @param xml_spec A string or open file object containing the XML
61  specification of the RTS Profile. If present, the other arguments must
62  be None.
63 
64  @param yaml_spec A string or open file object containing the YAML
65  specification of the RTS Profile. If present, the other arguments must
66  be None.
67 
68  '''
69  if xml_spec:
70  if yaml_spec:
71  raise MultipleSourcesError('XML and YAML specifications both \
72 given.')
73  self.parse_from_xml(xml_spec)
74  elif yaml_spec:
75  if xml_spec:
76  raise MultipleSourcesError('XML and YAML specifications both \
77 given.')
78  self.parse_from_yaml(yaml_spec)
79  else:
80  self._reset()
81 
82  def __str__(self):
83  result = 'ID: {0}\nAbstract: {1}\nCreation date: {2}\n\
84 Update date: {3}\nVersion: {4}\n'.format(self.id, self.abstract,
85  self.creation_date, self.update_date,
86  self.version)
87  if self.components:
88  result += 'Components:\n'
89  for c in self.components:
90  result += '{0}\n'.format(indent_string(str(c)))
91  if self.groups:
92  result += 'Groups:\n'
93  for g in self.groups:
94  result += '{0}\n'.format(indent_string(str(g)))
95  if self.data_port_connectors:
96  result += 'Data port connectors:\n'
97  for c in self.data_port_connectors:
98  result += '{0}\n'.format(indent_string(str(c)))
100  result += 'Service port connectors:\n'
101  for c in self.service_port_connectors:
102  result += '{0}\n'.format(indent_string(str(c)))
103  if self.startup:
104  result += 'Startup: {0}\n'.format(self.startup)
105  if self.shutdown:
106  result += 'Shutdown: {0}\n'.format(self.shutdown)
107  if self.activation:
108  result += 'Activation: {0}\n'.format(self.activation)
109  if self.deactivation:
110  result += 'Deactivation: {0}\n'.format(self.deactivation)
111  if self.resetting:
112  result += 'Resetting: {0}\n'.format(self.resetting)
113  if self.initializing:
114  result += 'Initializing: {0}\n'.format(self.initializing)
115  if self.finalizing:
116  result += 'Finalizing: {0}\n'.format(self.finalizing)
117  if self.comment:
118  result += 'Comment: {0}\n'.format(self.comment)
119  if self.version_up_log:
120  result += 'Version up logs:\n'
121  for vl in self.version_up_log:
122  result += '{0}\n'.format(indent_string(vl))
123  if self.properties:
124  result += 'Properties:\n'
125  for p in self.properties:
126  result += ' {0}: {1}\n'.format(p, self.properties[p])
127  return result[:-1] # Lop off the last new line
128 
129  ###########################################################################
130  # Properties
131 
132  @property
133  def id(self):
134  '''ID used to distinguish the RT system.
135 
136  Typically in the format '[vendor name].[system name].[version]'.
137 
138  '''
139  return self._id
140 
141  @id.setter
142  def id(self, id):
143  print 'setting id to ', id
144  validate_attribute(id, 'rts_profile.id',
145  expected_type=[str, unicode], required=True)
146  self._id = id
147 
148  @property
149  def abstract(self):
150  '''Description of this RT system.
151 
152  May be empty.
153 
154  '''
155  return self._abstract
156 
157  @abstract.setter
158  def abstract(self, abstract):
159  validate_attribute(abstract, 'rts_profile.abstract',
160  expected_type=[str, unicode], required=True)
161  self._abstract = abstract
162 
163  @property
164  def creation_date(self):
165  '''The date this RT system was first created.
166 
167  Usually set automatically by the tool that created the system.
168 
169  '''
170  return self._creation_date
171 
172  @creation_date.setter
173  def creation_date(self, creation_date):
174  validate_attribute(creation_date, 'rts_profile.creationDate',
175  expected_type=[str, unicode], required=True)
176  self._creation_date = creation_date
177 
178  @property
179  def update_date(self):
180  '''The date this RT system was most recently updated.
181 
182  Usually set automatically by the tool that created the system.
183 
184  '''
185  return self._update_date
186 
187  @update_date.setter
188  def update_date(self, update_date):
189  validate_attribute(update_date, 'rts_profile.updateDate',
190  expected_type=[str, unicode], required=True)
191  self._update_date = update_date
192 
193  @property
194  def version(self):
195  '''Version of the RTSProfile specification this is in.'''
196  return self._version
197 
198  @version.setter
199  def version(self, version):
200  validate_attribute(version, 'rts_profile.version',
201  expected_type=[str, unicode], required=True)
202  self._version = version
203 
204  @property
205  def components(self):
206  '''Information about the components that make up the RT system.
207 
208  May be an empty list if there are no components. Members are of type
209  @ref Component.
210 
211  '''
212  return self._components
213 
214  @components.setter
215  def components(self, components):
216  validate_attribute(components, 'rts_profile.Components',
217  expected_type=list, required=True)
218  self._components = components
219 
220  @property
221  def groups(self):
222  '''Information about the component groups in the RT system.
223 
224  May be an empty list if there are no groups. Members are of type @ref
225  ComponentGroup.
226 
227  '''
228  return self._groups
229 
230  @groups.setter
231  def groups(self, groups):
232  validate_attribute(groups, 'rts_profile.Groups',
233  expected_type=list, required=True)
234  self._groups = groups
235 
236  @property
238  '''Connections between data ports in the RT system.
239 
240  Members are of type @ref DataPortConnector.
241 
242  '''
243  return self._data_port_connectors
244 
245  @data_port_connectors.setter
246  def data_port_connectors(self, data_port_connectors):
247  validate_attribute(data_port_connectors,
248  'rts_profile.DataPortConnectors',
249  expected_type=list, required=True)
250  self._data_port_connectors = data_port_connectors
251 
252  @property
254  '''Connections between service ports in the RT system.
255 
256  Members are of type @ref ServicePortConnector.
257 
258  '''
259  return self._service_port_connectors
260 
261  @service_port_connectors.setter
262  def service_port_connectors(self, service_port_connectors):
263  validate_attribute(service_port_connectors,
264  'rts_profile.ServicePortConnectors',
265  expected_type=list, required=True)
266  self._service_port_connectors = service_port_connectors
267 
268  @property
269  def startup(self):
270  '''Ordering and conditions for when the RT system is started.'''
271  return self._startup
272 
273  @startup.setter
274  def startup(self, startup):
275  validate_attribute(startup, 'rts_profile.StartUp',
276  expected_type=StartUp, required=False)
277  self._startup = startup
278 
279  @property
280  def shutdown(self):
281  '''Ordering and conditions for when the RT system is shut down.'''
282  return self._shutdown
283 
284  @shutdown.setter
285  def shutdown(self, shutdown):
286  validate_attribute(shutdown, 'rts_profile.ShutDown',
287  expected_type=ShutDown, required=False)
288  self._shutdown = shutdown
289 
290  @property
291  def activation(self):
292  '''Ordering and conditions for when the RT system is activated.'''
293  return self._activation
294 
295  @activation.setter
296  def activation(self, activation):
297  validate_attribute(activation, 'rts_profile.Activation',
298  expected_type=Activation, required=False)
299  self._activation = activation
300 
301  @property
302  def deactivation(self):
303  '''Ordering and conditions for when the RT system is deactivated.'''
304  return self._deactivation
305 
306  @deactivation.setter
307  def deactivation(self, deactivation):
308  validate_attribute(deactivation, 'rts_profile.Deactivation',
309  expected_type=Deactivation, required=False)
310  self._deactivation = deactivation
311 
312  @property
313  def resetting(self):
314  '''Ordering and conditions for when the RT system is reset.'''
315  return self._resetting
316 
317  @resetting.setter
318  def resetting(self, resetting):
319  validate_attribute(resetting, 'rts_profile.Resetting',
320  expected_type=Resetting, required=False)
321  self._resetting = resetting
322 
323  @property
324  def initializing(self):
325  '''Ordering and conditions for when the RT system is initialised.'''
326  return self._initializing
327 
328  @initializing.setter
329  def initializing(self, initializing):
330  validate_attribute(initializing, 'rts_profile.Initializing',
331  expected_type=Initialize, required=False)
332  self._initializing = initializing
333 
334  @property
335  def finalizing(self):
336  '''Ordering and conditions for when the RT system is finalised.'''
337  return self._finalizing
338 
339  @finalizing.setter
340  def finalizing(self, finalizing):
341  validate_attribute(finalizing, 'rts_profile.Finalizing',
342  expected_type=Finalize, required=False)
343  self._finalizing = finalizing
344 
345  @property
346  def comment(self):
347  '''Comment about the system.
348 
349  A brief comment about the system. May or may not be displayed in other
350  tools. May be empty.
351 
352  Part of the extended profile.
353 
354  '''
355  return self._comment
356 
357  @comment.setter
358  def comment(self, comment):
359  validate_attribute(comment, 'rtsprofile.ext.comment',
360  expected_type=[str, unicode], required=False)
361  self._comment = comment
362 
363  @property
364  def version_up_log(self):
365  '''Log entries for new versions.
366 
367  When an update to a system is made, the log entry describing changes is
368  stored in this value.
369 
370  Part of the extended profile.
371 
372  '''
373  return self._version_up_log
374 
375  @version_up_log.setter
376  def version_up_log(self, version_up_log):
377  validate_attribute(version_up_log, 'rtsprofile.ext.VersionUpLog',
378  expected_type=list, required=False)
379  self._version_up_log = version_up_log
380 
381  @property
382  def properties(self):
383  '''Miscellaneous properties.
384 
385  Stores key/value pair properties.
386 
387  Part of the extended profile.
388 
389  '''
390  return self._properties
391 
392  @properties.setter
393  def properties(self, properties):
394  validate_attribute(properties, 'rtsprofile.ext.Properties',
395  expected_type=dict, required=False)
396  self._properties = properties
397 
398  ###########################################################################
399  # API functions
400 
401  def find_comp_by_target(self, target):
402  '''Finds a component using a TargetComponent or one of its subclasses.
403 
404  @param A @ref TargetComponent object or subclass of @ref
405  TargetComponent.
406  @return A Component object matching the target.
407  @raises MissingComponentError
408 
409  '''
410  for comp in self._components:
411  if comp.id == target.component_id and \
412  comp.instance_name == target.instance_name:
413  return comp
414  raise MissingComponentError
415 
417  '''Finds all data connections in which one or more components are not
418  required.
419 
420  If all the components involved in a connection are required, that
421  connection is also required. If one or more are not required, that
422  connection is optional.
423 
424  '''
425  result = []
426  for conn in self._data_port_connectors:
427  source_comp = self.find_comp_by_target(conn.source_data_port)
428  target_comp = self.find_comp_by_target(conn.target_data_port)
429  if not source_comp.is_required or not target_comp.is_required:
430  result.append(conn)
431  return result
432 
434  '''Finds all service connections in which one or more components are
435  not required.
436 
437  If all the components involved in a connection are required, that
438  connection is also required. If one or more are not required, that
439  connection is optional.
440 
441  '''
442  result = []
443  for conn in self._service_port_connectors:
444  source_comp = self.find_comp_by_target(conn.source_service_port)
445  target_comp = self.find_comp_by_target(conn.target_service_port)
446  if not source_comp.is_required or not target_comp.is_required:
447  result.append(conn)
448  return result
449 
451  '''Finds all data connections in which all components are required.
452 
453  If all the components involved in a connection are required, that
454  connection is also required. If one or more are not required, that
455  connection is optional.
456 
457  '''
458  result = []
459  for conn in self._data_port_connectors:
460  source_comp = self.find_comp_by_target(conn.source_data_port)
461  target_comp = self.find_comp_by_target(conn.target_data_port)
462  if source_comp.is_required and target_comp.is_required:
463  result.append(conn)
464  return result
465 
467  '''Finds all service connections in which all components are required.
468 
469  If all the components involved in a connection are required, that
470  connection is also required. If one or more are not required, that
471  connection is optional.
472 
473  '''
474  result = []
475  for conn in self._service_port_connectors:
476  source_comp = self.find_comp_by_target(conn.source_service_port)
477  target_comp = self.find_comp_by_target(conn.target_service_port)
478  if source_comp.is_required and target_comp.is_required:
479  result.append(conn)
480  return result
481 
482  ###########################################################################
483  # XML
484 
485  def parse_from_xml(self, xml_spec):
486  '''Parse a string or file containing an XML specification.'''
487  if type(xml_spec) == str or type(xml_spec) == unicode:
488  dom = xml.dom.minidom.parseString(xml_spec)
489  else:
490  dom = xml.dom.minidom.parse(xml_spec)
491  self._parse_xml(dom)
492  dom.unlink()
493 
494  def save_to_xml(self):
495  '''Save this RtsProfile into an XML-formatted string.'''
496  xml_obj = self._to_xml_dom()
497  return xml_obj.toprettyxml(indent=' ')
498 
499  ###########################################################################
500  # YAML
501 
502  def parse_from_yaml(self, yaml_spec):
503  '''Parse a string or file containing a YAML specification.'''
504  self._parse_yaml(yaml.safe_load(yaml_spec))
505 
506  def save_to_yaml(self):
507  '''Save this RtsProfile into a YAML-formatted string.'''
508  return self._to_yaml()
509 
510  ###########################################################################
511  # Internal functions
512 
513  def _parse_xml(self, dom):
514  self._reset()
515  root = dom.documentElement
516  # Get the attributes
517  self.id = root.getAttributeNS(RTS_NS, 'id')
518  self.abstract = root.getAttributeNS(RTS_NS, 'abstract')
519  self.creation_date = root.getAttributeNS(RTS_NS, 'creationDate')
520  self.update_date = root.getAttributeNS(RTS_NS, 'updateDate')
521  self.version = root.getAttributeNS(RTS_NS, 'version')
522  self.comment = root.getAttributeNS(RTS_EXT_NS, 'comment')
523  # Parse the children
524  for c in root.getElementsByTagNameNS(RTS_NS, 'Components'):
525  self._components.append(Component().parse_xml_node(c))
526  for c in root.getElementsByTagNameNS(RTS_NS, 'Groups'):
527  self._groups.append(ComponentGroup().parse_xml_node(c))
528  for c in root.getElementsByTagNameNS(RTS_NS, 'DataPortConnectors'):
529  self._data_port_connectors.append(DataPortConnector().parse_xml_node(c))
530  for c in root.getElementsByTagNameNS(RTS_NS, 'ServicePortConnectors'):
531  self._service_port_connectors.append(ServicePortConnector().parse_xml_node(c))
532  # These children should have zero or one
533  c = root.getElementsByTagNameNS(RTS_NS, 'StartUp')
534  if c.length > 0:
535  if c.length > 1:
536  raise InvalidRtsProfileNodeError('StartUp')
537  self._startup = StartUp().parse_xml_node(c[0])
538  c = root.getElementsByTagNameNS(RTS_NS, 'ShutDown')
539  if c.length > 0:
540  if c.length > 1:
541  raise InvalidRtsProfileNodeError('ShutDown')
542  self._shutdown = ShutDown().parse_xml_node(c[0])
543  c = root.getElementsByTagNameNS(RTS_NS, 'Activation')
544  if c.length > 0:
545  if c.length > 1:
546  raise InvalidRtsProfileNodeError('Activation')
547  self._activation = Activation().parse_xml_node(c[0])
548  c = root.getElementsByTagNameNS(RTS_NS, 'Deactivation')
549  if c.length > 0:
550  if c.length > 1:
551  raise InvalidRtsProfileNodeError('Deactivation')
552  self._deactivation = Deactivation().parse_xml_node(c[0])
553  c = root.getElementsByTagNameNS(RTS_NS, 'Resetting')
554  if c.length > 0:
555  if c.length > 1:
556  raise InvalidRtsProfileNodeError('Resetting')
557  self._resetting = Resetting().parse_xml_node(c[0])
558  c = root.getElementsByTagNameNS(RTS_NS, 'Initializing')
559  if c.length > 0:
560  if c.length > 1:
561  raise InvalidRtsProfileNodeError('Initializing')
562  self._initializing = Initializing().parse_xml_node(c[0])
563  c = root.getElementsByTagNameNS(RTS_NS, 'Finalizing')
564  if c.length > 0:
565  if c.length > 1:
566  raise InvalidRtsProfileNodeError('Finalizing')
567  self._finalizing = Finalizing().parse_xml_node(c[0])
568  # Extended profile children
569  for c in root.getElementsByTagNameNS(RTS_EXT_NS, 'VersionUpLog'):
570  if c.nodeType == c.TEXT_NODE:
571  self._version_up_log.append(c.data)
572  else:
573  print >>sys.stderr, 'Warning: bad VersionUpLog node type.'
574  for c in get_direct_child_elements_xml(root, prefix=RTS_EXT_NS,
575  local_name='Properties'):
576  name, value = parse_properties_xml(c)
577  self._properties[name] = value
578 
579  def _parse_yaml(self, spec):
580  self._reset()
581  if not 'rtsProfile' in spec:
582  raise RtsProfileError('Missing root node.')
583  root = spec['rtsProfile']
584  # Get the attributes
585  self.id = root['id']
586  if 'abstract' in root:
587  self.abstract = root['abstract']
588  self.creation_date = '{year:04}-{month:02}-{day:02}T{hour:02}:\
589 {minute:02}:{second:02}'.format(**root['creationDate'])
590  self.update_date = '{year:04}-{month:02}-{day:02}T{hour:02}:\
591 {minute:02}:{second:02}'.format(**root['updateDate'])
592  self.version = root['version']
593  if RTS_EXT_NS_YAML + 'comment' in root:
594  self.comment = root[RTS_EXT_NS_YAML + 'comment']
595  # Parse the children
596  if 'components' in root:
597  for c in root['components']:
598  self._components.append(Component().parse_yaml(c))
599  if 'groups' in root:
600  for c in root['groups']:
601  self._groups.append(ComponentGroup().parse_yaml(c))
602  if 'dataPortConnectors' in root:
603  for c in root['dataPortConnectors']:
604  self._data_port_connectors.append(DataPortConnector().parse_yaml(c))
605  if 'servicePortConnectors' in root:
606  for c in root['servicePortConnectors']:
607  self._service_port_connectors.append(ServicePortConnector().parse_yaml(c))
608  # Singular children
609  if 'startUp' in root:
610  self._startup = StartUp().parse_yaml(root['startUp'])
611  if 'shutDown' in root:
612  self._shutdown = ShutDown().parse_yaml(root['shutDown'])
613  if 'activation' in root:
614  self._activation = Activation().parse_yaml(root['activation'])
615  if 'deactivation' in root:
616  self._deactivation = Deactivation().parse_yaml(root['deactivation'])
617  if 'resetting' in root:
618  self._resetting = Resetting().parse_yaml(root['resetting'])
619  if 'initializing' in root:
620  self._initializing = Initializing().parse_yaml(root['initializing'])
621  if 'finalizing' in root:
622  self._finalizing = Finalizing().parse_yaml(root['finalizing'])
623  # Extended profile children
624  if RTS_EXT_NS_YAML + 'versionUpLogs' in root:
625  for c in root[RTS_EXT_NS_YAML + 'versionUpLogs']:
626  self._version_up_log.append(c)
627  if RTS_EXT_NS_YAML + 'properties' in root:
628  for p in root[RTS_EXT_NS_YAML + 'properties']:
629  if 'value' in p:
630  value = p['value']
631  else:
632  value = None
633  self._properties[p['name']] = value
634 
635  def _reset(self):
636  # Clears all values in the class in preparation for parsing an
637  # XML file.
638  # Attributes
639  self._id = ''
640  self._abstract = None
641  self._creation_date = datetime(MINYEAR, 1, 1)
642  self._update_date = datetime(MINYEAR, 1, 1)
643  self._version = ''
644  # Children
645  self._components = []
646  self._groups = []
647  self._data_port_connectors = []
648  self._service_port_connectors = []
649  self._startup = None
650  self._shutdown = None
651  self._activation = None
652  self._deactivation = None
653  self._resetting = None
654  self._initializing = None
655  self._finalizing = None
656  # Extended spec
657  self._comment = ''
658  self._version_up_log = ''
659  self._properties = {}
660 
661  def _to_dict(self):
662  # This converts an RTSProfile object into a dictionary. The typical use
663  # for this is to then dump that dictionary as YAML.
664  # We need to do this because the RtsProfile object hierarchy does not
665  # correspond directly to the YAML object hierarchy.
666  prof = {'id': self.id,
667  'abstract': self.abstract,
668  'creationDate': date_to_dict(self.creation_date),
669  'updateDate': date_to_dict(self.update_date),
670  'version': self.version}
671  if self.comment:
672  prof[RTS_EXT_NS_YAML + 'comment'] = self.comment
673 
674  components = []
675  for c in self.components:
676  components.append(c.to_dict())
677  if components:
678  prof['components'] = components
679  groups = []
680  for g in self.groups:
681  groups.append(g.to_dict())
682  if groups:
683  prof['groups'] = groups
684  d_connectors = []
685  for c in self.data_port_connectors:
686  d_connectors.append(c.to_dict())
687  if d_connectors:
688  prof['dataPortConnectors'] = d_connectors
689  s_connectors = []
690  for c in self.service_port_connectors:
691  s_connectors.append(c.to_dict())
692  if s_connectors:
693  prof['servicePortConnectors'] = s_connectors
694 
695  if self.startup:
696  prof['startUp'] = self.startup.to_dict()
697  if self.shutdown:
698  prof['shutDown'] = self.shutdown.to_dict()
699  if self.activation:
700  prof['activation'] = self.activation.to_dict()
701  if self.deactivation:
702  prof['deactivation'] = self.deactivation.to_dict()
703  if self.resetting:
704  prof['resetting'] = self.resetting.to_dict()
705  if self.initializing:
706  prof['initializing'] = self.initializing.to_dict()
707  if self.finalizing:
708  prof['finalizing'] = self.finalizing.to_dict()
709 
710  log = []
711  for l in self.version_up_log:
712  log.append(l)
713  if log:
714  prof[RTS_EXT_NS_YAML + 'versionUpLogs'] = log
715  props = []
716  for name in self.properties:
717  p = {'name': name}
718  if self.properties[name]:
719  p['value'] = str(self.properties[name])
720  props.append(p)
721  if props:
722  prof[RTS_EXT_NS_YAML + 'properties'] = props
723 
724  return {'rtsProfile': prof}
725 
726  def _to_xml_dom(self):
727  impl = xml.dom.minidom.getDOMImplementation()
728  doc = impl.createDocument(RTS_NS, RTS_NS_S + 'RtsProfile', None)
729  doc.documentElement.setAttribute('xmlns:rts', RTS_NS)
730  doc.documentElement.setAttribute('xmlns:rtsExt', RTS_EXT_NS)
731  doc.documentElement.setAttribute('xmlns:xsi',
732  'http://www.w3.org/2001/XMLSchema-instance')
733 
734  doc.documentElement.setAttributeNS(RTS_NS, RTS_NS_S + 'id', self.id)
735  doc.documentElement.setAttributeNS(RTS_NS, RTS_NS_S + 'abstract',
736  self.abstract)
737  doc.documentElement.setAttributeNS(RTS_NS, RTS_NS_S + 'creationDate',
738  self.creation_date)
739  doc.documentElement.setAttributeNS(RTS_NS, RTS_NS_S + 'updateDate',
740  self.update_date)
741  doc.documentElement.setAttributeNS(RTS_NS, RTS_NS_S + 'version',
742  str(self.version))
743  if self.comment:
744  doc.documentElement.setAttributeNS(RTS_EXT_NS,
745  RTS_EXT_NS_S + 'comment',
746  self.comment)
747  for c in self.components:
748  new_comp_element = doc.createElementNS(RTS_NS,
749  RTS_NS_S + 'Components')
750  c.save_xml(doc, new_comp_element)
751  doc.documentElement.appendChild(new_comp_element)
752  for g in self.groups:
753  new_group_element = doc.createElementNS(RTS_NS,
754  RTS_NS_S + 'Groups')
755  g.save_xml(doc, new_group_element)
756  doc.documentElement.appendChild(new_group_element)
757  for dc in self.data_port_connectors:
758  new_conn_element = doc.createElementNS(RTS_NS,
759  RTS_NS_S + 'DataPortConnectors')
760  dc.save_xml(doc, new_conn_element)
761  doc.documentElement.appendChild(new_conn_element)
762  for sc in self.service_port_connectors:
763  new_conn_element = doc.createElementNS(RTS_NS,
764  RTS_NS_S + 'ServicePortConnectors')
765  sc.save_xml(doc, new_conn_element)
766  doc.documentElement.appendChild(new_conn_element)
767  if self.startup:
768  new_cond = doc.createElementNS(RTS_NS, RTS_NS_S + 'StartUp')
769  self.startup.save_xml(doc, new_cond)
770  doc.documentElement.appendChild(new_cond)
771  if self.shutdown:
772  new_cond = doc.createElementNS(RTS_NS, RTS_NS_S + 'ShutDown')
773  self.shutdown.save_xml(doc, new_cond)
774  doc.documentElement.appendChild(new_cond)
775  if self.activation:
776  new_cond = doc.createElementNS(RTS_NS, RTS_NS_S + 'Activation')
777  self.activation.save_xml(doc, new_cond)
778  doc.documentElement.appendChild(new_cond)
779  if self.deactivation:
780  new_cond = doc.createElementNS(RTS_NS, RTS_NS_S + 'Deactivation')
781  self.deactivation.save_xml(doc, new_cond)
782  doc.documentElement.appendChild(new_cond)
783  if self.resetting:
784  new_cond = doc.createElementNS(RTS_NS, RTS_NS_S + 'Resetting')
785  self.resetting.save_xml(doc, new_cond)
786  doc.documentElement.appendChild(new_cond)
787  if self.initializing:
788  new_cond = doc.createElementNS(RTS_NS, RTS_NS_S + 'Initializing')
789  self.initializing.save_xml(doc, new_cond)
790  doc.documentElement.appendChild(new_cond)
791  if self.finalizing:
792  new_cond = doc.createElementNS(RTS_NS, RTS_NS_S + 'Finalizing')
793  self.finalizing.save_xml(doc, new_cond)
794  doc.documentElement.appendChild(new_cond)
795  for vl in self.version_up_log:
796  new_vl_element = doc.createElementNS(RTS_EXT_NS,
797  RTS_EXT_NS_S + 'VersionUpLog')
798  new_text_node = doc.createTextNode(vl)
799  new_vl_element.appendChild(new_text_node)
800  doc.documentElement.appendChild(new_vl_element)
801  for p in self.properties:
802  new_prop_element = doc.createElementNS(RTS_EXT_NS,
803  RTS_EXT_NS_S + 'Properties')
804  properties_to_xml(new_prop_element, p, self.properties[p])
805  doc.documentElement.appendChild(new_prop_element)
806  return doc
807 
808  def _to_yaml(self):
809  return yaml.safe_dump(self._to_dict())
810 
811 
812 # vim: tw=79
813 
def find_comp_by_target(self, target)
API functions.
Definition: rts_profile.py:401
Component object.
Definition: component.py:42
def _parse_xml(self, dom)
Internal functions.
Definition: rts_profile.py:513
def date_to_dict(date)
Public API functions.
Definition: utils.py:37
def properties_to_xml(element, name, value=None)
Definition: utils.py:86
def parse_properties_xml(node)
Definition: utils.py:77
def __init__(self, xml_spec=None, yaml_spec=None)
Definition: rts_profile.py:51
def parse_from_xml(self, xml_spec)
XML.
Definition: rts_profile.py:485
def validate_attribute(attr, name, expected_type=None, required=False)
Definition: utils.py:92
def parse_from_yaml(self, yaml_spec)
YAML.
Definition: rts_profile.py:502
def get_direct_child_elements_xml(node, prefix=None, local_name=None)
Definition: utils.py:50
def indent_string(string, num_spaces=2)
Definition: utils.py:65


rtsprofile
Author(s): Geoffrey Biggs
autogenerated on Fri Jun 7 2019 21:52:35