Pin pip to 20.3.3 and disable tmpfs in DIB
[ta/build-tools.git] / tools / repository.py
1 # Copyright 2019 Nokia
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 import os
16
17 from tools.buildconfig import BuildConfigParser
18 from tools.statics import BUILD_CONFIG_PATH
19 from tools.utils import validate_environ
20
21
22 class RepositoryConfig(object):
23     def __init__(self, ini_file=BUILD_CONFIG_PATH):
24         self.config = BuildConfigParser(ini_file=ini_file)
25
26     def read_section(self, section):
27         repositories = []
28         for repo_name, repo_value in self.config.items(section):
29             parts = repo_value.split('#')
30             repodata = dict(name=repo_name, baseurl=parts[0])
31             for p in parts[1:]:
32                 key, value = p.split('=', 1)
33                 repodata[key] = value
34             repositories.append(repodata)
35         return repositories
36
37     def read_sections(self, sections):
38         repositories = []
39         for s in sections:
40             repositories += self.read_section(s)
41         return repositories
42
43     @classmethod
44     def get_localrepo(cls, remote=False):
45         dirname = 'repo'
46         if remote:
47             validate_environ(['BUILD_URL'])
48             baseurl = os.path.join(os.environ['BUILD_URL'], 'artifact/results', dirname)
49         else:
50             validate_environ(['WORK'])
51             baseurl = 'file://' + \
52                       os.path.join(os.environ['WORK'], 'results', dirname)
53         return dict(name='localrepo', baseurl=baseurl)