Пример #1
0
    def _writeError(self, data):
        """ Writes import error data to the logger, formatting it for human readable display. """
        source = {}

        if 'data' in data:
            for n,v in DictUtils.iter(data['data']):
                source[' '.join(n.split('_')).title()] = v

        indexPrefix = ''
        if 'index' in data:
            indexPrefix = ' [INDEX: %s]:' % data.get('index', 'Unknown')

        result  = [
            'IMPORT ERROR%s: %s' % (indexPrefix, data['message']),
            'DATA: ' + DictUtils.prettyPrint(source)]

        if 'existing' in data:
            source = {}
            snapshot = data['existing'].snapshot
            if snapshot:
                snapshot = JSON.fromString(snapshot)
            if snapshot:
                for n,v in DictUtils.iter(snapshot):
                    source[' '.join(n.split('_')).title()] = v
            result.append('CONFLICT: ' + DictUtils.prettyPrint(source))

        if 'error' in data:
            self._logger.writeError(result, data['error'])
        else:
            self._logger.write(result)
Пример #2
0
    def _parseData(self, data):
        if not data:
            return None

        try:
            return JSON.fromString(data)
        except Exception, err:
            return data
Пример #3
0
    def get(cls, url, config):
        """Returns the embedding object for the specified URL and config."""

        try:
            req = requests.get(config['url'] + '?url=' + urllib2.quote(url) + '&format=json')
            return JSON.fromString(req.text)
        except Exception, err:
            return None
Пример #4
0
    def _loadBuildSnapshot(self):
        settings = SettingsConfig(CompilerDeckEnvironment.projectSettingsPath, pretty=True)
        snap = settings.get(['BUILD', 'LAST_SNAPSHOT'])
        if snap is None:
            return

        try:
            self._buildSnapshot = JSON.fromString(snap)
        except Exception, err:
            pass
Пример #5
0
    def _populateTools(self):
        """Doc..."""

        path = self.getAppResourcePath('ToolsManifest.json', isFile=True)

        try:
            f = open(path)
            definition = JSON.fromString(f.read())
            f.close()
        except Exception, err:
            self.log.writeError('ERROR: Unable to read tools manifest file.', err)
            return
Пример #6
0
    def _populateTools(self):
        """Doc..."""

        path = self.getAppResourcePath('ToolsManifest.json', isFile=True)

        try:
            f = open(path)
            definition = JSON.fromString(f.read())
            f.close()
        except Exception as err:
            self.log.writeError('ERROR: Unable to read tools manifest file.', err)
            return

        for tool in ArgsUtils.getAsList('tools', definition):
            self._addTool(tool)

        self._toolBox.layout().addStretch()
Пример #7
0
    def _getEnvValue(cls, key, defaultValue =None, refresh =False, error =False):
        if cls._ENV_SETTINGS is None or refresh:
            if not cls.settingsFileExists():
                print('WARNING: No environmental settings file found.')
                return defaultValue

            envPath = cls.getRootLocalResourcePath(cls._GLOBAL_SETTINGS_FILE, isFile=True)
            f = open(envPath, 'r+')
            try:
                res = f.read()
            except Exception:
                print('ERROR: Unable to read the environmental settings file at: ' + envPath)
                return
            finally:
                f.close()

            try:
                settings = JSON.fromString(res)
            except Exception:
                print('ERROR: Unable to parse environmental settings file at: ' + envPath)
                return

            cls._ENV_SETTINGS = settings
        else:
            settings = cls._ENV_SETTINGS

        if key is None:
            return settings

        if StringUtils.isStringType(key):
            key = [key]
        value = settings
        for k in key:
            if k in value:
                value = value[k]
            else:
                if error:
                    raise Exception('Missing environmental setting: ' + str(key))
                return defaultValue

        return value
Пример #8
0
    def handle(self):
        try:
            data = self.rfile.readline().strip()
            self._log.write('HANDLE: ' + str(data))
            try:
                result = self._respondImpl(JSON.fromString(unquote(data)))
            except Exception as err:
                self._log.writeError('RESPOND FAILURE', err)
                if self.returnResponse:
                    self.wfile.write(JSON.asString({'error':1}))
                return

            if self.returnResponse:
                out = {'error':0}
                if result:
                    out['payload'] = result
                self.wfile.write(out)
        except Exception as err:
            self._log.write('HANDLE FAILURE', err)

        return
Пример #9
0
    def handle(self):
        try:
            data = self.rfile.readline().strip()
            self._log.write('HANDLE: ' + str(data))
            try:
                result = self._respondImpl(JSON.fromString(unquote(data)))
            except Exception as err:
                self._log.writeError('RESPOND FAILURE', err)
                if self.returnResponse:
                    self.wfile.write(JSON.asString({'error': 1}))
                return

            if self.returnResponse:
                out = {'error': 0}
                if result:
                    out['payload'] = result
                self.wfile.write(out)
        except Exception as err:
            self._log.write('HANDLE FAILURE', err)

        return
Пример #10
0
    def __init__(self, request, rootPackage =None, **kwargs):
        """ Creates a new ApiRouterView instance.
            @param rootPackage - The root package in which the router will import views. By default
                the module will look in same package as the router class. Packages can be absolute,
                or relative to the current package. """

        super(ApiRouterView, self).__init__(request, **kwargs)

        # Determine root package
        self._root = rootPackage if rootPackage else ClassUtils.getModulePackage(self.__class__, 1)

        zargs = self.getArg('zargs', None)
        if zargs:
            try:
                self._zargs = JSON.fromString(zargs)
            except Exception as err:
                self._zargs = None
        else:
            self._zargs = None
        self._signature = StringUtils.toUnicode(self.getArg('sig', ''))

        self._incomingTimestamp = None
        self._outgoingTimestamp = None
Пример #11
0
            if not cls.settingsFileExists():
                print 'WARNING: No environmental settings file found.'
                return defaultValue

            envPath = cls.getRootLocalResourcePath(cls._GLOBAL_SETTINGS_FILE, isFile=True)
            f = open(envPath, 'r+')
            try:
                res = f.read()
            except Exception, err:
                print 'ERROR: Unable to read the environmental settings file at: ' + envPath
                return
            finally:
                f.close()

            try:
                settings = JSON.fromString(res)
            except Exception, err:
                print 'ERROR: Unable to parse environmental settings file at: ' + envPath
                return

            cls._ENV_SETTINGS = settings
        else:
            settings = cls._ENV_SETTINGS

        if key is None:
            return settings

        if isinstance(key, basestring):
            key = [key]
        value = settings
        for k in key:
Пример #12
0
 def json_data(self):
     return JSON.fromString(self._json_data) if self._json_data else None
Пример #13
0
 def snapshotData(self):
     try:
         out = JSON.fromString(self.snapshot)
         return out if out is not None else dict()
     except Exception:
         return dict()
Пример #14
0
 def infoData(self):
     if self.info:
         return JSON.fromString(self.info)
     return dict()