[TIC-CORE] support cli commands
[archive/20170607/tools/tic-core.git] / tic / command.py
index e506e6c..51f41cc 100644 (file)
 
 import os
 import logging
-import shutil
 
 from tic.dependency import analyze_dependency, get_installed_packages
 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.utils.file import copyfile
 from tic.repo import get_repodata_from_repos
 from tic.pykickstarter import KSoption, kswriter
+from tic.utils import process
 
 
 DEFAULT_CACHEDIR='/var/tmp/tic-core/cached'
@@ -77,12 +78,14 @@ def analyze(repo_list, recipe_list=None):
     
     return result
 
-def exports(export_type, recipe, packages, output):
+def exports(export_type, recipe, packages, outdir):
     logger = logging.getLogger(__name__)
+    
+    #TODO validation should be checked before request
     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:
@@ -116,7 +119,23 @@ def exports(export_type, recipe, packages, output):
         raise TICError('No ks file was created from kickstarter')
     
     # copy the ks to output directory
-    shutil.copy(kspath, output)
+    output=copyfile(kspath, outdir)
     logger.info('copy the ks file from %s to dst:%s', kspath, output)
     
     return output
+
+def createimage(recipes, ksfile, outdir):
+    logger = logging.getLogger(__name__)
+    
+    if recipes:
+        logger.info('the recipes option is not yet supported')
+        return
+    
+    if not os.path.exists(ksfile) or os.path.isdir(ksfile):
+        raise TICError('kickstart file does not exist')
+    
+    mic_command=['mic', 'cr', 'auto', ksfile]
+    if outdir:
+        mic_command.append('--outdir=%s' % outdir)
+    
+    process.run(mic_command, 2)