コード例 #1
0
ファイル: cache.py プロジェクト: 571451370/devstack_mitaka
def build_cache_db(conf, versions_to_include):
    s = scanner.Scanner(conf)
    notes = s.get_notes_by_version()

    # Default to including all versions returned by the scanner.
    if not versions_to_include:
        versions_to_include = list(notes.keys())

    # Build a cache data structure including the file contents as well
    # as the basic data returned by the scanner.
    file_contents = {}
    for version in versions_to_include:
        for filename, sha in notes[version]:
            body = s.get_file_at_commit(filename, sha)
            # We want to save the contents of the file, which is YAML,
            # inside another YAML file. That looks terribly ugly with
            # all of the escapes needed to format it properly as
            # embedded YAML, so parse the input and convert it to a
            # data structure that can be serialized cleanly.
            y = yaml.safe_load(body)
            file_contents[filename] = y

    cache = {
        'notes': [
            {'version': k, 'files': v}
            for k, v in notes.items()
        ],
        'file-contents': file_contents,
    }
    return cache
コード例 #2
0
    def _load_data(self):
        cache_file_exists = os.path.exists(self._cache_filename)

        if self._ignore_cache and cache_file_exists:
            LOG.debug('ignoring cache file %s', self._cache_filename)

        if (not self._ignore_cache) and cache_file_exists:
            LOG.debug('loading cache file %s', self._cache_filename)
            with open(self._cache_filename, 'r') as f:
                self._cache = yaml.safe_load(f.read())
                # Save the cached scanner output to the same attribute
                # it would be in if we had loaded it "live". This
                # simplifies some of the logic in the other methods.
                self._scanner_output = collections.OrderedDict(
                    (n['version'], n['files']) for n in self._cache['notes'])
        else:
            self._scanner = scanner.Scanner(self._config)
            self._scanner_output = self._scanner.get_notes_by_version()