From 9dac2e5349d8c25d4b8b3376e889e9b69a07e676 Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Mon, 20 Aug 2012 07:48:11 +0100 Subject: [PATCH] Added "0install apps" This command lists the installed apps, possibly using the GUI. TODO: - The GUI should show the available apps, not just the old .desktop files - Deprecate 0desktop - Put the Add button in the app list window --- 0install.1 | 9 +++++++++ zeroinstall/0launch-gui/main.py | 11 +++++++++++ zeroinstall/apps.py | 15 +++++++++++++++ zeroinstall/cmd/__init__.py | 2 +- zeroinstall/cmd/apps.py | 31 +++++++++++++++++++++++++++++++ zeroinstall/gtkui/desktop.py | 2 +- 6 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 zeroinstall/cmd/apps.py diff --git a/0install.1 b/0install.1 index 3a76104..508117f 100644 --- a/0install.1 +++ b/0install.1 @@ -22,6 +22,8 @@ .B 0install whatchanged \fBNAME\fP +.B 0install apps + .B 0install destroy \fBNAME\fP .SS Other commands: @@ -375,6 +377,13 @@ If additional requirements are given (as for "0install select", e.g. --before), they update the requirements stored with the application and apply to this and future updates. +.B 0install apps + +.PP +List all the applications which have been added. By default, this will open the +GUI, which also allows you to run or modify the applications. Use \-c to get a +simple list written to the console. + .B 0install whatchanged \fBNAME\fP .PP diff --git a/zeroinstall/0launch-gui/main.py b/zeroinstall/0launch-gui/main.py index 6062f27..487f7cf 100644 --- a/zeroinstall/0launch-gui/main.py +++ b/zeroinstall/0launch-gui/main.py @@ -26,6 +26,7 @@ def recalculate(): def run_gui(args): parser = OptionParser(usage=_("usage: %prog [options] interface")) + parser.add_option("", "--apps", help=_("show app list"), action='store_true') parser.add_option("", "--before", help=_("choose a version before this"), metavar='VERSION') parser.add_option("", "--cpu", help=_("target CPU type"), metavar='CPU') parser.add_option("", "--command", help=_("command to select"), metavar='COMMAND') @@ -97,6 +98,16 @@ def run_gui(args): except SafeException as ex: nogui(ex) # logging needs this as a raised exception + if options.apps: + from zeroinstall.gtkui.applistbox import AppListBox, AppList + from zeroinstall.injector.iface_cache import iface_cache + box = AppListBox(iface_cache, AppList()) + done = tasks.Blocker('close app list') + box.window.connect('destroy', lambda w: done.trigger()) + box.window.show() + tasks.wait_for_blocker(done) + sys.exit(0) + handler = gui.GUIHandler() config = load_config(handler) diff --git a/zeroinstall/apps.py b/zeroinstall/apps.py index 516c532..bb80b20 100644 --- a/zeroinstall/apps.py +++ b/zeroinstall/apps.py @@ -285,3 +285,18 @@ class AppManager: return None else: raise SafeException("No such application '{name}'".format(name = name)) + + def list_apps(self): + """Returns all the apps. + @rtype: [L{App}]""" + apps = [] + + for d in basedir.load_config_paths(namespaces.config_site, "apps"): + for app in os.listdir(d): + if not valid_name.match(app): + continue + app_dir = os.path.join(d, app) + if os.path.isdir(app_dir): + apps.append((app, App(self.config, app_dir))) + + return [app for (name, app) in sorted(apps)] diff --git a/zeroinstall/cmd/__init__.py b/zeroinstall/cmd/__init__.py index bf75671..2b49507 100644 --- a/zeroinstall/cmd/__init__.py +++ b/zeroinstall/cmd/__init__.py @@ -14,7 +14,7 @@ import logging from zeroinstall import SafeException -valid_commands = ['add', 'select', 'download', 'run', 'update', 'whatchanged', 'destroy', +valid_commands = ['add', 'select', 'download', 'run', 'update', 'whatchanged', 'apps', 'destroy', 'config', 'import', 'list', 'add-feed', 'remove-feed', 'list-feeds', 'digest'] diff --git a/zeroinstall/cmd/apps.py b/zeroinstall/cmd/apps.py new file mode 100644 index 0000000..d0eef85 --- /dev/null +++ b/zeroinstall/cmd/apps.py @@ -0,0 +1,31 @@ +""" +The B{0install apps} command-line interface. +""" + +# Copyright (C) 2012, Thomas Leonard +# See the README file for details, or visit http://0install.net. + +from __future__ import print_function + +import sys + +from zeroinstall.cmd import UsageError +from zeroinstall import helpers + +syntax = "" + +def add_options(parser): + pass + +def handle(config, options, args): + if len(args) != 0: + raise UsageError() + + result = helpers.get_selections_gui(None, ['--apps'], use_gui = options.gui) + if result is helpers.DontUseGUI: + apps = config.app_mgr.list_apps() + if apps: + for app in apps: + print(app.get_name()) + else: + print('No apps. Use "0install add" to add some.') diff --git a/zeroinstall/gtkui/desktop.py b/zeroinstall/gtkui/desktop.py index 2de8c49..7b480c6 100644 --- a/zeroinstall/gtkui/desktop.py +++ b/zeroinstall/gtkui/desktop.py @@ -33,7 +33,7 @@ def main(command_args): if options.version: import zeroinstall print("0desktop (zero-install) " + zeroinstall.version) - print("Copyright (C) 2009 Thomas Leonard") + print("Copyright (C) 2012 Thomas Leonard") print(_("This program comes with ABSOLUTELY NO WARRANTY," "\nto the extent permitted by law." "\nYou may redistribute copies of this program" -- 2.11.4.GIT