3 # zavai - simple interface to the OpenMoko (or to the FSO stack)
5 # Copyright (C) 2009 Enrico Zini <enrico@enricozini.org>
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 import dbus.mainloop.glib
31 class Parser(optparse.OptionParser):
32 def __init__(self, *args, **kwargs):
33 # Yes, in 2009 optparse from the *standard library* still uses old
35 optparse.OptionParser.__init__(self, *args, **kwargs)
38 sys.stderr.write("%s: error: %s\n\n" % (self.get_prog_name(), msg))
39 self.print_help(sys.stderr)
42 parser = Parser(usage="usage: %prog [options]",
43 version="%prog "+ VERSION,
44 description="Simple interactive interface for the OpenMoko")
45 parser.add_option("-v", "--verbose", action="store_true", help="verbose mode")
47 (opts, args) = parser.parse_args()
53 zavai.info("Loading configuration")
54 conf = zavai.read_config(nick="zavai")
57 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
58 dbus_system_bus = dbus.SystemBus()
61 registry = zavai.Registry()
63 # Register main factories
64 registry.register("dbus.system_bus", dbus_system_bus)
65 registry.register("conf", conf)
66 registry.register_factory("app", zavai.Zavai)
67 registry.register_factory("gps", zavai.GPS)
70 zavai.info("Loading plugins")
71 for p in zavai.load_plugins(nick="zavai"):
73 p.init(conf = conf, registry = registry)
75 print >>sys.stderr, "Exception caught loading plugin %s: skipping plugin" % p
76 print >>sys.stderr, "Exception details:"
78 details = traceback.format_exc()
79 print >>sys.stderr, "\t"+details.rstrip().replace("\n", "\n\t")
81 # Shutdown the main loop on SIGINT
82 def on_kill(signum, frame):
84 signal.signal(signal.SIGINT, on_kill)
85 signal.signal(signal.SIGTERM, on_kill)
87 zavai.info("Starting")
88 app = registry.resource("app")
89 app.connect("destroy", gtk.main_quit)
92 zavai.info("Shutting down")