X-Git-Url: https://gerrit.akraino.org/r/gitweb?a=blobdiff_plain;f=tools%2Fpackage.py;fp=tools%2Fpackage.py;h=1a42af979ab6057c3eaf5e0b24b695dc471e18ce;hb=4ded4f2a805e9447be90751d7d4fb7e11552e545;hp=0000000000000000000000000000000000000000;hpb=3b1226294aa9e47692e15279e669d159675deeb9;p=ta%2Fbuild-tools.git diff --git a/tools/package.py b/tools/package.py new file mode 100755 index 0000000..1a42af9 --- /dev/null +++ b/tools/package.py @@ -0,0 +1,53 @@ +# Copyright 2019 Nokia +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import yaml + +from tools.statics import PACKAGES_CONFIG_PATH + + +class PackageConfigReader(object): + def __init__(self, config_file=PACKAGES_CONFIG_PATH): + self.config_file = config_file + self.config = None + self._read_file() + + def _read_file(self): + with open(self.config_file, 'r') as fp: + self.config = yaml.load(fp) + + def get(self, package_operation_type): + return self._get_packages_by_type(package_operation_type) + + def _get_packages_by_type(self, package_operation_type): + if self.config is None: + return [] + if package_operation_type == 'install': + return self._get_installed_packages() + elif package_operation_type == 'uninstall': + return self._get_uninstalled_packages() + raise Exception('Never here') + + def _get_uninstalled_packages(self): + return sorted([p for p in self.config if not self._is_install_package(p)]) + + def _get_installed_packages(self): + return sorted([p for p in self.config if self._is_install_package(p)]) + + def _is_install_package(self, package): + if self.config[package] is None: + return True + if self.config[package].get('uninstall') is True: + return False + return True