Converted print statements to functions
[zeroinstall.git] / zeroinstall / gtkui / desktop.py
blob4c1dab33fc810cd72bee39f86c6f69d97085cefe
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 __future__ import print_function
8 from zeroinstall import _
9 import sys
10 from optparse import OptionParser
11 import logging
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')
21 (options, args) = parser.parse_args(command_args)
23 if options.verbose:
24 logger = logging.getLogger()
25 if options.verbose == 1:
26 logger.setLevel(logging.INFO)
27 else:
28 logger.setLevel(logging.DEBUG)
29 hdlr = logging.StreamHandler()
30 fmt = logging.Formatter("%(levelname)s:%(message)s")
31 hdlr.setFormatter(fmt)
32 logger.addHandler(hdlr)
34 if options.version:
35 import zeroinstall
36 print("0desktop (zero-install) " + zeroinstall.version)
37 print("Copyright (C) 2009 Thomas Leonard")
38 print(_("This program comes with ABSOLUTELY NO WARRANTY,"
39 "\nto the extent permitted by law."
40 "\nYou may redistribute copies of this program"
41 "\nunder the terms of the GNU Lesser General Public License."
42 "\nFor more information about these matters, see the file named COPYING."))
43 sys.exit(0)
45 if not args:
46 interface_uri = None
47 elif len(args) == 1:
48 interface_uri = args[0]
49 else:
50 parser.print_help()
51 sys.exit(1)
53 import pygtk; pygtk.require('2.0')
54 import gtk
56 if options.manage:
57 from zeroinstall.gtkui.applistbox import AppListBox, AppList
58 from zeroinstall.injector.iface_cache import iface_cache
59 box = AppListBox(iface_cache, AppList())
60 else:
61 from zeroinstall.gtkui.addbox import AddBox
62 box = AddBox(interface_uri)
64 box.window.connect('destroy', gtk.main_quit)
65 box.window.show()
66 gtk.main()