コード例 #1
0
ファイル: configuration_file.py プロジェクト: chevah/utils
    def __init__(self, configuration_path=None, configuration_file=None,
                 defaults=None):
        raw_defaults = None
        if defaults:
            raw_defaults = {}
            for key, value in defaults.items():
                raw_defaults[key] = json.dumps(value)

        self._raw_config = ConfigParser.RawConfigParser(raw_defaults)
        self._configuration_path = configuration_path
        if configuration_path:
            configuration_segments = local_filesystem.getSegmentsFromRealPath(
                configuration_path)
            if not local_filesystem.isFile(configuration_segments):
                raise UtilsError(u'1011', _(
                    u'Configuration file "%s" does not exists.' % (
                        configuration_path)))
            try:
                self._configuration_file = (
                    local_filesystem.openFileForReading(
                         configuration_segments, utf8=True))
            except IOError:
                raise UtilsError(u'1012', _(
                    u'Server process could not read the configuration file '
                    u'"%s".' % (configuration_path))
                    )
        elif configuration_file:
            self._configuration_file = configuration_file
        else:
            raise AssertionError('You must specify a path or a file.')
コード例 #2
0
ファイル: json_file.py プロジェクト: chevah/utils
 def load(self):
     """
     Load the JSON from input file. Deserialize data.
     """
     from chevah.compat import local_filesystem
     if self._segments:
         try:
             self._file = (
                 local_filesystem.openFileForReading(
                     self._segments, utf8=True))
         except IOError, error:
             data = {
                 'path': self._path,
                 'details': str(error),
             }
             raise UtilsError(u'1027',
                 u'Failed to load JSON file "%(path)s". %(details)s' % (
                     data),
                 data=data)