forked from google/vanir
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile_list_manager.py
58 lines (42 loc) · 1.45 KB
/
file_list_manager.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# Copyright 2023 Google LLC
#
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file or at
# https://developers.google.com/open-source/licenses/bsd
"""Module for managing known files for each ecosystem/package.
This module manages lists of known files for each ecysostem & package needed
for calculating truncated path level.
"""
import collections
import enum
import json
from typing import Mapping, Sequence
from vanir import parser
_GITFS_TIMEOUT_SEC = 60
_GITFS_ADDR = 'blade:git'
ANDROID_ECOSYSTEM = 'Android'
KERNEL_PACKAGE = ':linux_kernel:'
_MAINLINE_KERNEL_PROJECT = 'android:kernel/common:refs/heads/android-mainline:'
_KNOWN_SOURCES = [(ANDROID_ECOSYSTEM, KERNEL_PACKAGE, _MAINLINE_KERNEL_PROJECT)]
ECOSYSTEM_FILE_LISTS_CACHE = (
'cache/ecosystem_file_lists.json'
)
@enum.unique
class Source(enum.Enum):
CACHE = 'cache'
def get_file_lists(
source: Source = Source.CACHE,
) -> Mapping[str, Mapping[str, Sequence[str]]]:
"""Returns reference file lists for signature generation.
Args:
source: source to retrieve file lists.
Returns:
Reference file list map where the first key is ecosystem, the second key is
package name and the value is list of files.
"""
if source == Source.CACHE:
resource = open(ECOSYSTEM_FILE_LISTS_CACHE, mode='rb').read()
file_lists = json.loads(resource)
return file_lists
else:
raise ValueError('Unknown file list source: %s' % source)