7de426a6b2de9107fe1cca3ad93eccfc88d74cc0
[archive/20170607/tools/tic-core.git] / tic / parser / recipe_parser.py
1 #!/usr/bin/python
2 # Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
3 #
4 # Contact: 
5 # @author Chulwoo Shin <cw1.shin@samsung.com>
6
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
10 #
11 # http://www.apache.org/licenses/LICENSE-2.0
12 #
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.
18 #
19 # Contributors:
20 # - S-Core Co., Ltd
21
22 import os
23 import yaml
24 from tic.utils import error
25 from tic.utils.file import write
26
27 def get_default_recipe():
28     recipe = dict(
29         Default=dict(
30             Baseline= 'tizen-3.0',
31             Active= True,
32             Mic2Options= '-f raw --fstab=uuid --copy-kernel --compress-disk-image=bz2 --generate-bmap',
33             Part='mobile-mbr',
34             Language= 'en_US.UTF-8',
35             Keyboard= 'us',
36             Timezone= 'Asia/Seoul',
37             RootPass= 'tizen',
38             DefaultUser= 'guest',
39             DefaultUserPass= 'tizen',
40             BootLoader= True,
41             BootloaderAppend= "rw vga=current splash rootwait rootfstype=ext4 plymouth.enable=0",
42             BootloaderTimeout= 3,
43             BootloaderOptions= '--ptable=gpt --menus="install:Wipe and Install:systemd.unit=system-installer.service:test"',
44             StartX= False,
45             Desktop= 'None',
46             SaveRepos= False,
47             UserGroups= "audio,video"
48         ),
49         Emulator64wayland=dict(
50             Part='mobile-mbr',
51             UserGroups='audio,video',
52             Groups=[
53                 'Generic Base',
54                 'Mobile Base',
55                 'Mobile Console Tools',
56                 'Mobile Adaptation',
57                 'Mobile Wayland',
58                 'Mobile Middleware',
59                 'Mobile Applications',
60                 'Generic Multimedia',
61                 'Mobile Multimedia',
62                 'Generic Desktop Applications',
63                 'Mobile Dali',
64                 'Mobile EFL',
65                 'Mobile Enlightenment',
66                 'Mobile Input Framework',
67                 'Mobile Connectivity Framework',
68                 'Mobile Bluetooth',
69                 'Mobile Web Framework',
70                 'Mobile Telephony'],
71             PostScripts=[],
72             Repos= [],
73             NoChrootScripts=[]
74         ),
75         Configurations=[
76             dict(
77                 Name='mobile-emulator64-wayland',
78                 Architecture='x86_64',
79                 Schedule= "*",
80                 Active= True,
81                 Platform= 'Emulator64wayland',
82                 Mic2Options= '-f loop --pack-to=@NAME@.tar.gz,',
83                 FileName= 'mobile-emulator64-wayland',
84                 Repos=['mobile-emulator64-wayland', 'base_emulator64'],
85                 Groups=['Mobile Adaptation Emulator'],
86                 ExtraPackages= [],
87                 RemovePackages=[]
88             )
89         ],
90         Repositories=[
91             dict(Name='mobile-emulator64-wayland',
92                  Url='http://download.tizen.org/snapshots/tizen/mobile/latest/repos/emulator64-wayland/packages/',
93                  Options='--ssl_verify=no'),
94             dict(Name='base_emulator64',
95                  Url='http://download.tizen.org/snapshots/tizen/base/latest/repos/emulator64/packages/',
96                  Options='--ssl_verify=no')
97         ],
98         Partitions=[
99             dict(Name='mobile-mbr',
100                  Contents='part / --fstype="ext4" --size=3584 --ondisk=sda --active --label platform --fsoptions=defaults,noatime')
101         ]
102     )
103     return recipe
104
105 def load_yaml(path):
106     try:
107         with file(path) as f:
108             return yaml.load(f)
109     except IOError:
110         raise error.TICError('cannot read meta file: %s' % path)
111     except:
112         raise error.TICError('yaml format error of meta file: %s' % path)
113     
114
115 def separate_recipe_file_for_ks(recipe):
116     path = '/home/shinchulwoo/recipe/test'
117     
118     # config.yaml
119     config = dict(Default=None, Configurations=[])
120     config['Default'] = recipe.get('Default')
121     # targets (only one target)
122     config['Configurations'].append(recipe.get('Configurations')[0])
123     platform_name = config['Configurations'][0].get('Platform')
124     config[platform_name] = recipe.get(platform_name)
125     with open(os.path.join(path, 'config.yaml'), 'w') as outfile:
126         yaml.dump(config, outfile, default_flow_style=False)
127
128     # repo.yaml    
129     if 'Repositories' in recipe:
130         repos = {}
131         repos['Repositories'] = recipe['Repositories']
132         with open(os.path.join(path, 'repos.yaml'), 'w') as outfile:
133             yaml.dump(repos, outfile, default_flow_style=False)
134     
135     # partition info
136     if 'Partitions' in recipe:
137         for partition in recipe.get('Partitions'):
138             partition_path = os.path.join(path, 'partitions')
139             file_name = partition.get('Name')
140             temp = os.path.join(partition_path, file_name)
141             write(temp, partition['Contents'])
142     
143     # script.post
144     if 'PostScripts' in recipe:
145         for script in recipe.get('PostScripts'):
146             script_path = os.path.join(path, 'scripts')
147             script_type = script.get('Type')
148             if script_type and script_type == 'nochroot':
149                 file_name = '%s.nochroot' % script.get('Name')
150             else:
151                 file_name = '%s.post' % script.get('Name')
152             write(os.path.join(script_path, file_name), script['Contents'])
153
154 if __name__ == "__main__":
155     get_default_recipe()
156     recipe = load_yaml('/home/shinchulwoo/recipe/test/test.yaml')
157     separate_recipe_file_for_ks(recipe)
158     
159     print('test')