Exemplo n.º 1
0
def run():
    try:
        log.init('client.log')

        context = daemonise.getContext(
            pidfile = _config['client-pid-file'],
            signal_map = {
                signal.SIGUSR1: 'terminate',
                signal.SIGHUP: configuration.reload,
            },
        )

        _log.debug('Entering running context...')
        with context:
            _log.info('Configuration file: {0}'.format(configuration.filename()))
            _log.info('Initializing ConSys client daemon...')
            # Install GLib reactor
            from twisted.internet import glib2reactor
            glib2reactor.install()
            from consys.common import app
            from consys.client import network, persistent
            app.startup()
            app.dispatch_loop()
            _log.info('Terminating ConSys client daemon...')
    except Exception:
        _log.exception('Unhandled exception in main thread, exiting')
Exemplo n.º 2
0
def daemon():
    from twisted.internet import glib2reactor
    glib2reactor.install()
    from twisted.internet import reactor

    main_app = Application("Audio Failure Monitor") #, uid, gid)

    services = IServiceCollection(main_app)
    options = DaemonOptions()
    options.parseOptions()

    application = options.getService()
    application.infotub.setServiceParent(services)
    application.coretub.setServiceParent(services)

    app.startApplication(main_app, False)

    reactor.addSystemEventTrigger('before', 'shutdown',
                                  logging.getLogger(__name__).info,
                                  'Stopping AFM')

    logging.getLogger(__name__).info("AFM Started")
    try:
        reactor.run()
    except KeyboardInterrupt:
        reactor.stop()
Exemplo n.º 3
0
Arquivo: cli.py Projeto: riedel/Cohen3
def run_cohen3_on_twisted_loop():
    """
    Initialize a `Coherence` instance on a `twisted.internet.reactor`'s
    loop, depending on supplied arguments via `cli`.
    """
    parser = get_parser()
    options, args = parser.parse_args()
    if args:
        parser.error("takes no arguments")

    if options.daemon:
        try:
            daemonize()
        except:
            print(traceback.format_exc())

    config = {}

    if options.configfile:
        try:
            config = ConfigObj(options.configfile)
        except IOError:
            print("Config file %r not found, ignoring" % options.configfile)
            pass
    if "logging" not in config:
        config["logging"] = {}

    if options.logfile:
        config["logging"]["logfile"] = options.logfile

    # copy options passed by -o/--option into config
    for k, v in list(options.options.items()):
        if k == "logfile":
            continue
        config[k] = v

    if options.daemon:
        if config["logging"].get("logfile") is None:
            config["logging"]["level"] = "none"
            config["logging"].pop("logfile", None)

    if (config.get("use_dbus", "no") == "yes"
            or config.get("glib", "no") == "yes"
            or config.get("transcoding", "no") == "yes"):
        try:
            from twisted.internet import glib2reactor

            glib2reactor.install()
        except AssertionError:
            print("error installing glib2reactor")

    if options.plugins:
        config = process_plugins_for(config, options)

    from twisted.internet import reactor

    reactor.callWhenRunning(Coherence, config)
    reactor.run()
Exemplo n.º 4
0
def installDbusReactor():
    try:
        from twisted.internet import glib2reactor
        glib2reactor.install()
        return True
    except:
        try:
            from twisted.internet import gtk2reactor
            gtk2reactor.install()
            return True
        except:
            return False
Exemplo n.º 5
0
def installDbusReactor():
    try:
        from twisted.internet import glib2reactor
        glib2reactor.install()
        return True
    except:
        try:
            from twisted.internet import gtk2reactor
            gtk2reactor.install()
            return True
        except:
            return False
Exemplo n.º 6
0
def main(port=4118, parentpid=None):
    import os
    os.environ['NO_GAIL'] = '1'
    os.environ['NO_AT_BRIDGE'] = '1'

    import twisted
    gtkVersion = None
    try:
        from gi.repository import Gtk
        gtkVersion = Gtk._version
    except:
        pass
    if not gtkVersion or gtkVersion == '2.0':
       # As per Ubuntu 11.10, twisted glib2reactor
       # works with gtk2, which fails with gtk3
       from twisted.internet import glib2reactor
       glib2reactor.install()
    elif gtkVersion >= '3.0':
        try:
            # Exist in Ubuntu 12.04, but not on
            # Ubuntu 11.10 / Fedora 16
            from twisted.internet import gtk3reactor
            gtk3reactor.install()
        except:
            pass
    from twisted.internet import reactor
    from twisted.web import server, xmlrpc
    from xmlrpc_daemon import XMLRPCLdtpd
    import twisted.internet
    import socket
    import pyatspi
    import traceback

    _ldtp_debug = os.environ.get('LDTP_DEBUG', None)
    _ldtp_debug_file = os.environ.get('LDTP_DEBUG_FILE', None)

    try:
        pyatspi.setCacheLevel(pyatspi.CACHE_PROPERTIES)
        r = XMLRPCLdtpd()
        xmlrpc.addIntrospection(r)
        if parentpid:
            reactor.callWhenRunning(SignalParent(parentpid).send_later)
        reactor.listenTCP(port, server.Site(r))
        reactor.run()
    except twisted.internet.error.CannotListenError:
        if _ldtp_debug:
            print(traceback.format_exc())
    except socket.error:
        if _ldtp_debug:
            print(traceback.format_exc())
        if _ldtp_debug_file:
            with open(_ldtp_debug_file, "a") as fp:
                fp.write(traceback.format_exc())
Exemplo n.º 7
0
def main(port=4118, parentpid=None):
    import os
    os.environ['NO_GAIL'] = '1'
    os.environ['NO_AT_BRIDGE'] = '1'

    import twisted
    gtkVersion = None
    try:
        from gi.repository import Gtk
        gtkVersion = Gtk._version
    except:
        pass
    if not gtkVersion or gtkVersion == '2.0':
        # As per Ubuntu 11.10, twisted glib2reactor
        # works with gtk2, which fails with gtk3
        from twisted.internet import glib2reactor
        glib2reactor.install()
    elif gtkVersion >= '3.0':
        try:
            # Exist in Ubuntu 12.04, but not on
            # Ubuntu 11.10 / Fedora 16
            from twisted.internet import gtk3reactor
            gtk3reactor.install()
        except:
            pass
    from twisted.internet import reactor
    from twisted.web import server, xmlrpc
    from xmlrpc_daemon import XMLRPCLdtpd
    import twisted.internet
    import socket
    import pyatspi
    import traceback

    _ldtp_debug = os.environ.get('LDTP_DEBUG', None)
    _ldtp_debug_file = os.environ.get('LDTP_DEBUG_FILE', None)

    try:
        pyatspi.setCacheLevel(pyatspi.CACHE_PROPERTIES)
        r = XMLRPCLdtpd()
        xmlrpc.addIntrospection(r)
        if parentpid:
            reactor.callWhenRunning(SignalParent(parentpid).send_later)
        reactor.listenTCP(port, server.Site(r))
        reactor.run()
    except twisted.internet.error.CannotListenError:
        if _ldtp_debug:
            print(traceback.format_exc())
    except socket.error:
        if _ldtp_debug:
            print(traceback.format_exc())
        if _ldtp_debug_file:
            with open(_ldtp_debug_file, "a") as fp:
                fp.write(traceback.format_exc())
Exemplo n.º 8
0
 def __init__(self, mcserver):
     from twisted.internet import glib2reactor
     glib2reactor.install()
     from twisted.internet import reactor
     from twisted.web import xmlrpc, server
     class Test(xmlrpc.XMLRPC):
         server = mcserver
         def xmlrpc_list(self):
             return self.server.list()
     t = Test()
     config = mcserver.get_config(self)
     reactor.listenTCP(config['port'], server.Site(t))
Exemplo n.º 9
0
def maybeInstallDBus():
    import shtoom.dbus
    if shtoom.dbus.isAvailable():
        try:
            from twisted.internet import glib2reactor
            glib2reactor.install()
        except:
            try:
                from twisted.internet import gtk2reactor
                gtk2reactor.install()
            except:
                shtoom.dbus._setUnavailable()
Exemplo n.º 10
0
		import dbus.glib		
except ImportError:
    dbus = None

if dbus:
    try:
        import avahi
    except ImportError:
        avahi = None
else:
    avahi = None

from twisted.internet import defer, threads
from twisted.internet import glib2reactor
import logging
glib2reactor.install()

class avahiClient():

    def __init__(self, type):
		self._callbacks = {'new-service':  [], 'remove-service': [] }
		# initialize dbus stuff needed for discovery
								   
		self.bus = dbus.SystemBus()
		
		avahi_bus = self.bus.get_object(avahi.DBUS_NAME, avahi.DBUS_PATH_SERVER)
		self.server = dbus.Interface(avahi_bus, avahi.DBUS_INTERFACE_SERVER)
		
		#stype = '_workstation._tcp'
		#stype = '_controlaula._tcp'
Exemplo n.º 11
0
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
import os, sys
if __name__ == '__main__':
    from twisted.internet import glib2reactor as reactor
    reactor.install()
from twisted.internet import defer, reactor
from twisted.internet.protocol import Protocol, ClientFactory
import time, datetime
from gzip import GzipFile
from StringIO import StringIO
#import TapasPlayer as tp
#from TapasPlayer import update_sock_addr, test_method
from gi.repository import GObject as gobject
#import gobject
import gc
#
from util import debug


DEBUG = 2


localport=12

global localport

class ClientProtocol(Protocol):
    def __init__(self):
        self._recv_data = ''
        self._header = ''
Exemplo n.º 12
0
import sys
import time

from optparse import OptionParser

import dbus
import dbus.mainloop.glib  # this is black magic. DO NOT REMOVE!

from distutils.spawn import find_executable

# fix paths 1, to include lib for most basic stuff
LIB_DIR = os.path.abspath("lib")
sys.path.insert(0, LIB_DIR)

from twisted.internet import glib2reactor
glib2reactor.install()  # before any reactor import

from ubuntuone.storage.server.testing.testcase import create_test_user
from utilities import utils, dev_launcher
from ubuntuone.platform.linux import tools
from twisted.internet import reactor, defer

from ubuntuone.storage.tests.integration.helpers import debug, retryable

# to make dbus work
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)

# this should be done manually before:
DEP_STARTOAUTH = """
make start-oauth
"""
import os
import random
import shutil
import signal
import subprocess
import time

from optparse import OptionParser

import dbus
import dbus.mainloop.glib  # this is black magic. DO NOT REMOVE!

from distutils.spawn import find_executable

from twisted.internet import glib2reactor
glib2reactor.install()  # NOQA: before any reactor import

from django.conf import settings
from utilities import utils, dev_launcher
from twisted.internet import reactor, defer
from ubuntuone.platform.linux import tools

from magicicada.filesync import services
from magicicada.server.integration.helpers import debug, retryable

# to make dbus work
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)

LIB_DIR = os.path.abspath("lib")

# this should be done manually before:
Exemplo n.º 14
0
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
import os, sys
if __name__ == '__main__':
    from twisted.internet import glib2reactor as reactor
    reactor.install()
from twisted.internet import defer, reactor
from twisted.internet.protocol import Protocol, ClientFactory
import time, datetime
from gzip import GzipFile
from StringIO import StringIO

import gobject
import gc
#
from util import debug

DEBUG = 2

class ClientProtocol(Protocol):
    def __init__(self):
        self._recv_data = ''
        self._header = ''
        self.content_encoding = ''
        self.content_size = 0

    def connectionMade(self):
        debug(DEBUG+1, '%s connectionMade with: %s', self, self.transport.getPeer())
        #self.transport.setTcpKeepAlive(1)
        self.factory.connectionMade(self.transport.getPeer().host)
        
Exemplo n.º 15
0
#!/usr/bin/python
from twisted.internet import glib2reactor #We need this reactor to let dbus and twisted play nice together.
glib2reactor.install() #Turn glib2reactor into the reactor.
from twisted.internet import reactor #Now import reactor, being glib2reactor.
from twisted.web import http
from twisted.web.static import File
import os
import json
import sys
import jinja2
import dbus
import gobject
from dbus.mainloop.glib import DBusGMainLoop
import daemon
import syslog

class DynamicRouterConfig:
    def __init__(self,conffile):
        infile=open(conffile,"r")
        self.config=json.load(infile)
        infile.close()
    def getGroupName(self,host):
        for clientnet in self.config["devices"]["clients"]:
            if clientnet["ip"] == host:
                return clientnet["groupname"]
        return None
    def clientips(self):
        for clientnet in self.config["devices"]["clients"]:
            yield clientnet["ip"]
    def getGatewayList(self,host):
        groupname=self.getGroupName(host)