diff options
author | Joonsub Lee <joon-sub.lee@samsung.com> | 2016-08-09 10:47:57 +0900 |
---|---|---|
committer | Joonsub Lee <joon-sub.lee@samsung.com> | 2016-09-09 20:48:54 +0900 |
commit | dea1b843374418030cac237992e7e8e7f91c9ea8 (patch) | |
tree | ad3a7b60b3a57afab652d0ac36f9704f1b2a48b3 | |
parent | d3b43b4768e2c1f71b85ce9e3035c33abe27153d (diff) | |
download | image-configurations-dea1b843374418030cac237992e7e8e7f91c9ea8.tar.gz image-configurations-dea1b843374418030cac237992e7e8e7f91c9ea8.tar.bz2 image-configurations-dea1b843374418030cac237992e7e8e7f91c9ea8.zip |
Convert group names to rpm package listssubmit/tizen/20160912.084946accepted/tizen/wearable/20160912.093713accepted/tizen/tv/20160912.093657accepted/tizen/mobile/20160912.093642accepted/tizen/ivi/20160912.093730accepted/tizen/common/20160912.181640
ks file with group names is simple to view but
not usable when modifing and searching package by package.
'convert_ks.py' converts groups in ks file to rpm package lists.
https://bugs.tizen.org/jira/browse/TRE-526
Change-Id: I7ea1be1a29aef5a759c05390d0943845c5ccf41b
Signed-off-by: Joonsub Lee <joon-sub.lee@samsung.com>
-rw-r--r-- | convert_ks.py | 113 | ||||
-rw-r--r-- | packaging/image-configurations.spec | 14 |
2 files changed, 125 insertions, 2 deletions
diff --git a/convert_ks.py b/convert_ks.py new file mode 100644 index 0000000..e89acd1 --- /dev/null +++ b/convert_ks.py @@ -0,0 +1,113 @@ +#!/usr/bin/python +#-*- encoding: utf-8 -*- +""" + File name: convert_ks.py + Python Version: 2.7.3 + Licensed under the terms of the GNU GPL License version 2 +""" + +import tempfile +import shutil +import argparse +from lxml import etree + +def write_package(convert_ks, xmlfile, groups, extra_pkgs): + """ + Arguments: + - convert_ks: temporary file for converting + - xmlfile: group.xml from 'package-groups' + - groups: Group list from original ks file + - extra_pkgs: ExtraPackages and RemovePackages from original ks file + + Function: + - convert group name to rpm list and write to ks file + getting from xmlfile has group information. + + Return value: + - True: success + - False: fail caused by KeyError + """ + xmltree = etree.parse(xmlfile) + root = xmltree.getroot() + group_info = dict() + + for group in root: + pkg_list = list() + for pkgname in group.find('packagelist').findall('packagereq'): + pkg_list.append(pkgname.text) + group_info[group.find('name').text] = pkg_list + + for group in groups: + try: + convert_ks.write('# @ ' + group + '\n') + for pkg in sorted(group_info[group]): + convert_ks.write(pkg + '\n') + except KeyError: + print '\nin convert_ks.py: ' + print 'error: Could not find @ ' + group + ' in package-groups\n' + return False + + convert_ks.write('# Others\n') + for pkg in extra_pkgs: + convert_ks.write(pkg + '\n') + + return True + +def main(origin_file, group_file): + """ + Arguments: + - origin_file: *.ks file wrote by Groups name + - group_file: group.xml from 'package-groups' + + Function: + - Read origin ks file and write to temp file line by line. + In pkg group session, call write_package() to convert + group name to rpm file list. + """ + origin_ks = file(origin_file, 'r') + (file_flag, convert_file) = tempfile.mkstemp() + convert_ks = file(convert_file, 'w') #temporary file for converting + groups = list() + extra_pkgs = list() + + pkg_session = False + for line in origin_ks.readlines(): + line_plaintext = line.strip() + if not pkg_session and line_plaintext == "%packages": + convert_ks.write(line + '\n') + pkg_session = True + elif pkg_session and line_plaintext == "%end": + # write_package writes packages' list when pkg_session ends + if not write_package(convert_ks, group_file, groups, extra_pkgs): + # KeyError in write_package: close files and exit with error + origin_ks.close() + convert_ks.close() + exit(1) + convert_ks.write('\n') + pkg_session = False + + if pkg_session: + if line_plaintext.startswith('@'): # Read Group + groups.append(line_plaintext[1:]) + elif not line_plaintext.startswith('%'): # Read Extra/RemovePackage + extra_pkgs.append(line_plaintext) + else: + convert_ks.write(line) + + origin_ks.close() + convert_ks.close() + + shutil.move(convert_file, origin_file) + +if __name__ == '__main__': + parser = argparse.ArgumentParser( + description=''' + Replace group names with list of packages they contain. + ''', + ) + parser.add_argument('ksfilename', type=str, help='ks file to modify') + parser.add_argument('pkggroup', type=str, + help='group.xml file from package-groups package') + args = parser.parse_args() + + main(args.ksfilename, args.pkggroup) diff --git a/packaging/image-configurations.spec b/packaging/image-configurations.spec index 47633ae..f2eb15c 100644 --- a/packaging/image-configurations.spec +++ b/packaging/image-configurations.spec @@ -8,10 +8,10 @@ Summary: Create kickstart files for Tizen images Name: image-configurations -Version: 101 +Version: 102 Release: 1 License: GPL-2.0 -Group: System/Base +Group: System/Configuration URL: http://www.tizen.org Source: image-configurations-%{version}.tar.bz2 Source1001: image-configurations.manifest @@ -20,6 +20,8 @@ BuildArch: noarch BuildRequires: kickstarter >= 0.15 BuildRequires: meta-generic BuildRequires: meta-%{_profile} +BuildRequires: package-groups +BuildRequires: python %description Create Configuration files to build Tizen images @@ -39,6 +41,9 @@ for profile in generic %_profile; do [ -d $pdir ] && cp -a $pdir/* input/ done +pdir=%{_datadir}/package-groups +[ -d "$pdir" ] && cp "$pdir/group.xml" input/ + kickstarter -c input/%_profile.yaml \ -e input/configs \ -r input/%_profile-repos.yaml \ @@ -52,6 +57,11 @@ mkdir -p %{buildroot}/usr/share/image-configurations [ -n "$(ls -A %{baseline}/*.ks 2>/dev/null)" ] && cp %{baseline}/*.ks %{buildroot}/usr/share/image-configurations cp image-configs.xml %{buildroot}/usr/share/image-configurations +[ -d %{buildroot}/usr/share/image-configurations ] && for ksfile in $(ls -A %{buildroot}/usr/share/image-configurations/*.ks 2>/dev/null) +do + python convert_ks.py "${ksfile}" input/group.xml +done + %files %manifest %{name}.manifest #%dir %_datadir/image-configurations |