Added '0install config' sub-command
[zeroinstall.git] / zeroinstall / gtkui / desktop.py
blobb0627e53df58477adca8baa26a17c70285c6ccd8
1 """Code for the B{0desktop} command."""
3 # Copyright (C) 2009, Thomas Leonard
4 # See the README file for details, or visit http://0install.net.
6 from zeroinstall import _
7 import sys
8 from optparse import OptionParser
9 import logging
11 def main(command_args):
12 """Implements the logic of the 0desktop command.
13 @param command_args: the command-line arguments"""
14 parser = OptionParser(usage=_("usage: %prog [options] [URI]"))
15 parser.add_option("-m", "--manage", help=_("manage added applications"), action='store_true')
16 parser.add_option("-v", "--verbose", help=_("more verbose output"), action='count')
17 parser.add_option("-V", "--version", help=_("display version information"), action='store_true')
19 (options, args) = parser.parse_args(command_args)
21 if options.verbose:
22 logger = logging.getLogger()
23 if options.verbose == 1:
24 logger.setLevel(logging.INFO)
25 else:
26 logger.setLevel(logging.DEBUG)
27 hdlr = logging.StreamHandler()
28 fmt = logging.Formatter("%(levelname)s:%(message)s")
29 hdlr.setFormatter(fmt)
30 logger.addHandler(hdlr)
32 if options.version:
33 import zeroinstall
34 print "0desktop (zero-install) " + zeroinstall.version
35 print "Copyright (C) 2009 Thomas Leonard"
36 print _("This program comes with ABSOLUTELY NO WARRANTY,"
37 "\nto the extent permitted by law."
38 "\nYou may redistribute copies of this program"
39 "\nunder the terms of the GNU Lesser General Public License."
40 "\nFor more information about these matters, see the file named COPYING.")
41 sys.exit(0)
43 if not args:
44 interface_uri = None
45 elif len(args) == 1:
46 interface_uri = args[0]
47 else:
48 parser.print_help()
49 sys.exit(1)
51 import pygtk; pygtk.require('2.0')
52 import gtk
54 if options.manage:
55 from zeroinstall.gtkui.applistbox import AppListBox, AppList
56 from zeroinstall.injector.iface_cache import iface_cache
57 box = AppListBox(iface_cache, AppList())
58 else:
59 from zeroinstall.gtkui.addbox import AddBox
60 box = AddBox(interface_uri)
62 box.window.connect('destroy', gtk.main_quit)
63 box.window.show()
64 gtk.main()