Ejemplo n.º 1
0
    def load(self, data):
        """ Loads the data into the CadenceData instance, parsing if necessary beforehand.

            @@@param load:string,dict
                Either a string or dictionary representation of valid Cadence Interchange Data
                formatted data to be loaded.

            @@@return bool
                True if successful, False if the load process failed because of invalid data.
        """

        if not data:
            return False

        if StringUtils.isStringType(data):
            try:
                data = json.loads(data)
            except Exception as err:
                print("FAILED: Loading Cadence data from JSON string.", err)
                return False

        if CadenceData._NAME_KEY in data:
            self._name = data.get(CadenceData._NAME_KEY)

        if CadenceData._CONFIGS_KEY in data:
            self._configs = ConfigReader.fromDict(data.get(CadenceData._CONFIGS_KEY))

        if CadenceData._CHANNELS_KEY in data:
            for c in data.get(CadenceData._CHANNELS_KEY, dict()):
                self._channels.append(DataChannel.fromDict(c))

        return True
Ejemplo n.º 2
0
        if isinstance(data, basestring):
            try:
                data = json.loads(data)
            except Exception, err:
                print 'FAILED: Loading Cadence data from JSON string.', err
                return False

        if CadenceData._NAME_KEY in data:
            self._name = data.get(CadenceData._NAME_KEY)

        if CadenceData._CONFIGS_KEY in data:
            self._configs = ConfigReader.fromDict(data.get(CadenceData._CONFIGS_KEY))

        if CadenceData._CHANNELS_KEY in data:
            for c in data.get(CadenceData._CHANNELS_KEY, dict()):
                self._channels.append(DataChannel.fromDict(c))

        return True

#___________________________________________________________________________________________________ write
    def write(self, folder =None, name =None):
        """ Writes the Cadence data to an encoded string and returns that string. If a path is
            specified, it will also write the data to that file before returning the string. If the
            writing process fails, None is returned instead.

            @@@param folder:string
                The folder where the file should be written relative to Cadence's root data
                directory.

            @@@param name:string
                If specified this value will override the CadenceData instance's name for the