Esempio n. 1
0
    def _parse_dep_cache_file(self):
        with self.profile.timer('Pod._parse_dep_cache_file'):
            podcache_file_name = '/{}'.format(self.FILE_DEP_CACHE)

            # TODO Remove deprecated cachefile support.
            # Convert legacy yaml cache files.
            legacy_podcache_file_name = '/.podcache.yaml'
            if self.file_exists(legacy_podcache_file_name):
                logging.info('Converting {} to {}.'.format(
                    legacy_podcache_file_name, podcache_file_name))
                # Do not use the utils.parse_yaml as that has extra constructors
                # that should not be run when the cache file is being parsed.
                temp_data = yaml.load(
                    self.read_file(legacy_podcache_file_name)) or {}
                if 'objects' in temp_data and temp_data['objects']:
                    object_cache_file_name = '/{}'.format(
                        podcache.FILE_OBJECT_CACHE)
                    self.write_file(object_cache_file_name,
                                    json.dumps(temp_data['objects']))
                self.delete_file(legacy_podcache_file_name)

            if not self.file_exists(podcache_file_name):
                return {}
            try:
                return self.read_json(podcache_file_name) or {}
            except IOError:
                path = self.abs_path(podcache_file_name)
                raise podcache.PodCacheParseError(
                    'Error parsing: {}'.format(path))
Esempio n. 2
0
    def _parse_object_cache_file(self):
        with self.profile.timer('Pod._parse_object_cache_file'):
            object_cache_file_name = '/{}'.format(podcache.FILE_OBJECT_CACHE)

            if not self.file_exists(object_cache_file_name):
                return {}
            try:
                return self.read_json(object_cache_file_name) or {}
            except IOError:
                path = self.abs_path(object_cache_file_name)
                raise podcache.PodCacheParseError(
                    'Error parsing: {}'.format(path))
Esempio n. 3
0
 def _parse_routes_cache_file(self):
     with self.profile.timer('Pod._parse_routes_cache_file'):
         routes_cache_file_name = '{}{}'.format(self.PATH_CONTROL,
                                                podcache.FILE_ROUTES_CACHE)
         if not self.file_exists(routes_cache_file_name):
             return {}
         try:
             return self.read_json(routes_cache_file_name) or {}
         except ValueError:
             # File became corrupted; delete it and start over.
             # https://github.com/grow/grow/issues/1050#issuecomment-596346032
             self.delete_file(routes_cache_file_name)
             return {}
         except IOError:
             path = self.abs_path(routes_cache_file_name)
             raise podcache.PodCacheParseError(
                 'Error parsing: {}'.format(path))