+#!/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 yaml
+from tic.utils import error
+from tic.utils.file import write
+
+def get_default_recipe():
+ recipe = dict(
+ Default=dict(
+ Baseline= 'tizen-3.0',
+ Active= True,
+ Mic2Options= '-f raw --fstab=uuid --copy-kernel --compress-disk-image=bz2 --generate-bmap',
+ Part='mobile-mbr',
+ Language= 'en_US.UTF-8',
+ Keyboard= 'us',
+ Timezone= 'Asia/Seoul',
+ RootPass= 'tizen',
+ DefaultUser= 'guest',
+ DefaultUserPass= 'tizen',
+ BootLoader= True,
+ BootloaderAppend= "rw vga=current splash rootwait rootfstype=ext4 plymouth.enable=0",
+ BootloaderTimeout= 3,
+ BootloaderOptions= '--ptable=gpt --menus="install:Wipe and Install:systemd.unit=system-installer.service:test"',
+ StartX= False,
+ Desktop= 'None',
+ SaveRepos= False,
+ UserGroups= "audio,video"
+ ),
+ Emulator64wayland=dict(
+ Part='mobile-mbr',
+ UserGroups='audio,video',
+ Groups=[
+ 'Generic Base',
+ 'Mobile Base',
+ 'Mobile Console Tools',
+ 'Mobile Adaptation',
+ 'Mobile Wayland',
+ 'Mobile Middleware',
+ 'Mobile Applications',
+ 'Generic Multimedia',
+ 'Mobile Multimedia',
+ 'Generic Desktop Applications',
+ 'Mobile Dali',
+ 'Mobile EFL',
+ 'Mobile Enlightenment',
+ 'Mobile Input Framework',
+ 'Mobile Connectivity Framework',
+ 'Mobile Bluetooth',
+ 'Mobile Web Framework',
+ 'Mobile Telephony'],
+ PostScripts=[],
+ Repos= [],
+ NoChrootScripts=[]
+ ),
+ Configurations=[
+ dict(
+ Name='mobile-emulator64-wayland',
+ Architecture='x86_64',
+ Schedule= "*",
+ Active= True,
+ Platform= 'Emulator64wayland',
+ Mic2Options= '-f loop --pack-to=@NAME@.tar.gz,',
+ FileName= 'mobile-emulator64-wayland',
+ Repos=['mobile-emulator64-wayland', 'base_emulator64'],
+ Groups=['Mobile Adaptation Emulator'],
+ ExtraPackages= [],
+ RemovePackages=[]
+ )
+ ],
+ Repositories=[
+ dict(Name='mobile-emulator64-wayland',
+ Url='http://download.tizen.org/snapshots/tizen/mobile/latest/repos/emulator64-wayland/packages/',
+ Options='--ssl_verify=no'),
+ dict(Name='base_emulator64',
+ Url='http://download.tizen.org/snapshots/tizen/base/latest/repos/emulator64/packages/',
+ Options='--ssl_verify=no')
+ ],
+ Partitions=[
+ dict(Name='mobile-mbr',
+ Contents='part / --fstype="ext4" --size=3584 --ondisk=sda --active --label platform --fsoptions=defaults,noatime')
+ ]
+ )
+ return recipe
+
+def load_yaml(path):
+ try:
+ with file(path) as f:
+ return yaml.load(f)
+ except IOError:
+ raise error.TICError('cannot read meta file: %s' % path)
+ except:
+ raise error.TICError('yaml format error of meta file: %s' % path)
+
+
+def separate_recipe_file_for_ks(recipe):
+ path = '/home/shinchulwoo/recipe/test'
+
+ # config.yaml
+ config = dict(Default=None, Configurations=[])
+ config['Default'] = recipe.get('Default')
+ # targets (only one target)
+ 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:
+ yaml.dump(config, outfile, default_flow_style=False)
+
+ # repo.yaml
+ if 'Repositories' in recipe:
+ repos = {}
+ repos['Repositories'] = recipe['Repositories']
+ with open(os.path.join(path, 'repos.yaml'), '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')
+ 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_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')