aboutsummaryrefslogtreecommitdiffstats
path: root/tools/xmlGenerator/PfwBaseTranslator.py
diff options
context:
space:
mode:
authorDavid Wagner <david.wagner@intel.com>2015-01-08 17:11:44 +0100
committerDavid Wagner <david.wagner@intel.com>2015-01-28 20:02:38 +0100
commit7d996811c0e80b30a40a5add1f01f0314f2ebef4 (patch)
treed2ecef1672edc7ba183fe902f2b778b32a171cbc /tools/xmlGenerator/PfwBaseTranslator.py
parentfa09759eddd515fb2f83810ba76f9a6f8878093f (diff)
downloadexternal_parameter-framework-7d996811c0e80b30a40a5add1f01f0314f2ebef4.zip
external_parameter-framework-7d996811c0e80b30a40a5add1f01f0314f2ebef4.tar.gz
external_parameter-framework-7d996811c0e80b30a40a5add1f01f0314f2ebef4.tar.bz2
xmlGenerator: Refactor PFWScriptGenerator
The existing code is split in two parts: - "EDD"-files parsing; - parameter-framework remote commands generation The first part is mostly kept as-is but the file is renamed to "EddParser.py"; the second part is refactored and an object presenting a "Translator" intreface is passed to the parsed objects in order to generate the remote parameter-framework commands. Later, another class implementing the Translator interface will be implemented using the python bindings. Some dead code is removed in the process. Change-Id: I9725600ce34f36742c7e27ea7aee53892dd799b0 Signed-off-by: David Wagner <david.wagner@intel.com>
Diffstat (limited to 'tools/xmlGenerator/PfwBaseTranslator.py')
-rw-r--r--tools/xmlGenerator/PfwBaseTranslator.py177
1 files changed, 177 insertions, 0 deletions
diff --git a/tools/xmlGenerator/PfwBaseTranslator.py b/tools/xmlGenerator/PfwBaseTranslator.py
new file mode 100644
index 0000000..0d08565
--- /dev/null
+++ b/tools/xmlGenerator/PfwBaseTranslator.py
@@ -0,0 +1,177 @@
+# Copyright (c) 2015, Intel Corporation
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without modification,
+# are permitted provided that the following conditions are met:
+#
+# 1. Redistributions of source code must retain the above copyright notice, this
+# list of conditions and the following disclaimer.
+#
+# 2. Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation and/or
+# other materials provided with the distribution.
+#
+# 3. Neither the name of the copyright holder nor the names of its contributors
+# may be used to endorse or promote products derived from this software without
+# specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+class PfwException(Exception):
+ pass
+
+class PfwBaseTranslator(object):
+ """Abstract Pfw Translator class
+
+ The protocol presented by this class allows the creation of
+ parameter-framework settings: domains, configurations rules, etc.
+
+ Some methods must be called within a context; e.g. when 'addElement' is
+ called, the element is added to the domain that was last created through
+ 'createDomain'
+
+ Derived classed should only implemented the backend methods, prefixed by an
+ underscore."""
+
+ def __init__(self):
+ self._ctx_domain = ''
+ self._ctx_configuration = ''
+ self._ctx_sequence_aware = False
+ self._ctx_command = ''
+
+ self._domain_valid = False
+ self._configuration_valid = False
+
+ def _getContext(self):
+ return {
+ 'domain': self._ctx_domain,
+ 'configuration': self._ctx_configuration,
+ 'sequence_aware': self._ctx_sequence_aware,
+ 'command': self._ctx_command}
+
+ def _check(self, func):
+ """Check and handles exceptions
+
+ Returns False if an exception occured and was properly caught,
+ True otherwise"""
+ def wrapped(*args, **kwargs):
+ try:
+ func(*args, **kwargs)
+ except PfwException as ex:
+ self._handleException(ex)
+ return False
+
+ return True
+
+ return wrapped
+
+ def createDomain(self, name, sequence_aware=False):
+ """Create a domain with a given name and optionally set its sequence
+ awareness"""
+
+ self._ctx_command = "createDomain"
+ self._ctx_domain = name
+ self._ctx_configuration = ''
+ self._ctx_sequence_aware = sequence_aware
+ self._domain_valid = True
+
+ if not self._check(self._doCreateDomain)(name):
+ self._domain_valid = False
+ elif sequence_aware:
+ self._check(self._doSetSequenceAware)()
+
+ def addElement(self, path):
+ """Add a configurable element to the current domain"""
+
+ self._ctx_command = "addElement"
+
+ if not self._domain_valid:
+ return
+
+ self._check(self._doAddElement)(path)
+
+ def createConfiguration(self, name):
+ """Create a configuration for the current domain"""
+
+ self._ctx_command = "createConfiguration"
+ self._ctx_configuration = name
+ self._configuration_valid = True
+
+ if not self._domain_valid:
+ self._configuration_valid = False
+ return
+
+ if not self._check(self._doCreateConfiguration)(name):
+ self._configuration_valid = False
+
+ def setElementSequence(self, paths):
+ """Set the element sequence (if applicable, e.g. if the domain is
+ sequence-aware) of the current configuration"""
+
+ self._ctx_command = "setElementSequence"
+
+ if not self._configuration_valid:
+ return
+
+ if not self._ctx_sequence_aware:
+ return
+
+ self._check(self._doSetElementSequence)(paths)
+
+ def setRule(self, rule):
+ """Set the current configuration's applicability rule"""
+
+ self._ctx_command = "setRule"
+
+ if not self._configuration_valid:
+ return
+
+ self._doSetRule(rule)
+
+ def setParameter(self, path, value):
+ """Set a parameter value for the current configuration"""
+
+ self._ctx_command = "setParameter"
+
+ if not self._configuration_valid:
+ return
+
+ self._check(self._doSetParameter)(path, value)
+
+ def _handleException(self, exception):
+ raise exception
+
+ def _notImplemented(self):
+ raise NotImplementedError(
+ "{} is an abstract class".format(self.__class__))
+
+ # Implementation methods
+ def _doCreateDomain(self, name):
+ self._notImplemented()
+
+ def _doSetSequenceAware(self):
+ self._notImplemented()
+
+ def _doAddElement(self, path):
+ self._notImplemented()
+
+ def _doCreateConfiguration(self, name):
+ self._notImplemented()
+
+ def _doSetElementSequence(self, paths):
+ self._notImplemented()
+
+ def _doSetRule(self, rule):
+ self._notImplemented()
+
+ def _doSetParameter(self, path, value):
+ self._notImplemented()