]>
Commit | Line | Data |
---|---|---|
47a4cb89 | 1 | #!/usr/bin/python |
b792d887 MT |
2 | ############################################################################### |
3 | # # | |
4 | # Pakfire - The IPFire package management system # | |
5 | # Copyright (C) 2011 Pakfire development team # | |
6 | # # | |
7 | # This program is free software: you can redistribute it and/or modify # | |
8 | # it under the terms of the GNU General Public License as published by # | |
9 | # the Free Software Foundation, either version 3 of the License, or # | |
10 | # (at your option) any later version. # | |
11 | # # | |
12 | # This program is distributed in the hope that it will be useful, # | |
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # | |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | |
15 | # GNU General Public License for more details. # | |
16 | # # | |
17 | # You should have received a copy of the GNU General Public License # | |
18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. # | |
19 | # # | |
20 | ############################################################################### | |
47a4cb89 MT |
21 | |
22 | import argparse | |
936f6b37 | 23 | import os |
47a4cb89 MT |
24 | import sys |
25 | ||
60845a36 | 26 | import logger |
47a4cb89 | 27 | import packages |
fa6d335b | 28 | import repository |
677ff42a | 29 | import server |
e9c20259 | 30 | import util |
47a4cb89 | 31 | |
18edfe75 | 32 | import pakfire.api as pakfire |
47a4cb89 MT |
33 | from constants import * |
34 | from i18n import _ | |
35 | ||
60845a36 MT |
36 | # Initialize a very simple logging that is removed when a Pakfire instance |
37 | # is started. | |
38 | logger.setup_logging() | |
39 | ||
47a4cb89 | 40 | class Cli(object): |
47a4cb89 MT |
41 | def __init__(self): |
42 | self.parser = argparse.ArgumentParser( | |
43 | description = _("Pakfire command line interface."), | |
44 | ) | |
45 | ||
46 | self.parse_common_arguments() | |
47 | ||
2ba449f0 | 48 | self.parser.add_argument("--root", metavar="PATH", |
d2e26956 | 49 | default="/", |
47a4cb89 MT |
50 | help=_("The path where pakfire should operate in.")) |
51 | ||
52 | # Add sub-commands. | |
53 | self.sub_commands = self.parser.add_subparsers() | |
54 | ||
55 | self.parse_command_install() | |
5e87fa4f | 56 | self.parse_command_localinstall() |
a39fd08b | 57 | self.parse_command_remove() |
47a4cb89 MT |
58 | self.parse_command_info() |
59 | self.parse_command_search() | |
e38914be | 60 | self.parse_command_check_update() |
47a4cb89 | 61 | self.parse_command_update() |
fa6d335b | 62 | self.parse_command_provides() |
c1962d40 | 63 | self.parse_command_grouplist() |
ce2764c1 | 64 | self.parse_command_groupinstall() |
67bc4528 | 65 | self.parse_command_repolist() |
31267a64 | 66 | self.parse_command_clean() |
35d89fd7 | 67 | self.parse_command_check() |
b25a3d84 | 68 | self.parse_command_resolvdep() |
47a4cb89 MT |
69 | |
70 | # Finally parse all arguments from the command line and save them. | |
71 | self.args = self.parser.parse_args() | |
72 | ||
47a4cb89 | 73 | self.action2func = { |
5e87fa4f MT |
74 | "install" : self.handle_install, |
75 | "localinstall" : self.handle_localinstall, | |
a39fd08b | 76 | "remove" : self.handle_remove, |
e38914be | 77 | "check_update" : self.handle_check_update, |
5e87fa4f MT |
78 | "update" : self.handle_update, |
79 | "info" : self.handle_info, | |
80 | "search" : self.handle_search, | |
fa6d335b | 81 | "provides" : self.handle_provides, |
c1962d40 | 82 | "grouplist" : self.handle_grouplist, |
ce2764c1 | 83 | "groupinstall" : self.handle_groupinstall, |
67bc4528 | 84 | "repolist" : self.handle_repolist, |
31267a64 | 85 | "clean_all" : self.handle_clean_all, |
35d89fd7 | 86 | "check" : self.handle_check, |
b25a3d84 | 87 | "resolvdep" : self.handle_resolvdep, |
47a4cb89 MT |
88 | } |
89 | ||
7c8f2953 MT |
90 | @property |
91 | def pakfire_args(self): | |
6557ff4c MT |
92 | ret = { "mode" : "normal" } |
93 | ||
2ba449f0 MT |
94 | if hasattr(self.args, "root"): |
95 | ret["path"] = self.args.root | |
f9a012a8 MT |
96 | |
97 | if hasattr(self.args, "disable_repo"): | |
98 | ret["disable_repos"] = self.args.disable_repo | |
99 | ||
100 | if hasattr(self.args, "enable_repo"): | |
101 | ret["enable_repos"] = self.args.enable_repo | |
102 | ||
6a509182 MT |
103 | if hasattr(self.args, "offline"): |
104 | ret["offline"] = self.args.offline | |
105 | ||
f9a012a8 | 106 | return ret |
7c8f2953 | 107 | |
47a4cb89 | 108 | def parse_common_arguments(self): |
50381f5c MT |
109 | self.parser.add_argument("--version", action="version", |
110 | version="%(prog)s " + PAKFIRE_VERSION) | |
111 | ||
47a4cb89 MT |
112 | self.parser.add_argument("-v", "--verbose", action="store_true", |
113 | help=_("Enable verbose output.")) | |
114 | ||
115 | self.parser.add_argument("-c", "--config", nargs="?", | |
116 | help=_("Path to a configuration file to load.")) | |
117 | ||
f781b1ab MT |
118 | self.parser.add_argument("--disable-repo", nargs="*", metavar="REPO", |
119 | help=_("Disable a repository temporarily.")) | |
120 | ||
f9a012a8 MT |
121 | self.parser.add_argument("--enabled-repo", nargs="*", metavar="REPO", |
122 | help=_("Enable a repository temporarily.")) | |
123 | ||
6a509182 MT |
124 | self.parser.add_argument("--offline", action="store_true", |
125 | help=_("Run pakfire in offline mode.")) | |
126 | ||
47a4cb89 MT |
127 | def parse_command_install(self): |
128 | # Implement the "install" command. | |
129 | sub_install = self.sub_commands.add_parser("install", | |
130 | help=_("Install one or more packages to the system.")) | |
131 | sub_install.add_argument("package", nargs="+", | |
132 | help=_("Give name of at least one package to install.")) | |
133 | sub_install.add_argument("action", action="store_const", const="install") | |
134 | ||
5e87fa4f MT |
135 | def parse_command_localinstall(self): |
136 | # Implement the "localinstall" command. | |
137 | sub_install = self.sub_commands.add_parser("localinstall", | |
138 | help=_("Install one or more packages from the filesystem.")) | |
139 | sub_install.add_argument("package", nargs="+", | |
140 | help=_("Give filename of at least one package.")) | |
141 | sub_install.add_argument("action", action="store_const", const="localinstall") | |
142 | ||
a39fd08b MT |
143 | def parse_command_remove(self): |
144 | # Implement the "remove" command. | |
145 | sub_remove = self.sub_commands.add_parser("remove", | |
146 | help=_("Remove one or more packages from the system.")) | |
147 | sub_remove.add_argument("package", nargs="+", | |
148 | help=_("Give name of at least one package to remove.")) | |
149 | sub_remove.add_argument("action", action="store_const", const="remove") | |
150 | ||
05fb1da0 MT |
151 | @staticmethod |
152 | def _parse_command_update(parser): | |
153 | parser.add_argument("package", nargs="*", | |
154 | help=_("Give a name of a package to update or leave emtpy for all.")) | |
155 | parser.add_argument("--exclude", "-x", nargs="+", | |
156 | help=_("Exclude package from update.")) | |
157 | parser.add_argument("--allow-vendorchange", action="store_true", | |
158 | help=_("Allow changing the vendor of packages.")) | |
159 | parser.add_argument("--allow-archchange", action="store_true", | |
160 | help=_("Allow changing the architecture of packages.")) | |
161 | ||
47a4cb89 MT |
162 | def parse_command_update(self): |
163 | # Implement the "update" command. | |
164 | sub_update = self.sub_commands.add_parser("update", | |
165 | help=_("Update the whole system or one specific package.")) | |
47a4cb89 | 166 | sub_update.add_argument("action", action="store_const", const="update") |
05fb1da0 | 167 | self._parse_command_update(sub_update) |
47a4cb89 | 168 | |
e38914be MT |
169 | def parse_command_check_update(self): |
170 | # Implement the "check-update" command. | |
171 | sub_check_update = self.sub_commands.add_parser("check-update", | |
172 | help=_("Check, if there are any updates available.")) | |
e38914be | 173 | sub_check_update.add_argument("action", action="store_const", const="check_update") |
05fb1da0 | 174 | self._parse_command_update(sub_check_update) |
e38914be | 175 | |
47a4cb89 MT |
176 | def parse_command_info(self): |
177 | # Implement the "info" command. | |
178 | sub_info = self.sub_commands.add_parser("info", | |
179 | help=_("Print some information about the given package(s).")) | |
180 | sub_info.add_argument("package", nargs="+", | |
181 | help=_("Give at least the name of one package.")) | |
182 | sub_info.add_argument("action", action="store_const", const="info") | |
183 | ||
184 | def parse_command_search(self): | |
185 | # Implement the "search" command. | |
186 | sub_search = self.sub_commands.add_parser("search", | |
187 | help=_("Search for a given pattern.")) | |
188 | sub_search.add_argument("pattern", | |
189 | help=_("A pattern to search for.")) | |
190 | sub_search.add_argument("action", action="store_const", const="search") | |
191 | ||
fa6d335b MT |
192 | def parse_command_provides(self): |
193 | # Implement the "provides" command | |
194 | sub_provides = self.sub_commands.add_parser("provides", | |
195 | help=_("Get a list of packages that provide a given file or feature.")) | |
196 | sub_provides.add_argument("pattern", nargs="+", | |
197 | help=_("File or feature to search for.")) | |
198 | sub_provides.add_argument("action", action="store_const", const="provides") | |
199 | ||
c1962d40 MT |
200 | def parse_command_grouplist(self): |
201 | # Implement the "grouplist" command | |
202 | sub_grouplist = self.sub_commands.add_parser("grouplist", | |
203 | help=_("Get list of packages that belong to the given group.")) | |
204 | sub_grouplist.add_argument("group", nargs=1, | |
205 | help=_("Group name to search for.")) | |
206 | sub_grouplist.add_argument("action", action="store_const", const="grouplist") | |
207 | ||
ce2764c1 MT |
208 | def parse_command_groupinstall(self): |
209 | # Implement the "grouplist" command | |
210 | sub_groupinstall = self.sub_commands.add_parser("groupinstall", | |
211 | help=_("Install all packages that belong to the given group.")) | |
212 | sub_groupinstall.add_argument("group", nargs=1, | |
213 | help=_("Group name.")) | |
214 | sub_groupinstall.add_argument("action", action="store_const", const="groupinstall") | |
215 | ||
67bc4528 MT |
216 | def parse_command_repolist(self): |
217 | # Implement the "repolist" command | |
218 | sub_repolist = self.sub_commands.add_parser("repolist", | |
219 | help=_("List all currently enabled repositories.")) | |
220 | sub_repolist.add_argument("action", action="store_const", const="repolist") | |
ce2764c1 | 221 | |
31267a64 MT |
222 | def parse_command_clean(self): |
223 | sub_clean = self.sub_commands.add_parser("clean", help=_("Cleanup commands.")) | |
224 | ||
225 | sub_clean_commands = sub_clean.add_subparsers() | |
226 | ||
227 | self.parse_command_clean_all(sub_clean_commands) | |
228 | ||
229 | def parse_command_clean_all(self, sub_commands): | |
230 | sub_create = sub_commands.add_parser("all", | |
231 | help=_("Cleanup all temporary files.")) | |
232 | sub_create.add_argument("action", action="store_const", const="clean_all") | |
233 | ||
35d89fd7 MT |
234 | def parse_command_check(self): |
235 | # Implement the "check" command | |
236 | sub_check = self.sub_commands.add_parser("check", | |
237 | help=_("Check the system for any errors.")) | |
238 | sub_check.add_argument("action", action="store_const", const="check") | |
239 | ||
b25a3d84 MT |
240 | def parse_command_resolvdep(self): |
241 | # Implement the "resolvdep" command. | |
242 | sub_resolvdep = self.sub_commands.add_parser("resolvdep", | |
243 | help=_("Check the dependencies for a particular package.")) | |
244 | sub_resolvdep.add_argument("package", nargs="+", | |
245 | help=_("Give name of at least one package to check.")) | |
246 | sub_resolvdep.add_argument("action", action="store_const", const="resolvdep") | |
247 | ||
47a4cb89 MT |
248 | def run(self): |
249 | action = self.args.action | |
250 | ||
251 | if not self.action2func.has_key(action): | |
252 | raise | |
253 | ||
254 | try: | |
255 | func = self.action2func[action] | |
256 | except KeyError: | |
257 | raise # XXX catch and return better error message | |
258 | ||
259 | return func() | |
260 | ||
9afa5620 | 261 | def handle_info(self, long=False): |
7c8f2953 | 262 | pkgs = pakfire.info(self.args.package, **self.pakfire_args) |
47a4cb89 | 263 | |
7c8f2953 MT |
264 | for pkg in pkgs: |
265 | print pkg.dump(long=long) | |
47a4cb89 MT |
266 | |
267 | def handle_search(self): | |
7c8f2953 | 268 | pkgs = pakfire.search(self.args.pattern, **self.pakfire_args) |
47a4cb89 MT |
269 | |
270 | for pkg in pkgs: | |
271 | print pkg.dump(short=True) | |
272 | ||
05fb1da0 MT |
273 | def handle_update(self, **args): |
274 | args.update(self.pakfire_args) | |
275 | ||
276 | pakfire.update(self.args.package, excludes=self.args.exclude, | |
277 | allow_vendorchange=self.args.allow_vendorchange, | |
278 | allow_archchange=self.args.allow_archchange, | |
279 | **args) | |
47a4cb89 | 280 | |
e38914be | 281 | def handle_check_update(self): |
05fb1da0 | 282 | self.handle_update(check=True) |
e38914be | 283 | |
e0b99370 MT |
284 | def handle_install(self): |
285 | pakfire.install(self.args.package, **self.pakfire_args) | |
5e87fa4f MT |
286 | |
287 | def handle_localinstall(self): | |
e0b99370 | 288 | pakfire.localinstall(self.args.package, **self.pakfire_args) |
5e87fa4f | 289 | |
a39fd08b MT |
290 | def handle_remove(self): |
291 | pakfire.remove(self.args.package, **self.pakfire_args) | |
292 | ||
fa6d335b | 293 | def handle_provides(self): |
7c8f2953 | 294 | pkgs = pakfire.provides(self.args.pattern, **self.pakfire_args) |
fa6d335b MT |
295 | |
296 | for pkg in pkgs: | |
297 | print pkg.dump() | |
298 | ||
c1962d40 | 299 | def handle_grouplist(self): |
7c8f2953 | 300 | pkgs = pakfire.grouplist(self.args.group[0], **self.pakfire_args) |
c1962d40 MT |
301 | |
302 | for pkg in pkgs: | |
303 | print " * %s" % pkg | |
304 | ||
ce2764c1 | 305 | def handle_groupinstall(self): |
7c8f2953 | 306 | pakfire.groupinstall(self.args.group[0], **self.pakfire_args) |
ce2764c1 | 307 | |
67bc4528 | 308 | def handle_repolist(self): |
7c8f2953 | 309 | repos = pakfire.repo_list(**self.pakfire_args) |
67bc4528 | 310 | |
c605d735 | 311 | FORMAT = " %-20s %8s %12s %12s " |
67bc4528 | 312 | |
c605d735 | 313 | title = FORMAT % (_("Repository"), _("Enabled"), _("Priority"), _("Packages")) |
67bc4528 MT |
314 | print title |
315 | print "=" * len(title) # spacing line | |
316 | ||
317 | for repo in repos: | |
318 | # Skip the installed repository. | |
319 | if repo.name == "installed": | |
320 | continue | |
321 | ||
c605d735 | 322 | print FORMAT % (repo.name, repo.enabled, repo.priority, len(repo)) |
67bc4528 | 323 | |
31267a64 MT |
324 | def handle_clean_all(self): |
325 | print _("Cleaning up everything...") | |
326 | ||
327 | pakfire.clean_all(**self.pakfire_args) | |
328 | ||
35d89fd7 MT |
329 | def handle_check(self): |
330 | pakfire.check(**self.pakfire_args) | |
331 | ||
b25a3d84 MT |
332 | def handle_resolvdep(self): |
333 | pakfire.resolvdep(self.args.package, **self.pakfire_args) | |
334 | ||
47a4cb89 MT |
335 | |
336 | class CliBuilder(Cli): | |
337 | def __init__(self): | |
936f6b37 MT |
338 | # Check if we are already running in a pakfire container. In that |
339 | # case, we cannot start another pakfire-builder. | |
340 | if os.environ.get("container", None) == "pakfire-builder": | |
341 | raise PakfireContainerError, _("You cannot run pakfire-builder in a pakfire chroot.") | |
342 | ||
47a4cb89 MT |
343 | self.parser = argparse.ArgumentParser( |
344 | description = _("Pakfire builder command line interface."), | |
345 | ) | |
346 | ||
347 | self.parse_common_arguments() | |
348 | ||
349 | # Add sub-commands. | |
350 | self.sub_commands = self.parser.add_subparsers() | |
351 | ||
352 | self.parse_command_build() | |
353 | self.parse_command_dist() | |
354 | self.parse_command_info() | |
355 | self.parse_command_search() | |
356 | self.parse_command_shell() | |
357 | self.parse_command_update() | |
4fbd4216 | 358 | self.parse_command_provides() |
2c84aceb | 359 | self.parse_command_grouplist() |
67bc4528 | 360 | self.parse_command_repolist() |
31267a64 | 361 | self.parse_command_clean() |
b25a3d84 | 362 | self.parse_command_resolvdep() |
47a4cb89 MT |
363 | |
364 | # Finally parse all arguments from the command line and save them. | |
365 | self.args = self.parser.parse_args() | |
366 | ||
47a4cb89 | 367 | self.action2func = { |
fa6d335b MT |
368 | "build" : self.handle_build, |
369 | "dist" : self.handle_dist, | |
370 | "update" : self.handle_update, | |
371 | "info" : self.handle_info, | |
372 | "search" : self.handle_search, | |
373 | "shell" : self.handle_shell, | |
4fbd4216 | 374 | "provides" : self.handle_provides, |
2c84aceb | 375 | "grouplist" : self.handle_grouplist, |
67bc4528 | 376 | "repolist" : self.handle_repolist, |
31267a64 | 377 | "clean_all" : self.handle_clean_all, |
b25a3d84 | 378 | "resolvdep" : self.handle_resolvdep, |
47a4cb89 MT |
379 | } |
380 | ||
7c8f2953 MT |
381 | @property |
382 | def pakfire_args(self): | |
6557ff4c | 383 | ret = { "mode" : "builder" } |
f9a012a8 MT |
384 | |
385 | if hasattr(self.args, "disable_repo"): | |
386 | ret["disable_repos"] = self.args.disable_repo | |
387 | ||
388 | if hasattr(self.args, "enable_repo"): | |
389 | ret["enable_repos"] = self.args.enable_repo | |
390 | ||
6a509182 MT |
391 | if hasattr(self.args, "offline"): |
392 | ret["offline"] = self.args.offline | |
393 | ||
f9a012a8 | 394 | return ret |
7c8f2953 | 395 | |
47a4cb89 MT |
396 | def parse_command_update(self): |
397 | # Implement the "update" command. | |
398 | sub_update = self.sub_commands.add_parser("update", | |
399 | help=_("Update the package indexes.")) | |
400 | sub_update.add_argument("action", action="store_const", const="update") | |
401 | ||
402 | def parse_command_build(self): | |
403 | # Implement the "build" command. | |
404 | sub_build = self.sub_commands.add_parser("build", | |
405 | help=_("Build one or more packages.")) | |
406 | sub_build.add_argument("package", nargs=1, | |
407 | help=_("Give name of at least one package to build.")) | |
408 | sub_build.add_argument("action", action="store_const", const="build") | |
409 | ||
410 | sub_build.add_argument("-a", "--arch", | |
411 | help=_("Build the package for the given architecture.")) | |
412 | sub_build.add_argument("--resultdir", nargs="?", | |
413 | help=_("Path were the output files should be copied to.")) | |
f22069bb MT |
414 | sub_build.add_argument("-m", "--mode", nargs="?", default="development", |
415 | help=_("Mode to run in. Is either 'release' or 'development' (default).")) | |
1710ccec MT |
416 | sub_build.add_argument("--after-shell", action="store_true", |
417 | help=_("Run a shell after a successful build.")) | |
47a4cb89 MT |
418 | |
419 | def parse_command_shell(self): | |
420 | # Implement the "shell" command. | |
421 | sub_shell = self.sub_commands.add_parser("shell", | |
422 | help=_("Go into a shell.")) | |
042266f3 | 423 | sub_shell.add_argument("package", nargs="?", |
47a4cb89 MT |
424 | help=_("Give name of a package.")) |
425 | sub_shell.add_argument("action", action="store_const", const="shell") | |
426 | ||
427 | sub_shell.add_argument("-a", "--arch", | |
428 | help=_("Emulated architecture in the shell.")) | |
6ee3d6b9 MT |
429 | sub_shell.add_argument("-m", "--mode", nargs="?", default="development", |
430 | help=_("Mode to run in. Is either 'release' or 'development' (default).")) | |
47a4cb89 MT |
431 | |
432 | def parse_command_dist(self): | |
433 | # Implement the "dist" command. | |
434 | sub_dist = self.sub_commands.add_parser("dist", | |
435 | help=_("Generate a source package.")) | |
e412b8dc MT |
436 | sub_dist.add_argument("package", nargs="+", |
437 | help=_("Give name(s) of a package(s).")) | |
47a4cb89 MT |
438 | sub_dist.add_argument("action", action="store_const", const="dist") |
439 | ||
440 | sub_dist.add_argument("--resultdir", nargs="?", | |
441 | help=_("Path were the output files should be copied to.")) | |
442 | ||
9afa5620 MT |
443 | def handle_info(self): |
444 | Cli.handle_info(self, long=True) | |
445 | ||
47a4cb89 | 446 | def handle_build(self): |
47a4cb89 MT |
447 | # Get the package descriptor from the command line options |
448 | pkg = self.args.package[0] | |
449 | ||
450 | # Check, if we got a regular file | |
451 | if os.path.exists(pkg): | |
452 | pkg = os.path.abspath(pkg) | |
453 | ||
47a4cb89 | 454 | else: |
7c8f2953 | 455 | raise FileNotFoundError, pkg |
47a4cb89 | 456 | |
7c8f2953 MT |
457 | # Create distribution configuration from command line. |
458 | distro_config = { | |
459 | "arch" : self.args.arch, | |
460 | } | |
461 | ||
c07a3ca7 MT |
462 | pakfire.build(pkg, builder_mode=self.args.mode, |
463 | distro_config=distro_config, resultdirs=[self.args.resultdir,], | |
1710ccec | 464 | shell=True, after_shell=self.args.after_shell, **self.pakfire_args) |
47a4cb89 MT |
465 | |
466 | def handle_shell(self): | |
042266f3 MT |
467 | pkg = None |
468 | ||
47a4cb89 | 469 | # Get the package descriptor from the command line options |
042266f3 | 470 | if self.args.package: |
ad1b844f | 471 | pkg = self.args.package |
47a4cb89 | 472 | |
7c8f2953 MT |
473 | # Check, if we got a regular file |
474 | if os.path.exists(pkg): | |
475 | pkg = os.path.abspath(pkg) | |
47a4cb89 | 476 | |
7c8f2953 MT |
477 | else: |
478 | raise FileNotFoundError, pkg | |
47a4cb89 | 479 | |
7c8f2953 MT |
480 | # Create distribution configuration from command line. |
481 | distro_config = { | |
482 | "arch" : self.args.arch, | |
483 | } | |
47a4cb89 | 484 | |
6ee3d6b9 MT |
485 | pakfire.shell(pkg, builder_mode=self.args.mode, |
486 | distro_config=distro_config, **self.pakfire_args) | |
47a4cb89 MT |
487 | |
488 | def handle_dist(self): | |
e412b8dc MT |
489 | # Get the packages from the command line options |
490 | pkgs = [] | |
47a4cb89 | 491 | |
e412b8dc MT |
492 | for pkg in self.args.package: |
493 | # Check, if we got a regular file | |
494 | if os.path.exists(pkg): | |
495 | pkg = os.path.abspath(pkg) | |
7c8f2953 | 496 | pkgs.append(pkg) |
47a4cb89 | 497 | |
e412b8dc | 498 | else: |
7c8f2953 MT |
499 | raise FileNotFoundError, pkg |
500 | ||
6519843a MT |
501 | pakfire.dist(pkgs, resultdirs=[self.args.resultdir,], |
502 | **self.pakfire_args) | |
47a4cb89 | 503 | |
c605d735 MT |
504 | def handle_provides(self): |
505 | pkgs = pakfire.provides(self.args.pattern, **self.pakfire_args) | |
506 | ||
507 | for pkg in pkgs: | |
508 | print pkg.dump(long=True) | |
509 | ||
47a4cb89 | 510 | |
3ad4bb5a | 511 | class CliServer(Cli): |
677ff42a MT |
512 | def __init__(self): |
513 | self.parser = argparse.ArgumentParser( | |
3ad4bb5a | 514 | description = _("Pakfire server command line interface."), |
677ff42a MT |
515 | ) |
516 | ||
517 | self.parse_common_arguments() | |
518 | ||
519 | # Add sub-commands. | |
520 | self.sub_commands = self.parser.add_subparsers() | |
521 | ||
a52f536c | 522 | self.parse_command_build() |
677ff42a | 523 | self.parse_command_keepalive() |
8276111d | 524 | self.parse_command_repoupdate() |
df9c4f62 | 525 | self.parse_command_repo() |
677ff42a MT |
526 | |
527 | # Finally parse all arguments from the command line and save them. | |
528 | self.args = self.parser.parse_args() | |
529 | ||
269c59f3 | 530 | self.server = server.Server(**self.pakfire_args) |
677ff42a MT |
531 | |
532 | self.action2func = { | |
8276111d MT |
533 | "build" : self.handle_build, |
534 | "keepalive" : self.handle_keepalive, | |
535 | "repoupdate" : self.handle_repoupdate, | |
df9c4f62 | 536 | "repo_create": self.handle_repo_create, |
677ff42a MT |
537 | } |
538 | ||
6557ff4c MT |
539 | @property |
540 | def pakfire_args(self): | |
541 | ret = { "mode" : "server" } | |
542 | ||
6a509182 MT |
543 | if hasattr(self.args, "offline"): |
544 | ret["offline"] = self.args.offline | |
545 | ||
6557ff4c MT |
546 | return ret |
547 | ||
a52f536c MT |
548 | def parse_command_build(self): |
549 | # Implement the "build" command. | |
550 | sub_keepalive = self.sub_commands.add_parser("build", | |
551 | help=_("Request a build job from the server.")) | |
552 | sub_keepalive.add_argument("action", action="store_const", const="build") | |
553 | ||
677ff42a MT |
554 | def parse_command_keepalive(self): |
555 | # Implement the "keepalive" command. | |
556 | sub_keepalive = self.sub_commands.add_parser("keepalive", | |
557 | help=_("Send a keepalive to the server.")) | |
558 | sub_keepalive.add_argument("action", action="store_const", | |
559 | const="keepalive") | |
560 | ||
8276111d MT |
561 | def parse_command_repoupdate(self): |
562 | # Implement the "repoupdate" command. | |
563 | sub_repoupdate = self.sub_commands.add_parser("repoupdate", | |
564 | help=_("Update all repositories.")) | |
565 | sub_repoupdate.add_argument("action", action="store_const", | |
566 | const="repoupdate") | |
567 | ||
df9c4f62 MT |
568 | def parse_command_repo(self): |
569 | sub_repo = self.sub_commands.add_parser("repo", | |
570 | help=_("Repository management commands.")) | |
571 | ||
572 | sub_repo_commands = sub_repo.add_subparsers() | |
573 | ||
574 | self.parse_command_repo_create(sub_repo_commands) | |
575 | ||
576 | def parse_command_repo_create(self, sub_commands): | |
577 | sub_create = sub_commands.add_parser("create", | |
578 | help=_("Create a new repository index.")) | |
579 | sub_create.add_argument("path", nargs=1, help=_("Path to the packages.")) | |
580 | sub_create.add_argument("inputs", nargs="+", help=_("Path to input packages.")) | |
581 | sub_create.add_argument("action", action="store_const", const="repo_create") | |
582 | ||
677ff42a | 583 | def handle_keepalive(self): |
3ad4bb5a | 584 | self.server.update_info() |
9613a111 | 585 | |
a52f536c | 586 | def handle_build(self): |
3ad4bb5a | 587 | self.server.build_job() |
8276111d MT |
588 | |
589 | def handle_repoupdate(self): | |
590 | self.server.update_repositories() | |
df9c4f62 MT |
591 | |
592 | def handle_repo_create(self): | |
593 | path = self.args.path[0] | |
594 | ||
595 | pakfire.repo_create(path, self.args.inputs, **self.pakfire_args) | |
c07a3ca7 MT |
596 | |
597 | ||
9b875540 | 598 | class CliBuilderIntern(Cli): |
c07a3ca7 MT |
599 | def __init__(self): |
600 | self.parser = argparse.ArgumentParser( | |
601 | description = _("Pakfire builder command line interface."), | |
602 | ) | |
603 | ||
604 | self.parse_common_arguments() | |
605 | ||
606 | # Add sub-commands. | |
607 | self.sub_commands = self.parser.add_subparsers() | |
608 | ||
609 | self.parse_command_build() | |
610 | ||
611 | # Finally parse all arguments from the command line and save them. | |
612 | self.args = self.parser.parse_args() | |
613 | ||
614 | self.action2func = { | |
615 | "build" : self.handle_build, | |
616 | } | |
617 | ||
618 | def parse_command_build(self): | |
619 | # Implement the "build" command. | |
620 | sub_build = self.sub_commands.add_parser("build", | |
621 | help=_("Build one or more packages.")) | |
622 | sub_build.add_argument("package", nargs=1, | |
623 | help=_("Give name of at least one package to build.")) | |
624 | sub_build.add_argument("action", action="store_const", const="build") | |
625 | ||
626 | sub_build.add_argument("-a", "--arch", | |
627 | help=_("Build the package for the given architecture.")) | |
628 | sub_build.add_argument("--resultdir", nargs="?", | |
629 | help=_("Path were the output files should be copied to.")) | |
630 | sub_build.add_argument("-m", "--mode", nargs="?", default="development", | |
631 | help=_("Mode to run in. Is either 'release' or 'development' (default).")) | |
632 | sub_build.add_argument("--nodeps", action="store_true", | |
633 | help=_("Do not verify build dependencies.")) | |
634 | ||
635 | def handle_build(self): | |
636 | # Get the package descriptor from the command line options | |
637 | pkg = self.args.package[0] | |
638 | ||
639 | # Check, if we got a regular file | |
640 | if os.path.exists(pkg): | |
641 | pkg = os.path.abspath(pkg) | |
642 | else: | |
643 | raise FileNotFoundError, pkg | |
644 | ||
645 | # Create distribution configuration from command line. | |
646 | distro_config = { | |
647 | "arch" : self.args.arch, | |
648 | } | |
649 | ||
650 | pakfire._build(pkg, builder_mode=self.args.mode, | |
651 | distro_config=distro_config, resultdir=self.args.resultdir, | |
652 | nodeps=self.args.nodeps, **self.pakfire_args) |