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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
17 from tools.statics import PACKAGES_CONFIG_PATH
20 class PackageConfigReader(object):
21 def __init__(self, config_file=PACKAGES_CONFIG_PATH):
22 self.config_file = config_file
27 with open(self.config_file, 'r') as fp:
28 self.config = yaml.load(fp)
30 def get(self, package_operation_type):
31 return self._get_packages_by_type(package_operation_type)
33 def _get_packages_by_type(self, package_operation_type):
34 if self.config is None:
36 if package_operation_type == 'install':
37 return self._get_installed_packages()
38 elif package_operation_type == 'uninstall':
39 return self._get_uninstalled_packages()
40 raise Exception('Never here')
42 def _get_uninstalled_packages(self):
43 return sorted([p for p in self.config if not self._is_install_package(p)])
45 def _get_installed_packages(self):
46 return sorted([p for p in self.config if self._is_install_package(p)])
48 def _is_install_package(self, package):
49 if self.config[package] is None:
51 if self.config[package].get('uninstall') is True: