create kickstart(.ks) file using the kickstarter module.
add thread option for flask
Change-Id: Ib6d96e1179fa4750d9655cdd1346217b25a16282
Signed-off-by: Chulwoo Shin <cw1.shin@samsung.com>
+#!/usr/bin/python
+# Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
+#
+# Contact:
+# @author Chulwoo Shin <cw1.shin@samsung.com>
+#
+# 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.
+#
+# Contributors:
+# - S-Core Co., Ltd
+
+import os
import logging
+import shutil
from tic.dependency import analyze_dependency, get_installed_packages
-from tic.parser.recipe_parser import get_default_recipe
+from tic.parser.recipe_parser import get_default_recipe, convert_recipe_to_yaml
from tic.parser.repo_parser import RepodataParser
from tic.parser.view_parser import make_view_data
-
from tic.utils.error import TICError
from tic.repo import get_repodata_from_repos
+from tic.pykickstarter import KSoption, kswriter
+
DEFAULT_CACHEDIR='/var/tmp/tic-core/cached'
+DEFAULT_KICKSTARTDIR='/var/tmp/tic-core/kickstart'
def analyze(repo_list, recipe_list=None):
logger = logging.getLogger(__name__)
'repos': repos,
'defaultpackages': inst_packages}
- return result
\ No newline at end of file
+ return result
+
+def exports(export_type, recipe, packages, output):
+ logger = logging.getLogger(__name__)
+ if not export_type:
+ export_type='ks'
+ logger.info('set default export format(.ks)')
+
+ if not recipe:
+ raise TICError('No recipe defined')
+ if not packages or type(packages) is not list:
+ raise TICError('No packages defined')
+
+ #TODO recipe parsing
+ # Temporary code for 1st prototype release
+ if recipe.get('name') == 'default':
+ recipe = get_default_recipe()
+ config = recipe.get('Configurations')[0]
+ for key in ['Default', config['Platform']]:
+ recipe[key]['Groups']=[]
+ recipe[key]['ExtraPackages']=[]
+ config['Groups']=[]
+ config['ExtraPackages'] = packages
+ else:
+ raise TICError('No recipes defined')
+
+ # create the yaml
+ yaml_info = convert_recipe_to_yaml(recipe, DEFAULT_KICKSTARTDIR)
+
+ # create kickstart(.ks) using kickstarter tool
+ options = KSoption(yaml_info.configs, yaml_info.repos, yaml_info.cachedir)
+ kswriter(options)
+
+ # check whether the ks exists
+ baseline=recipe['Default'].get('Baseline')
+ ksname= ''.join([config.get('FileName'), '.ks'])
+ kspath=os.path.join(yaml_info.cachedir, baseline, ksname)
+ if not os.path.exists(kspath):
+ raise TICError('No ks file was created from kickstarter')
+
+ # copy the ks to output directory
+ shutil.copy(kspath, output)
+ logger.info('copy the ks file from %s to dst:%s', kspath, output)
+
+ return output
#
# Contributors:
# - S-Core Co., Ltd
+
from lxml import etree
from tic.utils.error import TICError
import logging
# Contributors:
# - S-Core Co., Ltd
+import collections
+from datetime import datetime
+import logging
import os
-import yaml
from tic.utils import error
-from tic.utils.file import write
+from tic.utils.file import write, make_dirs
+import yaml
+
def get_default_recipe():
recipe = dict(
Schedule= "*",
Active= True,
Platform= 'Emulator64wayland',
+ Part= 'mobile-2parts-emulator',
Mic2Options= '-f loop --pack-to=@NAME@.tar.gz,',
FileName= 'mobile-emulator64-wayland',
Repos=['mobile-emulator64-wayland', 'base_emulator64'],
],
Partitions=[
dict(Name='mobile-mbr',
- Contents='part / --fstype="ext4" --size=3584 --ondisk=sda --active --label platform --fsoptions=defaults,noatime')
+ Contents='part / --fstype="ext4" --size=3584 --ondisk=sda --active --label platform --fsoptions=defaults,noatime'),
+ dict(Name= 'mobile-2parts-emulator',
+ Contents='part / --size=2000 --ondisk=sda --fstype=ext4 --label=emulator-rootfs\npart /opt/ --size=2000 --ondisk=sda --fstype=ext4 --label=emulator-sysdata')
]
)
return recipe
raise error.TICError('yaml format error of meta file: %s' % path)
-def separate_recipe_file_for_ks(recipe):
- path = '/home/shinchulwoo/recipe/test'
+def convert_recipe_to_yaml(recipe, filepath):
+ logger = logging.getLogger(__name__)
# config.yaml
config = dict(Default=None, Configurations=[])
config['Configurations'].append(recipe.get('Configurations')[0])
platform_name = config['Configurations'][0].get('Platform')
config[platform_name] = recipe.get(platform_name)
- with open(os.path.join(path, 'config.yaml'), 'w') as outfile:
+
+ dir_path = os.path.join(filepath, datetime.now().strftime('%Y%m%d%H%M%S%f'))
+ make_dirs(dir_path)
+ logger.info('kickstart cache dir=%s' % dir_path)
+
+ yamlinfo = YamlInfo(dir_path,
+ os.path.join(dir_path, 'configs.yaml'),
+ os.path.join(dir_path, 'repos.yaml'))
+
+ # configs.yaml
+ with open(yamlinfo.configs, 'w') as outfile:
yaml.dump(config, outfile, default_flow_style=False)
- # repo.yaml
+ # repo.yaml
if 'Repositories' in recipe:
repos = {}
repos['Repositories'] = recipe['Repositories']
- with open(os.path.join(path, 'repos.yaml'), 'w') as outfile:
+ with open(yamlinfo.repos, 'w') as outfile:
yaml.dump(repos, outfile, default_flow_style=False)
# partition info
if 'Partitions' in recipe:
for partition in recipe.get('Partitions'):
- partition_path = os.path.join(path, 'partitions')
+ partition_path = os.path.join(dir_path, 'partitions')
file_name = partition.get('Name')
temp = os.path.join(partition_path, file_name)
write(temp, partition['Contents'])
# script.post
if 'PostScripts' in recipe:
for script in recipe.get('PostScripts'):
- script_path = os.path.join(path, 'scripts')
+ script_path = os.path.join(dir_path, 'scripts')
script_type = script.get('Type')
if script_type and script_type == 'nochroot':
file_name = '%s.nochroot' % script.get('Name')
else:
file_name = '%s.post' % script.get('Name')
write(os.path.join(script_path, file_name), script['Contents'])
-
-if __name__ == "__main__":
- get_default_recipe()
- recipe = load_yaml('/home/shinchulwoo/recipe/test/test.yaml')
- separate_recipe_file_for_ks(recipe)
- print('test')
+ return yamlinfo
+
+YamlType = collections.namedtuple('YamlInfo', 'cachedir, configs, repos')
+def YamlInfo(cachedir, configs, repos):
+ return YamlType(cachedir, configs, repos)
\ No newline at end of file
# Contributors:
# - S-Core Co., Ltd
+from tic.utils.error import TICError
from kswriter.KSWriter import KSWriter, KSMetaError
class KSoption:
- def __init__(self):
- self.configsfile = '/home/shinchulwoo/project/meta-mobile/mobile.yaml'
- self.repofile = ['/home/shinchulwoo/project/meta-mobile/mobile-repos.yaml']
- self.target = '/home/shinchulwoo/project/meta-mobile/mobile-targets.yaml'
- self.external = ['/home/shinchulwoo/project/meta-mobile/ks']
- self.outdir = '/home/shinchulwoo/project/meta-mobile/__test'
+ def __init__(self, configs, repos, outdir):
+ self.configsfile = configs
+ self.repofile = [repos]
+ self.target = None
+ self.external = None
+ self.outdir = outdir
self.config = None
- self.packages = None
+ self.packages = False
self.targetdefs = None
-def kswriter():
+def kswriter(options):
try:
- options = KSoption()
ks = KSWriter(options.configsfile, options.repofile, options.outdir, options.config, options.packages, options.external, options.targetdefs, options.target)
ks.generate()
except KSMetaError as err:
- print('ERROR:', str(err))
+ raise TICError(str(err))
if __name__ == "__main__":
print('start')
try:
logger = logging.getLogger(__name__)
logger.info('%s - %s %s : data=%s' % (request.remote_addr, request.method, request.path, request.data))
-
+ exportInfo = json.loads(request.data)
+ type = request.args.get('format')
+ output = command.exports(type, exportInfo.get('recipe'), exportInfo.get('packages'), exportInfo.get('output'))
+ resp = makeresponse(output, None)
except error.TICError as err:
logger.error(err)
resp = makeresponse(str(err), err)
except Exception as ex:
logger.error(ex)
resp = makeresponse(str(ex), ex)
-
return resp
with app.test_request_context():
print(url_for('index'))
print(url_for('analysis'))
- app.run(host='0.0.0.0', port=port_num)
+ app.run(host='0.0.0.0', threaded=True, port=port_num)
def makeresponse(data, err):