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