Commit 3e9a8b59 authored by Seblu's avatar Seblu

Add a switch to auto select all matching packages

parent 3f17472b
...@@ -272,11 +272,14 @@ def list_packages(packages, long=False): ...@@ -272,11 +272,14 @@ def list_packages(packages, long=False):
for package in packages: for package in packages:
print(pattern % package) print(pattern % package)
def select_packages(packages): def select_packages(packages, select_all=False):
"""select a package in a list""" """select a package in a list"""
# shortcut to one package # shortcut to one package
if len(packages) == 1: if len(packages) == 1:
yield packages[0] yield packages[0]
elif select_all:
for pkg in packages:
yield pkg
else: else:
# display a list of packages to select # display a list of packages to select
index = dict(enumerate(packages)) index = dict(enumerate(packages))
...@@ -301,14 +304,14 @@ def select_packages(packages): ...@@ -301,14 +304,14 @@ def select_packages(packages):
else: else:
warn("No package n°%s" % num) warn("No package n°%s" % num)
def get_packages(packages): def get_packages(packages, select_all=False):
"""download packages""" """download packages"""
for pkg in select_packages(packages): for pkg in select_packages(packages, select_all):
pkg.get() pkg.get()
def install_packages(packages): def install_packages(packages, select_all=False):
"""install packages in one shot to allow deps to work""" """install packages in one shot to allow deps to work"""
packages = list(select_packages(packages)) packages = list(select_packages(packages, select_all))
with TemporaryDirectory() as tmpdir: with TemporaryDirectory() as tmpdir:
cwd = getcwd() cwd = getcwd()
chdir(tmpdir) chdir(tmpdir)
...@@ -338,6 +341,8 @@ def parse_argv(): ...@@ -338,6 +341,8 @@ def parse_argv():
g_action.add_argument("-i", "--install", action="store_const", dest="mode", g_action.add_argument("-i", "--install", action="store_const", dest="mode",
const="install", help="install matching packages") const="install", help="install matching packages")
# common options # common options
p_main.add_argument("-a", "--all", action="store_true",
help="select all packages without prompting")
p_main.add_argument("-A", "--arch", nargs="*", default=[local_arch, "any"], p_main.add_argument("-A", "--arch", nargs="*", default=[local_arch, "any"],
help="filter by architectures (default: %s and any. empty means all)" % local_arch) help="filter by architectures (default: %s and any. empty means all)" % local_arch)
p_main.add_argument("-v", "--verbose", action="store_true", p_main.add_argument("-v", "--verbose", action="store_true",
...@@ -377,9 +382,9 @@ def main(): ...@@ -377,9 +382,9 @@ def main():
if args.mode == "list": if args.mode == "list":
list_packages(packages, long=args.verbose) list_packages(packages, long=args.verbose)
elif args.mode == "install": elif args.mode == "install":
install_packages(packages) install_packages(packages, args.all)
else: else:
get_packages(packages) get_packages(packages, args.all)
except KeyboardInterrupt: except KeyboardInterrupt:
exit(Error.ERR_ABORT) exit(Error.ERR_ABORT)
except Error as exp: except Error as exp:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment