2 # Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
5 # @author Chulwoo Shin <cw1.shin@samsung.com>
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
11 # http://www.apache.org/licenses/LICENSE-2.0
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.
22 from argparse import ArgumentParser
23 from argparse import RawDescriptionHelpFormatter
27 from tic import command
28 from tic.utils import file
29 from tic.utils import error
30 from tic.server import tic_server
33 __date__ = '2016-11-07'
34 __updated__ = '2016-11-07'
37 program_name = os.path.basename(sys.argv[0])
38 program_version = "%s" % __version__
39 program_version_message = '%s %s' % (program_name, program_version)
40 program_shortdesc = 'tic-core is a tool for analyzing package dependencies and generating Image' #__import__('__main__').__doc__
41 program_epilog = "Try 'tic-core SUBCOMMAND --help' for help on a specific sub-command."
43 parser = ArgumentParser(description=program_shortdesc, epilog=program_epilog,
44 formatter_class=RawDescriptionHelpFormatter)
45 parser.add_argument('-v', '--version', action='version', version=program_version_message)
46 subparsers = parser.add_subparsers(dest='subparser_name', help='sub-command help')
48 # create the parser for the 'analyze' command
49 parser_analyze = subparsers.add_parser('analysis', help='analyze install-dependency of packages')
50 parser_analyze.add_argument('-r', "--repo", dest="repos", metavar="urls", nargs='+', help="The URL of repository [default: %(default)s]", required=True)
51 parser_analyze.add_argument('-o', "--output", dest="output", action="store", help="The result file is distributed in the output path", default=os.getcwd())
53 parser_download = subparsers.add_parser('download', help='download repodata from repositories')
54 parser_download.add_argument('-r', "--repo", dest="repos", metavar="urls", nargs='+', help="The URL of repository [default: %(default)s]", required=True)
55 parser_download.add_argument('-o', "--output", dest="output", action="store", help="The result file is distributed in the output path [default: %(default)s]")
57 parser_start = subparsers.add_parser('start', help='start the tic-core demon on system. port 59001 is used by default ')
58 parser_start.add_argument('-p', "--port", dest="port", action="store", help="port number", default=59001)
64 # Setup argument parser
65 parser = create_parser()
67 args = parser.parse_args(argv[1:])
69 if args.subparser_name == 'analysis':
70 view_data = command.analyze(args.repos, None)
71 file.write(args.output, json.dumps(view_data))
72 elif args.subparser_name == 'download':
74 elif args.subparser_name == 'start':
75 tic_server.start(args.port)
80 except KeyboardInterrupt:
81 ### handle keyboard interrupt ###
83 except error.TICError as err:
85 except Exception as e:
89 if __name__ == "__main__":
90 sys.exit(main(sys.argv))