diff options
author | Justin chi <chigang@huawei.com> | 2016-11-24 08:47:48 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2016-11-24 08:47:48 +0000 |
commit | 36f5cffcf373a8a12677c8e406cd11c8d9ffe2bb (patch) | |
tree | a20455421b7bdf19890032ce4da74ceee3a46762 /repo/gen_ins_pkg_script.py | |
parent | 2446530c3230221d76877851012eb39e2a7c0360 (diff) | |
parent | 35086233fdfb4163c589fc258229a931bb02df1a (diff) |
Merge "Create make_repo directory and optimize the current repo making related script"
Diffstat (limited to 'repo/gen_ins_pkg_script.py')
-rw-r--r-- | repo/gen_ins_pkg_script.py | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/repo/gen_ins_pkg_script.py b/repo/gen_ins_pkg_script.py new file mode 100644 index 00000000..7f96d35d --- /dev/null +++ b/repo/gen_ins_pkg_script.py @@ -0,0 +1,90 @@ +import yaml +import os +import sys +from Cheetah.Template import Template +import constants as const + + +def get_file_list(root, arch): + files = [] + + dirs = os.listdir(os.path.join(root, 'roles')) + + for dir in dirs: + var_dir = os.path.join(root, 'roles', dir, 'vars') + for name in ['main.yml', arch + r'.yml']: + if os.path.exists(os.path.join(var_dir, name)): + files.append(os.path.join(var_dir, name)) + + return files + + +def get_packages_name_list(file_list, special_packages): + package_name_list = [] + + for file in file_list: + datas = yaml.load(open(file)) + if not datas: + continue + + for key, value in datas.items(): + if key == "pip_packages": + continue + + if not key.endswith("packages") and not key.endswith( + "packages_noarch"): + continue + + if not value: + continue + + if not isinstance(value, list): + value = [value] + + for i in value: + if i in special_packages: + continue + if i not in package_name_list: + package_name_list.append(i) + + return package_name_list + + +def generate_download_script(root="", arch="", tmpl="", docker_tmpl="", default_packages="", # noqa + special_packages="", special_packages_script_dir="", special_packages_dir="", os_ver=""): # noqa + package_name_list = get_packages_name_list( + get_file_list(root, arch), special_packages) if root else [] + + tmpl = Template( + file=tmpl, + searchList={ + 'packages': package_name_list, + 'default_packages': default_packages}) + with open('work/repo/install_packages.sh', 'w') as f: + f.write(tmpl.respond()) + + make_script = [] + for i in special_packages: + name = 'make_' + i + '.sh' + if os.path.exists(os.path.join(special_packages_script_dir, name)): + make_script.append(name) + + searchList = {'scripts': make_script, 'version': const.os_map[os_ver]} + if os.path.exists(special_packages_dir): + special_packages_names = [] + + for parent, dirname, filenames in os.walk(special_packages_dir): + for filename in filenames: + if os.path.isfile(os.path.join(parent, filename)): + special_packages_names.append(filename) + searchList.update({'spcial_packages': special_packages_names}) + + Dockerfile = os.path.basename(docker_tmpl).split('.')[0] + tmpl = Template(file=docker_tmpl, searchList=searchList) + with open(os.path.join('work/repo', Dockerfile), 'w') as f: + f.write(tmpl.respond()) + +if __name__ == '__main__': + # generate_download_script('ansible', 'Debian', 'Debian.tmpl') + generate_download_script(sys.argv[1], sys.argv[2], sys.argv[3], + sys.argv[4], sys.argv[5].split(' '), sys.argv[6].split(' '), sys.argv[7], sys.argv[8], sys.argv[9]) # noqa |