[TIC-CORE] support caching for analysis data
[archive/20170607/tools/tic-core.git] / tic / parser / recipe_parser.py
index 7de426a..6ddd176 100644 (file)
 # 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(
@@ -30,7 +34,7 @@ def get_default_recipe():
             Baseline= 'tizen-3.0',
             Active= True,
             Mic2Options= '-f raw --fstab=uuid --copy-kernel --compress-disk-image=bz2 --generate-bmap',
-            Part='mobile-mbr',
+            Part='headless',
             Language= 'en_US.UTF-8',
             Keyboard= 'us',
             Timezone= 'Asia/Seoul',
@@ -46,58 +50,43 @@ def get_default_recipe():
             SaveRepos= False,
             UserGroups= "audio,video"
         ),
-        Emulator64wayland=dict(
-            Part='mobile-mbr',
+        Wayland=dict(
+            Part='headless',
             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'],
+            Groups=[],
             PostScripts=[],
             Repos= [],
             NoChrootScripts=[]
         ),
         Configurations=[
             dict(
-                Name='mobile-emulator64-wayland',
-                Architecture='x86_64',
+                Name='tizen-headless',
+                Architecture='armv7l',
                 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'],
+                Platform= 'Wayland',
+                Part= 'headless',
+                Mic2Options= '-f loop --pack-to=@NAME@.tar.gz',
+                FileName= 'tizen-headless-tm1',
+                Repos=['tizen-unified', 'tizen-base'],
+                Groups=[],
                 ExtraPackages= [],
                 RemovePackages=[]
             )
         ],
         Repositories=[
-            dict(Name='mobile-emulator64-wayland',
-                 Url='http://download.tizen.org/snapshots/tizen/mobile/latest/repos/emulator64-wayland/packages/',
+            dict(Name='tizen-unified',
+                 Url='http://download.tizen.org/live/devel:/Tizen:/Unified/standard/',
                  Options='--ssl_verify=no'),
-            dict(Name='base_emulator64',
-                 Url='http://download.tizen.org/snapshots/tizen/base/latest/repos/emulator64/packages/',
+            dict(Name='tizen-base',
+                 Url='http://download.tizen.org/snapshots/tizen/base/latest/repos/arm/packages/',
                  Options='--ssl_verify=no')
         ],
         Partitions=[
-            dict(Name='mobile-mbr',
-                 Contents='part / --fstype="ext4" --size=3584 --ondisk=sda --active --label platform --fsoptions=defaults,noatime')
+            dict(Name='headless',
+                 Contents='part / --size=2000 --ondisk mmcblk0p --fstype=ext4 --label=rootfs --extoptions=\"-J size=16\" \n\
+part /opt/ --size=1000 --ondisk mmcblk0p --fstype=ext4 --label=system-data --extoptions="-m 0" \n\
+part /boot/kernel/mod_tizen_tm1/lib/modules --size=12 --ondisk mmcblk0p --fstype=ext4 --label=modules \n')
         ]
     )
     return recipe
@@ -112,8 +101,8 @@ def load_yaml(path):
         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=[])
@@ -122,20 +111,30 @@ def separate_recipe_file_for_ks(recipe):
     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)
+    
+    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.safe_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:
-            yaml.dump(repos, outfile, default_flow_style=False)
+        with open(yamlinfo.repos, 'w') as outfile:
+            yaml.safe_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'])
@@ -143,17 +142,16 @@ def separate_recipe_file_for_ks(recipe):
     # 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