]>
git.ipfire.org Git - pakfire.git/blob - pakfire/cli.py
11 import pakfire
.api
as pakfire
12 from constants
import *
17 self
.parser
= argparse
.ArgumentParser(
18 description
= _("Pakfire command line interface."),
21 self
.parse_common_arguments()
23 self
.parser
.add_argument("--instroot", metavar
="PATH",
25 help=_("The path where pakfire should operate in."))
28 self
.sub_commands
= self
.parser
.add_subparsers()
30 self
.parse_command_install()
31 self
.parse_command_localinstall()
32 self
.parse_command_remove()
33 self
.parse_command_info()
34 self
.parse_command_search()
35 self
.parse_command_update()
36 self
.parse_command_provides()
37 self
.parse_command_requires()
38 self
.parse_command_grouplist()
39 self
.parse_command_groupinstall()
40 self
.parse_command_repolist()
42 # Finally parse all arguments from the command line and save them.
43 self
.args
= self
.parser
.parse_args()
46 "install" : self
.handle_install
,
47 "localinstall" : self
.handle_localinstall
,
48 "remove" : self
.handle_remove
,
49 "update" : self
.handle_update
,
50 "info" : self
.handle_info
,
51 "search" : self
.handle_search
,
52 "provides" : self
.handle_provides
,
53 "requires" : self
.handle_requires
,
54 "grouplist" : self
.handle_grouplist
,
55 "groupinstall" : self
.handle_groupinstall
,
56 "repolist" : self
.handle_repolist
,
60 def pakfire_args(self
):
63 def parse_common_arguments(self
):
64 self
.parser
.add_argument("-v", "--verbose", action
="store_true",
65 help=_("Enable verbose output."))
67 self
.parser
.add_argument("-c", "--config", nargs
="?",
68 help=_("Path to a configuration file to load."))
70 self
.parser
.add_argument("--disable-repo", nargs
="*", metavar
="REPO",
71 help=_("Disable a repository temporarily."))
73 def parse_command_install(self
):
74 # Implement the "install" command.
75 sub_install
= self
.sub_commands
.add_parser("install",
76 help=_("Install one or more packages to the system."))
77 sub_install
.add_argument("package", nargs
="+",
78 help=_("Give name of at least one package to install."))
79 sub_install
.add_argument("action", action
="store_const", const
="install")
81 def parse_command_localinstall(self
):
82 # Implement the "localinstall" command.
83 sub_install
= self
.sub_commands
.add_parser("localinstall",
84 help=_("Install one or more packages from the filesystem."))
85 sub_install
.add_argument("package", nargs
="+",
86 help=_("Give filename of at least one package."))
87 sub_install
.add_argument("action", action
="store_const", const
="localinstall")
89 def parse_command_remove(self
):
90 # Implement the "remove" command.
91 sub_remove
= self
.sub_commands
.add_parser("remove",
92 help=_("Remove one or more packages from the system."))
93 sub_remove
.add_argument("package", nargs
="+",
94 help=_("Give name of at least one package to remove."))
95 sub_remove
.add_argument("action", action
="store_const", const
="remove")
97 def parse_command_update(self
):
98 # Implement the "update" command.
99 sub_update
= self
.sub_commands
.add_parser("update",
100 help=_("Update the whole system or one specific package."))
101 sub_update
.add_argument("package", nargs
="*",
102 help=_("Give a name of a package to update or leave emtpy for all."))
103 sub_update
.add_argument("action", action
="store_const", const
="update")
105 def parse_command_info(self
):
106 # Implement the "info" command.
107 sub_info
= self
.sub_commands
.add_parser("info",
108 help=_("Print some information about the given package(s)."))
109 sub_info
.add_argument("package", nargs
="+",
110 help=_("Give at least the name of one package."))
111 sub_info
.add_argument("action", action
="store_const", const
="info")
113 def parse_command_search(self
):
114 # Implement the "search" command.
115 sub_search
= self
.sub_commands
.add_parser("search",
116 help=_("Search for a given pattern."))
117 sub_search
.add_argument("pattern",
118 help=_("A pattern to search for."))
119 sub_search
.add_argument("action", action
="store_const", const
="search")
121 def parse_command_provides(self
):
122 # Implement the "provides" command
123 sub_provides
= self
.sub_commands
.add_parser("provides",
124 help=_("Get a list of packages that provide a given file or feature."))
125 sub_provides
.add_argument("pattern", nargs
="+",
126 help=_("File or feature to search for."))
127 sub_provides
.add_argument("action", action
="store_const", const
="provides")
129 def parse_command_requires(self
):
130 # Implement the "requires" command
131 sub_requires
= self
.sub_commands
.add_parser("requires",
132 help=_("Get a list of packages that require a given file or feature."))
133 sub_requires
.add_argument("pattern", nargs
="+",
134 help=_("File or feature to search for."))
135 sub_requires
.add_argument("action", action
="store_const", const
="requires")
137 def parse_command_grouplist(self
):
138 # Implement the "grouplist" command
139 sub_grouplist
= self
.sub_commands
.add_parser("grouplist",
140 help=_("Get list of packages that belong to the given group."))
141 sub_grouplist
.add_argument("group", nargs
=1,
142 help=_("Group name to search for."))
143 sub_grouplist
.add_argument("action", action
="store_const", const
="grouplist")
145 def parse_command_groupinstall(self
):
146 # Implement the "grouplist" command
147 sub_groupinstall
= self
.sub_commands
.add_parser("groupinstall",
148 help=_("Install all packages that belong to the given group."))
149 sub_groupinstall
.add_argument("group", nargs
=1,
150 help=_("Group name."))
151 sub_groupinstall
.add_argument("action", action
="store_const", const
="groupinstall")
153 def parse_command_repolist(self
):
154 # Implement the "repolist" command
155 sub_repolist
= self
.sub_commands
.add_parser("repolist",
156 help=_("List all currently enabled repositories."))
157 sub_repolist
.add_argument("action", action
="store_const", const
="repolist")
160 action
= self
.args
.action
162 if not self
.action2func
.has_key(action
):
166 func
= self
.action2func
[action
]
168 raise # XXX catch and return better error message
172 def handle_info(self
, long=False):
173 pkgs
= pakfire
.info(self
.args
.package
, **self
.pakfire_args
)
176 print pkg
.dump(long=long)
178 def handle_search(self
):
179 pkgs
= pakfire
.search(self
.args
.pattern
, **self
.pakfire_args
)
182 print pkg
.dump(short
=True)
184 def handle_update(self
):
185 pakfire
.update(self
.args
.package
, **self
.pakfire_args
)
187 def handle_install(self
):
188 pakfire
.install(self
.args
.package
, **self
.pakfire_args
)
190 def handle_localinstall(self
):
191 pakfire
.localinstall(self
.args
.package
, **self
.pakfire_args
)
193 def handle_remove(self
):
194 pakfire
.remove(self
.args
.package
, **self
.pakfire_args
)
196 def handle_provides(self
):
197 pkgs
= pakfire
.provides(self
.args
.pattern
, **self
.pakfire_args
)
202 def handle_requires(self
):
203 pkgs
= pakfire
.requires(self
.args
.pattern
, **self
.pakfire_args
)
208 def handle_grouplist(self
):
209 pkgs
= pakfire
.grouplist(self
.args
.group
[0], **self
.pakfire_args
)
214 def handle_groupinstall(self
):
215 pakfire
.groupinstall(self
.args
.group
[0], **self
.pakfire_args
)
217 def handle_repolist(self
):
218 repos
= pakfire
.repo_list(**self
.pakfire_args
)
221 FORMAT
= " %-20s %8s %12s "
223 title
= FORMAT
% (_("Repository"), _("Enabled"), _("Priority"))
225 print "=" * len(title
) # spacing line
228 # Skip the installed repository.
229 if repo
.name
== "installed":
232 print FORMAT
% (repo
.name
, repo
.enabled
, repo
.priority
)
235 class CliBuilder(Cli
):
237 self
.parser
= argparse
.ArgumentParser(
238 description
= _("Pakfire builder command line interface."),
241 self
.parse_common_arguments()
244 self
.sub_commands
= self
.parser
.add_subparsers()
246 self
.parse_command_build()
247 self
.parse_command_dist()
248 self
.parse_command_info()
249 self
.parse_command_search()
250 self
.parse_command_shell()
251 self
.parse_command_update()
252 self
.parse_command_provides()
253 self
.parse_command_requires()
254 self
.parse_command_grouplist()
255 self
.parse_command_repolist()
257 # Finally parse all arguments from the command line and save them.
258 self
.args
= self
.parser
.parse_args()
261 "build" : self
.handle_build
,
262 "dist" : self
.handle_dist
,
263 "update" : self
.handle_update
,
264 "info" : self
.handle_info
,
265 "search" : self
.handle_search
,
266 "shell" : self
.handle_shell
,
267 "provides" : self
.handle_provides
,
268 "requires" : self
.handle_requires
,
269 "grouplist" : self
.handle_grouplist
,
270 "repolist" : self
.handle_repolist
,
274 def pakfire_args(self
):
275 return { "builder" : 1 }
277 def parse_command_update(self
):
278 # Implement the "update" command.
279 sub_update
= self
.sub_commands
.add_parser("update",
280 help=_("Update the package indexes."))
281 sub_update
.add_argument("action", action
="store_const", const
="update")
283 def parse_command_build(self
):
284 # Implement the "build" command.
285 sub_build
= self
.sub_commands
.add_parser("build",
286 help=_("Build one or more packages."))
287 sub_build
.add_argument("package", nargs
=1,
288 help=_("Give name of at least one package to build."))
289 sub_build
.add_argument("action", action
="store_const", const
="build")
291 sub_build
.add_argument("-a", "--arch",
292 help=_("Build the package for the given architecture."))
293 sub_build
.add_argument("--resultdir", nargs
="?",
294 help=_("Path were the output files should be copied to."))
296 def parse_command_shell(self
):
297 # Implement the "shell" command.
298 sub_shell
= self
.sub_commands
.add_parser("shell",
299 help=_("Go into a shell."))
300 sub_shell
.add_argument("package", nargs
="?",
301 help=_("Give name of a package."))
302 sub_shell
.add_argument("action", action
="store_const", const
="shell")
304 sub_shell
.add_argument("-a", "--arch",
305 help=_("Emulated architecture in the shell."))
307 def parse_command_dist(self
):
308 # Implement the "dist" command.
309 sub_dist
= self
.sub_commands
.add_parser("dist",
310 help=_("Generate a source package."))
311 sub_dist
.add_argument("package", nargs
="+",
312 help=_("Give name(s) of a package(s)."))
313 sub_dist
.add_argument("action", action
="store_const", const
="dist")
315 sub_dist
.add_argument("--resultdir", nargs
="?",
316 help=_("Path were the output files should be copied to."))
318 def handle_info(self
):
319 Cli
.handle_info(self
, long=True)
321 def handle_build(self
):
322 # Get the package descriptor from the command line options
323 pkg
= self
.args
.package
[0]
325 # Check, if we got a regular file
326 if os
.path
.exists(pkg
):
327 pkg
= os
.path
.abspath(pkg
)
330 raise FileNotFoundError
, pkg
332 # Create distribution configuration from command line.
334 "arch" : self
.args
.arch
,
337 pakfire
.build(pkg
, distro_config
=distro_config
, resultdirs
=[self
.args
.resultdir
,],
338 shell
=True, **self
.pakfire_args
)
340 def handle_shell(self
):
343 # Get the package descriptor from the command line options
344 if self
.args
.package
:
345 pkg
= self
.args
.package
347 # Check, if we got a regular file
348 if os
.path
.exists(pkg
):
349 pkg
= os
.path
.abspath(pkg
)
352 raise FileNotFoundError
, pkg
354 # Create distribution configuration from command line.
356 "arch" : self
.args
.arch
,
359 pakfire
.shell(pkg
, distro_config
=distro_config
, **self
.pakfire_args
)
361 def handle_dist(self
):
362 # Get the packages from the command line options
365 for pkg
in self
.args
.package
:
366 # Check, if we got a regular file
367 if os
.path
.exists(pkg
):
368 pkg
= os
.path
.abspath(pkg
)
372 raise FileNotFoundError
, pkg
374 pakfire
.dist(pkgs
, resultdirs
=[self
.args
.resultdir
,],
380 self
.parser
= argparse
.ArgumentParser(
381 description
= _("Pakfire repo command line interface."),
384 self
.parse_common_arguments()
387 self
.sub_commands
= self
.parser
.add_subparsers()
389 self
.parse_command_repo()
391 # Finally parse all arguments from the command line and save them.
392 self
.args
= self
.parser
.parse_args()
395 "repo_create" : self
.handle_repo_create
,
398 def parse_command_repo(self
):
399 sub_repo
= self
.sub_commands
.add_parser("repo",
400 help=_("Repository management commands."))
402 sub_repo_commands
= sub_repo
.add_subparsers()
404 self
.parse_command_repo_create(sub_repo_commands
)
406 def parse_command_repo_create(self
, sub_commands
):
407 sub_create
= sub_commands
.add_parser("create",
408 help=_("Create a new repository index."))
409 sub_create
.add_argument("path", nargs
=1, help=_("Path to the packages."))
410 sub_create
.add_argument("inputs", nargs
="+", help=_("Path to input packages."))
411 sub_create
.add_argument("action", action
="store_const", const
="repo_create")
413 def handle_repo_create(self
):
414 path
= self
.args
.path
[0]
416 pakfire
.repo_create(path
, self
.args
.inputs
, **self
.pakfire_args
)
419 class CliMaster(Cli
):
421 self
.parser
= argparse
.ArgumentParser(
422 description
= _("Pakfire master command line interface."),
425 self
.parse_common_arguments()
428 self
.sub_commands
= self
.parser
.add_subparsers()
430 self
.parse_command_update()
432 # Finally parse all arguments from the command line and save them.
433 self
.args
= self
.parser
.parse_args()
435 self
.master
= server
.master
.Master()
438 "update" : self
.handle_update
,
441 def parse_command_update(self
):
442 # Implement the "update" command.
443 sub_update
= self
.sub_commands
.add_parser("update",
444 help=_("Update the sources."))
445 sub_update
.add_argument("action", action
="store_const", const
="update")
447 def handle_update(self
):
448 self
.master
.update_sources()
453 self
.parser
= argparse
.ArgumentParser(
454 description
= _("Pakfire slave command line interface."),
457 self
.parse_common_arguments()
460 self
.sub_commands
= self
.parser
.add_subparsers()
462 self
.parse_command_build()
463 self
.parse_command_keepalive()
465 # Finally parse all arguments from the command line and save them.
466 self
.args
= self
.parser
.parse_args()
468 self
.slave
= server
.slave
.Slave()
471 "build" : self
.handle_build
,
472 "keepalive" : self
.handle_keepalive
,
475 def parse_command_build(self
):
476 # Implement the "build" command.
477 sub_keepalive
= self
.sub_commands
.add_parser("build",
478 help=_("Request a build job from the server."))
479 sub_keepalive
.add_argument("action", action
="store_const", const
="build")
481 def parse_command_keepalive(self
):
482 # Implement the "keepalive" command.
483 sub_keepalive
= self
.sub_commands
.add_parser("keepalive",
484 help=_("Send a keepalive to the server."))
485 sub_keepalive
.add_argument("action", action
="store_const",
488 def handle_keepalive(self
):
489 self
.slave
.keepalive()
491 def handle_build(self
):
492 self
.slave
.build_job()