Esempio n. 1
0
def main():
    """
    Run as a utility for launching Turk Core
    usage: turkctl.py start|stop
    """
    parser = OptionParser("usage: %prog [options] <start|stop|restart|clean>")
    parser.add_option("-f",
                      "--config-file",
                      dest="config",
                      type="string",
                      default='/etc/turk/turk.yml',
                      help="default configuration file")
    (options, args) = parser.parse_args()

    if len(args) != 1:
        parser.error("incorrect number of arguments")

    conf = yaml.load(open(options.config, 'rU'))
    os.environ['TURK_CONF'] = options.config

    global log
    log = init_logging('turkctl', conf, debug=get_config('turkctl.debug'))

    {
        'start': start,
        'stop': stop,
        'restart': lambda conf: (stop(conf), start(conf)),
        'clean': clean
    }[args[0]](conf)
Esempio n. 2
0
def run(conf='/etc/turk/turk.yml'):
    global BUS_NAME
    
    if isinstance(conf, basestring):
        try:
            conf = yaml.load(open(conf, 'rU'))['xbeed']
        except Exception:
            log.debug( 'failed opening configuration file "%s"' % (conf))
            exit(1)

    log = turk.init_logging('xbeed', conf, debug=get_config('xbeed.debug'))

    dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)

    bus = getattr(dbus, get_config('global.bus', conf))()
    BUS_NAME = dbus.service.BusName(XBEED_SERVICE, bus)
    
    daemon = XBeeDaemon(*get_configs(('name', 'port', 'escaping', 'baudrate'), conf, 'xbeed'))

    mainloop = gobject.MainLoop()
    mainloop.run()     
Esempio n. 3
0
def run(conf='/etc/turk/turk.yml'):
    global BUS_NAME

    if isinstance(conf, basestring):
        try:
            conf = yaml.load(open(conf, 'rU'))['xbeed']
        except Exception:
            log.debug('failed opening configuration file "%s"' % (conf))
            exit(1)

    log = turk.init_logging('xbeed', conf, debug=get_config('xbeed.debug'))

    dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)

    bus = getattr(dbus, get_config('global.bus', conf))()
    BUS_NAME = dbus.service.BusName(XBEED_SERVICE, bus)

    daemon = XBeeDaemon(
        *get_configs(('name', 'port', 'escaping', 'baudrate'), conf, 'xbeed'))

    mainloop = gobject.MainLoop()
    mainloop.run()
Esempio n. 4
0
def main():
    """
    Run as a utility for launching Turk Core
    usage: turkctl.py start|stop
    """
    parser = OptionParser("usage: %prog [options] <start|stop|restart|clean>")
    parser.add_option("-f", "--config-file", dest="config", type="string", default='/etc/turk/turk.yml',
                      help="default configuration file")
    (options, args) = parser.parse_args()

    if len(args) != 1:
        parser.error("incorrect number of arguments")

    conf = yaml.load(open(options.config, 'rU'))
    os.environ['TURK_CONF'] = options.config

    global log
    log = init_logging('turkctl', conf, debug=get_config('turkctl.debug'))

    {'start':start,
     'stop':stop,
     'restart':lambda conf: (stop(conf), start(conf)),
     'clean':clean}[args[0]](conf)
Esempio n. 5
0
import logging

import gobject
import dbus
import dbus.service
import dbus.mainloop.glib

from turk import get_config, get_configs
import turk

XBEED_SERVICE = 'org.turkinnovations.xbeed'
XBEED_INTERFACE = 'org.turkinnovations.xbeed.XBeeInterface'
XBEED_DAEMON_OBJECT = '/XBeeInterfaces/%s'
XBEED_MODULE_OBJECT = '/XBeeModules/%X'

log = turk.init_logging('xbeed')


class XBeeDaemon(dbus.service.Object):
    """
    Main class which connects dbus API and serial communication
    name: Unique DBUS object name for this instance
    All other arguments are passed off to the underlying pySerial implementation
    """
    def __init__(self, name, port, escaping=True, baudrate=9600):
        self.port, self.baudrate = port, baudrate
        self.serial_type = EscapingSerial if escaping else Serial

        self.object_path = XBEED_DAEMON_OBJECT % name
        self.partial = PartialFrame()
        dbus.service.Object.__init__(self, BUS_NAME, self.object_path)
Esempio n. 6
0
#!/usr/bin/python

import os, sys
import signal
from optparse import OptionParser
import yaml
import multiprocessing
import logging
from time import sleep

from turk.runtime.spawner import run as run_spawner
from turk.runtime.bridge import run as run_bridge
from turk.xbeed.xbeed import run as run_xbeed
from turk import get_config, init_logging

log = init_logging('turkctl')

def start(conf):
    """
    Starts the Turk Core as a background process. 
    """
    pidfile_path = get_config('turkctl.pidfile', conf)
    
    if os.path.exists(pidfile_path):
        print 'File "%s" exists - Is Turk Core already running?' % pidfile_path
        exit(-1)

    pidfile = open(pidfile_path, 'w')

    pid = os.fork()
Esempio n. 7
0
#!/usr/bin/python

import os, sys
import signal
from optparse import OptionParser
import yaml
import multiprocessing
import logging
from time import sleep

from turk.runtime.spawner import run as run_spawner
from turk.runtime.bridge import run as run_bridge
from turk.xbeed.xbeed import run as run_xbeed
from turk import get_config, init_logging

log = init_logging('turkctl')


def start(conf):
    """
    Starts the Turk Core as a background process. 
    """
    pidfile_path = get_config('turkctl.pidfile', conf)

    if os.path.exists(pidfile_path):
        print 'File "%s" exists - Is Turk Core already running?' % pidfile_path
        exit(-1)

    pidfile = open(pidfile_path, 'w')

    pid = os.fork()
Esempio n. 8
0
import logging

import gobject
import dbus
import dbus.service
import dbus.mainloop.glib

from turk import get_config, get_configs
import turk

XBEED_SERVICE = 'org.turkinnovations.xbeed'
XBEED_INTERFACE = 'org.turkinnovations.xbeed.XBeeInterface'
XBEED_DAEMON_OBJECT = '/XBeeInterfaces/%s'
XBEED_MODULE_OBJECT = '/XBeeModules/%X'

log = turk.init_logging('xbeed')

class XBeeDaemon(dbus.service.Object):
    """
    Main class which connects dbus API and serial communication
    name: Unique DBUS object name for this instance
    All other arguments are passed off to the underlying pySerial implementation
    """
    def __init__(self, name, port, escaping=True, baudrate=9600):
        self.port, self.baudrate = port, baudrate
        self.serial_type = EscapingSerial if escaping else Serial

        self.object_path = XBEED_DAEMON_OBJECT % name
        self.partial = PartialFrame()
        dbus.service.Object.__init__(self, BUS_NAME, self.object_path)