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
37 """ Method called when the 'delete' action has been selected by the
38 user.
39
40 :param args: argparse arguments provided by the user
41 """
42 subcommands.delete(args.copr)
43
44
46 """ Method called when the 'list' action has been selected by the
47 user.
48
49 :param args: argparse arguments provided by the user
50
51 """
52 subcommands.listcoprs(args.username)
53
54
57
59 """ Method called when the 'cancel' action has been selected by the
60 user.
61
62 :param args: argparse arguments provided by the user
63
64 """
65 subcommands.cancel(args.build_id)
66
68 """
69 Set the main arguments.
70 """
71 parser = argparse.ArgumentParser(prog="copr-cli")
72
73 parser.add_argument("--version", action="version",
74 version="copr-cli {0}".format(__version__))
75
76 subparsers = parser.add_subparsers(title="actions")
77
78
79 parser_list = subparsers.add_parser("list",
80 help="List all the copr of the "
81 "provided "
82 )
83 parser_list.add_argument("username", nargs="?",
84 help="The username that you would like to "
85 "list the copr of (defaults to current user)"
86 )
87 parser_list.set_defaults(func=action_list)
88
89
90 parser_create = subparsers.add_parser("create",
91 help="Create a new copr")
92 parser_create.add_argument("name",
93 help="The name of the copr to create")
94 parser_create.add_argument("--chroot", dest="chroots", action="append",
95 help="Chroot to use for this copr")
96 parser_create.add_argument("--repo", dest="repos", action="append",
97 help="Repository to add to this copr")
98 parser_create.add_argument("--initial-pkgs", dest="initial_pkgs",
99 action="append",
100 help="List of packages URL to build in this "
101 "new copr")
102 parser_create.add_argument("--description",
103 help="Description of the copr")
104 parser_create.add_argument("--instructions",
105 help="Instructions for the copr")
106 parser_create.set_defaults(func=action_create)
107
108
109 parser_delete = subparsers.add_parser("delete",
110 help="Deletes the entire project")
111 parser_delete.add_argument("copr",
112 help="Name of your project to be deleted.")
113 parser_delete.set_defaults(func=action_delete)
114
115
116 parser_build = subparsers.add_parser("build",
117 help="Build packages to a "
118 "specified copr")
119 parser_build.add_argument("copr",
120 help="The copr repo to build the package in. Can just name of project or even in format username/project."
121 )
122 parser_build.add_argument("pkgs", nargs="+",
123 help="URL of packages to build")
124 parser_build.add_argument("-r", "--chroot", dest="chroots", action="append",
125 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.")
126 parser_build.add_argument("--memory", dest="memory",
127 help="")
128 parser_build.add_argument("--timeout", dest="timeout",
129 help="")
130 parser_build.add_argument("--nowait", action="store_true", default=False,
131 help="Don't wait for build")
132 parser_build.set_defaults(func=action_build)
133
134
135 parser_build = subparsers.add_parser("status",
136 help="Get build status of build"
137 " specified by its ID")
138 parser_build.add_argument("build_id",
139 help="Build ID")
140 parser_build.set_defaults(func=action_status)
141
142
143 parser_build = subparsers.add_parser("cancel",
144 help="Cancel build specified by its ID")
145 parser_build.add_argument("build_id",
146 help="Build ID")
147 parser_build.set_defaults(func=action_cancel)
148
149 return parser
150
151
152 -def main(argv=sys.argv[1:]):
153 try:
154
155 parser = setup_parser()
156
157 arg = parser.parse_args()
158 arg.func(arg)
159 except KeyboardInterrupt:
160 sys.stderr.write("\nInterrupted by user.")
161 sys.exit(1)
162 except copr_exceptions.CoprCliRequestException, e:
163 sys.stderr.write("\nSomething went wrong:")
164 sys.stderr.write("\nError: {0}\n".format(e))
165 sys.exit(1)
166 except argparse.ArgumentTypeError, e:
167 sys.stderr.write("\nError: {0}".format(e))
168 sys.exit(2)
169 except copr_exceptions.CoprCliException, e:
170 sys.stderr.write("\nError: {0}\n".format(e))
171 sys.exit(3)
172 except ConfigParser.ParsingError, e:
173 sys.stderr.write("\nError: {0}\n".format(e))
174 sys.stderr.write("Lines in INI file should not be indented.\n")
175 sys.exit(3)
176 except copr_exceptions.CoprCliBuildException, e:
177 sys.stderr.write("\nBuild error: {0}\n".format(e))
178 sys.exit(4)
179 except copr_exceptions.CoprCliUnknownResponseException, e:
180 sys.stderr.write("\nError: {0}\n".format(e))
181 sys.exit(5)
182
183
184
185
186
187 if __name__ == "__main__":
188 main()
189