1
2
3 import argparse
4 import sys
5
6 import subcommands
7 import copr_exceptions
8
9 __version__ = '0.1.0'
10 __description__ = "CLI tool to run copr"
11
12
14 """ Method called when the 'build' action has been selected by the
15 user.
16
17 :param args: argparse arguments provided by the user
18
19 """
20 subcommands.build(args.copr, args.pkgs,
21 args.memory, args.timeout)
22
23
34
35
37 """ Method called when the 'list' action has been selected by the
38 user.
39
40 :param args: argparse arguments provided by the user
41
42 """
43 subcommands.listcoprs(args.username)
44
45
47 """
48 Set the main arguments.
49 """
50 parser = argparse.ArgumentParser(prog="copr-cli")
51
52 parser.add_argument('--version', action='version',
53 version='copr-cli %s' % (__version__))
54
55 subparsers = parser.add_subparsers(title='actions')
56
57
58 parser_list = subparsers.add_parser('list',
59 help='List all the copr of the '
60 'provided '
61 )
62 parser_list.add_argument("username", nargs='?',
63 help='The username that you would like to '
64 'list the copr of (defaults to current user)'
65 )
66 parser_list.set_defaults(func=action_list)
67
68
69 parser_create = subparsers.add_parser('create',
70 help='Create a new copr')
71 parser_create.add_argument('name',
72 help='The name of the copr to create')
73 parser_create.add_argument("--chroot", dest="chroots", action='append',
74 help="Chroot to use for this copr")
75 parser_create.add_argument('--repo', dest='repos', action='append',
76 help="Repository to add to this copr")
77 parser_create.add_argument('--initial-pkgs', dest='initial_pkgs',
78 action='append',
79 help="List of packages to build in this "
80 "new copr")
81 parser_create.add_argument('--description',
82 help="Description of the copr")
83 parser_create.add_argument('--instructions',
84 help="Instructions for the copr")
85 parser_create.set_defaults(func=action_create)
86
87
88 parser_build = subparsers.add_parser('build',
89 help='Build packages to a '
90 'specified copr')
91 parser_build.add_argument('copr',
92 help='The copr repo to build the package in'
93 )
94 parser_build.add_argument('pkgs', nargs='+', action='append')
95 parser_build.add_argument('--memory', dest='memory',
96 help="")
97 parser_build.add_argument('--timeout', dest='timeout',
98 help="")
99 parser_build.set_defaults(func=action_build)
100
101 return parser
102
103
104 -def main(argv=sys.argv[1:]):
105 """ Main function """
106 try:
107
108 parser = setup_parser()
109
110 arg = parser.parse_args()
111 arg.func(arg)
112 except KeyboardInterrupt:
113 print "\nInterrupted by user."
114 sys.exit(1)
115 except argparse.ArgumentTypeError, e:
116 print "\nError: {0}".format(e)
117 sys.exit(2)
118 except copr_exceptions.CoprCliException, e:
119 print "\nError: {0}".format(e)
120 sys.exit(3)
121
122
123
124
125
126 if __name__ == '__main__':
127 main()
128