2 # Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
5 # @author Chulwoo Shin <cw1.shin@samsung.com>
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
11 # http://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
25 from tic.dependency import analyze_dependency, get_installed_packages
26 from tic.parser.recipe_parser import get_default_recipe, convert_recipe_to_yaml
27 from tic.parser.repo_parser import RepodataParser
28 from tic.parser.view_parser import make_view_data
29 from tic.utils.error import TICError
30 from tic.utils.file import copyfile
31 from tic.repo import get_repodata_from_repos
32 from tic.pykickstarter import KSoption, kswriter
33 from tic.utils import process
36 DEFAULT_CACHEDIR='/var/tmp/tic-core/cached'
37 DEFAULT_KICKSTARTDIR='/var/tmp/tic-core/kickstart'
39 def analyze(repo_list, recipe_list=None):
40 logger = logging.getLogger(__name__)
42 if not repo_list and not recipe_list:
43 raise TICError('No repositories defined')
47 #TODO Repository check
48 # using default recipe (Temporary Code)
49 if recipe_list and recipe_list[0] == 'default':
50 recipe = get_default_recipe()
51 for repo_url in recipe.get('Repositories'):
52 repos.append({'name': repo_url.get('Name'),
53 'url': repo_url.get('Url')})
56 for repo_url in repo_list:
57 repos.append({'name': 'repository_%d' % number,
61 #Download repodata from repositories (Remote/Local)
62 repoinfo = get_repodata_from_repos(repos, DEFAULT_CACHEDIR)
64 # Parse the xml files for the analysis of package (.rpm)
65 repo_parser = RepodataParser(repoinfo)
66 pkg_group = repo_parser.parse()
67 logger.info('pkg_list: %d, pkg2id: %d', len(pkg_group['pkg_list']), len(pkg_group['pkg2id']))
69 # package install-dependency analysis
70 analyze_dependency(pkg_group)
71 # Make a data for TIC (Tizen image creation)
72 view_data = make_view_data(pkg_group)
73 inst_packages = get_installed_packages(recipe, repoinfo, pkg_group)
75 result = {'packages': view_data,
77 'defaultpackages': inst_packages}
81 def exports(export_type, recipe, packages, outdir):
82 logger = logging.getLogger(__name__)
84 #TODO validation should be checked before request
87 logger.info('set default export format(.ks)')
90 raise TICError('No recipe defined')
91 if not packages or type(packages) is not list:
92 raise TICError('No packages defined')
95 # Temporary code for 1st prototype release
96 if recipe.get('name') == 'default':
97 recipe = get_default_recipe()
98 config = recipe.get('Configurations')[0]
99 for key in ['Default', config['Platform']]:
100 recipe[key]['Groups']=[]
101 recipe[key]['ExtraPackages']=[]
103 config['ExtraPackages'] = packages
105 raise TICError('No recipes defined')
108 yaml_info = convert_recipe_to_yaml(recipe, DEFAULT_KICKSTARTDIR)
110 # create kickstart(.ks) using kickstarter tool
111 options = KSoption(yaml_info.configs, yaml_info.repos, yaml_info.cachedir)
114 # check whether the ks exists
115 baseline=recipe['Default'].get('Baseline')
116 ksname= ''.join([config.get('FileName'), '.ks'])
117 kspath=os.path.join(yaml_info.cachedir, baseline, ksname)
118 if not os.path.exists(kspath):
119 raise TICError('No ks file was created from kickstarter')
121 # copy the ks to output directory
122 output=copyfile(kspath, outdir)
123 logger.info('copy the ks file from %s to dst:%s', kspath, output)
127 def createimage(recipes, ksfile, outdir):
128 logger = logging.getLogger(__name__)
131 logger.info('the recipes option is not yet supported')
134 if not os.path.exists(ksfile) or os.path.isdir(ksfile):
135 raise TICError('kickstart file does not exist')
137 mic_command=['mic', 'cr', 'auto', ksfile]
139 mic_command.append('--outdir=%s' % outdir)
141 process.run(mic_command, 2)