1
2
3 import argparse
4 import sys
5 import ConfigParser
6
7 import subcommands
8 import copr_exceptions
9
10 __version__ = "0.2.0"
11 __description__ = "CLI tool to run copr"
12
13
15 """ Method called when the 'build' action has been selected by the
16 user.
17
18 :param args: argparse arguments provided by the user
19
20 """
21 subcommands.build(args.copr, args.pkgs,
22 args.memory, args.timeout, not args.nowait, chroots=args.chroots)
23
24
26 """ Method called when the 'create' action has been selected by the
27 user.
28
29 :param args: argparse arguments provided by the user
30
31 """
32 subcommands.create(args.name, args.chroots, args.description,
33 args.instructions, args.repos,
34 args.initial_pkgs)
35
36
38 """ Method called when the 'list' action has been selected by the
39 user.
40
41 :param args: argparse arguments provided by the user
42
43 """
44 subcommands.listcoprs(args.username)
45
46
49
51 """ Method called when the 'cancel' action has been selected by the
52 user.
53
54 :param args: argparse arguments provided by the user
55
56 """
57 subcommands.cancel(args.build_id)
58
60 """
61 Set the main arguments.
62 """
63 parser = argparse.ArgumentParser(prog="copr-cli")
64
65 parser.add_argument("--version", action="version",
66 version="copr-cli {0}".format(__version__))
67
68 subparsers = parser.add_subparsers(title="actions")
69
70
71 parser_list = subparsers.add_parser("list",
72 help="List all the copr of the "
73 "provided "
74 )
75 parser_list.add_argument("username", nargs="?",
76 help="The username that you would like to "
77 "list the copr of (defaults to current user)"
78 )
79 parser_list.set_defaults(func=action_list)
80
81
82 parser_create = subparsers.add_parser("create",
83 help="Create a new copr")
84 parser_create.add_argument("name",
85 help="The name of the copr to create")
86 parser_create.add_argument("--chroot", dest="chroots", action="append",
87 help="Chroot to use for this copr")
88 parser_create.add_argument("--repo", dest="repos", action="append",
89 help="Repository to add to this copr")
90 parser_create.add_argument("--initial-pkgs", dest="initial_pkgs",
91 action="append",
92 help="List of packages URL to build in this "
93 "new copr")
94 parser_create.add_argument("--description",
95 help="Description of the copr")
96 parser_create.add_argument("--instructions",
97 help="Instructions for the copr")
98 parser_create.set_defaults(func=action_create)
99
100
101 parser_build = subparsers.add_parser("build",
102 help="Build packages to a "
103 "specified copr")
104 parser_build.add_argument("copr",
105 help="The copr repo to build the package in. Can just name of project or even in format username/project."
106 )
107 parser_build.add_argument("pkgs", nargs="+",
108 help="URL of packages to build")
109 parser_build.add_argument("-r", "--chroot", dest="chroots", action="append",
110 help="If you don't need this build for all the project's chroots. You can use it several times for each chroot you need.")
111 parser_build.add_argument("--memory", dest="memory",
112 help="")
113 parser_build.add_argument("--timeout", dest="timeout",
114 help="")
115 parser_build.add_argument("--nowait", action="store_true", default=False,
116 help="Don't wait for build")
117 parser_build.set_defaults(func=action_build)
118
119
120 parser_build = subparsers.add_parser("status",
121 help="Get build status of build"
122 " specified by its ID")
123 parser_build.add_argument("build_id",
124 help="Build ID")
125 parser_build.set_defaults(func=action_status)
126
127
128 parser_build = subparsers.add_parser("cancel",
129 help="Cancel build specified by its ID")
130 parser_build.add_argument("build_id",
131 help="Build ID")
132 parser_build.set_defaults(func=action_cancel)
133
134 return parser
135
136
137 -def main(argv=sys.argv[1:]):
138 try:
139
140 parser = setup_parser()
141
142 arg = parser.parse_args()
143 arg.func(arg)
144 except KeyboardInterrupt:
145 sys.stderr.write("\nInterrupted by user.")
146 sys.exit(1)
147 except argparse.ArgumentTypeError, e:
148 sys.stderr.write("\nError: {0}".format(e))
149 sys.exit(2)
150 except copr_exceptions.CoprCliException, e:
151 sys.stderr.write("\nError: {0}\n".format(e))
152 sys.exit(3)
153 except ConfigParser.ParsingError, e:
154 sys.stderr.write("\nError: {0}\n".format(e))
155 sys.stderr.write("Lines in INI file should not be indented.\n")
156 sys.exit(4)
157
158
159
160
161
162 if __name__ == "__main__":
163 main()
164