[TIC-Core] UI element HF and QT implemented. GBS support of category
[archive/20170607/tools/tic-core.git] / tools / tic-core
index 8400c77..0bc0f7f 100644 (file)
@@ -1,14 +1,11 @@
 #!/usr/bin/python
-# Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
+# Copyright (c) 2016 Samsung Electronics Co., Ltd
 #
-# Contact: 
-# @author Chulwoo Shin <cw1.shin@samsung.com>
-# 
-# Licensed under the Apache License, Version 2.0 (the "License");
+# Licensed under the Flora License, Version 1.1 (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
+#     http://floralicense.org/license/
 #
 # Unless required by applicable law or agreed to in writing, software
 # distributed under the License is distributed on an "AS IS" BASIS,
@@ -30,6 +27,7 @@ from tic.utils import log
 from tic.utils import file
 from tic.utils import error
 from tic.server import tic_server
+from tic.config import configmgr
 
 __version__ = 0.1
 __date__ = '2016-11-07'
@@ -48,16 +46,23 @@ def create_parser():
     subparsers = parser.add_subparsers(dest='subparser_name', help='sub-command help')
         
     # create the parser for the 'analyze' command
-    parser_analyze = subparsers.add_parser('analysis', help='analyze install-dependency of packages')
-    parser_analyze.add_argument('-r', "--repo", dest="repos", metavar="urls", nargs='+', help="The URL of repository [default: %(default)s]", required=True)
-    parser_analyze.add_argument('-o', "--output", dest="output", action="store", help="The result file is distributed in the output path", default=os.getcwd())
+    parser_analyze = subparsers.add_parser('analyze', help='analyze install-dependency of packages')
+    parser_analyze.add_argument('-r', "--repos", dest="repos", metavar="urls", nargs='+', help="The URL of repository [default: %(default)s]")
+    parser_analyze.add_argument('-c', "--recipes", dest="recipes", metavar="paths", nargs='+', help="The path of recipe")
+    parser_analyze.add_argument('-o', "--outdir", dest="outdir", action="store", help="The result file is distributed in the outdir path", default=os.getcwd())
+    # create the parser for the 'export' command
+    parser_export = subparsers.add_parser('export', help='export files')
+    parser_export.add_argument('-f', "--format", dest="format", metavar="recipe/ks", help="exports file format", required=True)
+    parser_export.add_argument('-c', "--recipes", dest="recipes", metavar="paths", nargs='+', help="recipe files")
+    parser_export.add_argument('-o', "--outdir", dest="outdir", action="store", help="export file output directory", default=os.getcwd())
+    # create the parser for the 'create' command
+    parser_create = subparsers.add_parser('createimage', help='create an image for tizen')
+    parser_create.add_argument('-c', "--recipes", dest="recipes", metavar="recipes", nargs='+', help="recipe files to be used for image creation")
+    parser_create.add_argument('-k', "--ks", dest="kickstart", metavar="kickstart", help="ks file to be used for image creation")
+    parser_create.add_argument('-o', "--outdir", dest="outdir", action="store", help="image output directory", default=os.getcwd())
     
-    parser_download = subparsers.add_parser('download', help='download repodata from repositories')
-    parser_download.add_argument('-r', "--repo", dest="repos", metavar="urls", nargs='+', help="The URL of repository [default: %(default)s]", required=True)
-    parser_download.add_argument('-o', "--output", dest="output", action="store", help="The result file is distributed in the output path [default: %(default)s]")
-    
-    parser_start = subparsers.add_parser('start', help='start the tic-core demon on system. port 59001 is used by default ')
-    parser_start.add_argument('-p', "--port", dest="port", action="store", help="port number", default=59001)
+    parser_start = subparsers.add_parser('start', help='start the tic-core demon on system.')
+    parser_start.add_argument('-p', "--port", dest="port", action="store", help="port number")
     
     return parser
 
@@ -69,12 +74,24 @@ def main(argv):
         # Process arguments
         args = parser.parse_args(argv[1:])
         
-        if args.subparser_name == 'analysis':
-            view_data = command.analyze(args.repos, None)
-            file.write(args.output, json.dumps(view_data))
-        elif args.subparser_name == 'download':
-            pass
+        if args.subparser_name == 'analyze':
+            view_data = command.analyze(args.repos, args.recipes)
+            output_dir=os.path.abspath(os.path.expanduser(args.outdir))
+            file.write(os.path.join(output_dir, 'viewdata.json'), json.dumps(view_data))
+        elif args.subparser_name == 'export':
+            #TODO Temporary code(should be deleted)
+            recipes={'name':'default'}
+            packages=['attr', 'filesystem']
+            output=command.exports(args.format, recipes, packages, args.outdir)
+            logger.info("export the %s file: %s", args.format, output)
+        elif args.subparser_name == 'createimage':
+            if args.recipes or args.kickstart:
+                command.createimage(args.recipes, args.kickstart, args.outdir)
+            else:
+                logger.info('kickstart or recipes file is required')
         elif args.subparser_name == 'start':
+            if not args.port:
+                args.port = configmgr.server['port']
             tic_server.start(args.port)
         return 0
     except KeyboardInterrupt: