X-Git-Url: http://git.maemo.org/git/?p=theonering;a=blobdiff_plain;f=src%2Ftelepathy-theonering;h=b18e407e5310b058cbd5e0197feecfc36d706db7;hp=f80f22b968ef64854a3d9ec3868e09bdb615fdff;hb=02a126316c2b761233aed2d194e61074fc69620b;hpb=921efa82da0ac09eb0cda115da465a241b169591 diff --git a/src/telepathy-theonering b/src/telepathy-theonering index f80f22b..b18e407 100755 --- a/src/telepathy-theonering +++ b/src/telepathy-theonering @@ -1,113 +1,8 @@ -#!/usr/bin/env python +#!/usr/bin/python -""" -Telepathy-TheOneRing - Telepathy plugin for GoogleVoice -Copyright (C) 2009 Ed Page eopage AT byu DOT net -This library is free software; you can redistribute it and/or -modify it under the terms of the GNU Lesser General Public -License as published by the Free Software Foundation; either -version 2.1 of the License, or (at your option) any later version. +import theonering -This library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public -License along with this library; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -""" - -import os -import sys -import signal -import logging -import gobject - -import dbus.glib -import telepathy.utils as telepathy_utils - -import util.linux as linux_utils -import util.go_utils as gobject_utils -import constants -import connection_manager - - -IDLE_TIMEOUT = 5000 - - -def run_theonering(persist): - linux_utils.set_process_name(constants.__app_name__) - - try: - os.makedirs(constants._data_path_) - except OSError, e: - if e.errno != 17: - raise - - @gobject_utils.async - def quit(): - manager.quit() - mainloop.quit() - - def timeout_cb(): - if len(manager._connections) == 0: - logging.info('No connection received - quitting') - quit() - return False - - if persist: - shutdown_callback = None - else: - gobject.timeout_add(IDLE_TIMEOUT, timeout_cb) - shutdown_callback = quit - - signal.signal(signal.SIGTERM, quit) - - try: - manager = connection_manager.TheOneRingConnectionManager(shutdown_func=shutdown_callback) - except dbus.exceptions.NameExistsException: - logging.warning('Failed to acquire bus name, connection manager already running?') - sys.exit(1) - - mainloop = gobject.MainLoop(is_running=True) - - while mainloop.is_running(): - try: - mainloop.run() - except KeyboardInterrupt: - quit() - - -def main(logToFile): - try: - os.makedirs(constants._data_path_) - except OSError, e: - if e.errno != 17: - raise - - telepathy_utils.debug_divert_messages(os.getenv('THEONERING_LOGFILE')) - if logToFile: - logging.basicConfig( - level=logging.DEBUG, - format='(%(asctime)s) %(levelname)s:%(name)s:%(message)s', - datefmt='%H:%M:%S', - ) - else: - logging.basicConfig(level=logging.DEBUG, filename=constants._user_logpath_) - logging.info("telepathy-theonering %s-%s" % (constants.__version__, constants.__build__)) - logging.info("OS: %s" % (os.uname()[0], )) - logging.info("Kernel: %s (%s) for %s" % os.uname()[2:]) - logging.info("Hostname: %s" % os.uname()[1]) - - persist = 'THEONERING_PERSIST' in os.environ - persist = True - - try: - run_theonering(persist) - finally: - logging.shutdown() if __name__ == "__main__": - main(False) + theonering.main(logToFile=True)