# 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