示例#1
0
def found_action(address, record, dongle):
    line = LogLine()
    line.content = "Found action for: %s" % address
    try:
        for plugin in pluginsystem.get_plugins("found_action"):
            logger.info("found action trying with %s" % plugin.name)
            service = plugin.rpc["found_action"](record=record, dongle=dongle)
            if service:
                logger.info("plugin has handled")
                line.content += " %s is handling" % getattr(plugin, "name", "plugin")
                line.save()
                OpenProximityService.addPending(address, service)
                return True
    except Exception, err:
        logger.error("plugin do_action")
        logger.exception(err)
示例#2
0
def found_action(services, address, record, pending, dongle):
    line = LogLine()
    line.content="Found action for: %s" % address
    try:
        for plugin in pluginsystem.get_plugins('found_action'):
            logger.info("found action trying with %s" % plugin.name)
            service = plugin.rpc['found_action'](services=services, record=record)
            if service:
                logger.info("plugin has handled")
                line.content+=" %s is handling" % getattr(plugin, 'name', 
                                                                    'plugin')
                line.save()
                pending[record.remote.address]=service
                return True
    except Exception, err:
        logger.error("plugin do_action")
        logger.exception(err)
示例#3
0
 def exposed_listener(self, signal, *args, **kwargs):
     global enabled
     
     if not enabled:
         logger.debug("rpc is locked, dropping signal %s" % signal)
         return
     
     logger.debug("exposed_listener %s %s %s" % ( signal, args, kwargs) )
     kwargs['pending']=pending
     
     try:
         for plugin in pluginsystem.get_plugins('rpc'):
     	     plugin.rpc['handle'](signal=signal, services=services, manager=self, *args, **kwargs)
         transaction.commit() # commit only after all the plugins have handled
     except Exception, err:
         logger.error("rpc listener while doing plugins")
         logger.exception(err)
         transaction.rollback() # oops rollback
示例#4
0
def runclient(argset=[], **kwargs):
    # Get the options
    options = CLIENT_OPTIONS.copy()
    options.update(kwargs)

    from net.aircable.utils import getLogger
    logger = getLogger(__name__)

    if options['daemonize']:
        if not options['pidfile']:
            options['pidfile'] = '/var/run/openproximity_client_%s_%s.pid' % ( \
                options['mode'], options['port'] )

        logger.info("storing pid file in %s" % options['pidfile'])
        from django.utils.daemonize import become_daemon
        
        logger.info("daemonizing")
        become_daemon()
        logger.info("daemonized")

        fp = open(options['pidfile'], 'w')
        fp.write("%d\n" % os.getpid())
        fp.close()

    # Start the rpc server
    logger.debug('starting client with options %s' % options)
    mode = options['mode']
    host = options['host']
    port = int(options['port'])
    valid_modes=['scanner', 'uploader', 'pairing']
    from net.aircable.openproximity.pluginsystem import pluginsystem
    valid_modes.extend([ \
            i.provides['serverxr_type'] for i in \
                pluginsystem.get_plugins('serverxr')])
    if mode not in valid_modes:
        print "not a valid mode, use any of", valid_modes
        sys.exit(1)
    from rpc_clients import manager
    manager.run(host, port, mode)
示例#5
0
        def exposed_generic_register(self, remote_quit=None, 
    						dongles=None, 
    						client=None):
            logger.info("generic register")

            all_dongles.update(dongles)

            if not enabled:
                return

            if not db_ready():
        	return

            try:
                for plugin in pluginsystem.get_plugins('rpc_register'):
                        logger.debug("plugin %s provides rpc register" % plugin.name)
                        if plugin.rpc['register'](dongles=dongles, client=client):
                            # wrap all calls as async, to avoid collitions
                            self.remote_quit = async(remote_quit)
                            logger.info("plugin %s handled rpc_register" % plugin.name)
                            return
            except Exception, err:
                logger.exception(err)
示例#6
0
        logger.info("database locked")
    except:
        pass

    logger.info("about to drop")
    for line in drop.splitlines():
        try:
            logger.debug(line)
            connection.cursor().execute(line)
        except Exception, err:
            logger.error("%s failed" % line)
            logger.exception(err)

    logger.info("allowing plugins to drop statistic it's tables")

    for plugin in pluginsystem.get_plugins("statistics_reset"):
        try:
            getattr(plugin.module, "statistics_reset")(connection)
        except Exception, err:
            logger.error("plugin failed to reset statistics %s" % plugin)
            logger.exception(err)

    logger.info("calling syncdb")
    management.call_command("syncdb", migrate_all=True)

    try:
        server = rpyc.connect("localhost", 8010)
        server.root.Unlock()
        server.root.restart()
    except:
        pass
示例#7
0
        logger.info("database locked")
    except:
        pass

    logger.info("about to drop")
    for line in drop.splitlines():
        try:
            logger.debug(line)
            connection.cursor().execute(line)
        except Exception, err:
            logger.error("%s failed" % line)
            logger.exception(err)

    logger.info("allowing plugins to drop statistic it's tables")

    for plugin in pluginsystem.get_plugins('statistics_reset'):
        try:
            getattr(plugin.module, 'statistics_reset')(connection)
        except Exception, err:
            logger.error("plugin failed to reset statistics %s" % plugin)
            logger.exception(err)

    logger.info("calling syncdb")
    management.call_command('syncdb', migrate_all=True)

    try:
        server = rpyc.connect('localhost', 8010)
        server.root.Unlock()
        server.root.restart()
    except:
        pass
示例#8
0
#    You should have received a copy of the GNU General Public License along
#    with this program; if not, write to the Free Software Foundation, Inc.,
#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

import os, sys
from net.aircable.openproximity.pluginsystem import pluginsystem

from net.aircable.utils import getLogger
logger = getLogger(__name__)

TEMPLATE_DIRS=()
LOCALE_PATHS=()
INSTALLED_APPS=()

logger.info("starting up plugins")
for plugin in pluginsystem.get_plugins('django'):
    if plugin.provides.get('TEMPLATE_DIRS', None) is not None :
        TEMPLATE_DIRS += ( 
            os.path.join(plugin.path, plugin.provides['TEMPLATE_DIRS']), )
    if plugin.provides.get('LOCALE_PATHS', None) is not None:
        LOCALE_PATHS+=( 
            os.path.join(plugin.path, plugin.provides['LOCALE_PATHS']), )
    if plugin.provides.get('django', False):
        INSTALLED_APPS+=( plugin.name, )

logger.info("starting up plugin providers")
for plugin in pluginsystem.get_plugins('plugin_provider'):
    for plug in pluginsystem.get_plugins(
            plugin.provides['plugin_provider_name']):
        INSTALLED_APPS+=( plug.name, )
SERIALIZATION_MODULES = {
    'json': 'wadofstuff.django.serializers.json'
}

# register our time zone aware user
AUTH_PROFILE_MODULE = "openproximity.UserProfile"

# load xml settings
OPENPROXIMITY = XMLTool('/etc/openproximity2/settings.xml')

# when logged in just send the user back to the main page
LOGIN_REDIRECT_URL = "/"

logger.info("starting up plugins")
pluginsystem.find_plugins()
for plugin in pluginsystem.get_plugins('django'):
    if plugin.provides.get('TEMPLATE_DIRS', None) is not None :
        TEMPLATE_DIRS += ( os.path.join(plugin.path, plugin.provides['TEMPLATE_DIRS']), )
    if plugin.provides.get('LOCALE_PATHS', None) is not None:
        LOCALE_PATHS += ( os.path.join(plugin.path, plugin.provides['LOCALE_PATHS']), )
    if plugin.provides.get('django_app', False):
        INSTALLED_APPS += (plugin.name,)

logger.info("starting up plugin providers")
for plugin in pluginsystem.get_plugins('plugin_provider'):
    for plug in pluginsystem.get_plugins(plugin.provides['plugin_provider_name']):
        INSTALLED_APPS += (plug.name, )

logger.info("plugin system initied")
logger.info("settings.py loaded")
示例#10
0
        server.root.Lock()
        logger.info("database locked")
    except:
        pass

    logger.info("about to drop")
    for line in drop.splitlines():
        try:
            connection.cursor().execute(line)       
        except Exception, err:
            logger.error("%s failed" %line)
            logger.exception(err)

    logger.info("allowing plugins to drop statistic it's tables")

    for plugin in pluginsystem.get_plugins('statistics_reset'):
        try:
            getattr(plugin.module,'statistics_reset')(connection)
        except Exception, err:
            logger.error("plugin failed to reset statistics %s" % plugin)
            logger.exception(err)

    logger.info("calling syncdb")
    management.call_command('syncdb', migrate_all=True)
    
    try:
        server=rpyc.connect('localhost', 8010)
        server.root.Unlock()
        server.root.restart()
    except:
        pass
示例#11
0
    #include translation site
    (r'^admin/translate/', include('rosetta.urls'), {}, "translate"),

    # Uncomment the admin/doc line below and add 'django.contrib.admindocs'
    # to INSTALLED_APPS to enable admin documentation:
    #    (r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
    (r'^admin/', include(admin.site.urls), {}, "admin"),
    (r'^site_media/(?P<path>.*)$', 'django.views.static.serve', {
        'document_root': os.path.join(os.path.dirname(__file__), 'media')
    }, "site-media"),
    (r'^notification/', include('notification.urls'), {}, "notification"),
)

for plugin in pluginsystem.get_plugins('urls'):
    logger.info("%s provides urls" % plugin.provides.get('name', plugin.name))
    url, path = plugin.provides.get('urls')
    urlpatterns += patterns(
        '',
        (
            r'^%s/' % url,
            include('%s.%s' % (plugin.name, path)),
            {},
            plugin.name  # allow url to be reverse resolved
        ))

urlpatterns += patterns(
    '', (r'', include('openproximity.urls'), {}, "openproximity"))
示例#12
0
 def render(self, context):
     context['plugins'] = pluginsystem.get_plugins('urls')
     return ''
示例#13
0
def run(server_, port, type_):
    '''
	Will get called from a child process once the autoreload system is ready
	everything will be setup so the rpc client can work.
    '''
    global server, manager, bus, loop
    
    loop=gobject.MainLoop()
    
    # first connect to the server, we can't do much without it
    try:
        server = rpyc.connect(server_, int(port))
    except:
        import time
        logger.info("server is not running")
        time.sleep(10)
        autoreload.RELOAD = True
        sys.exit(3)

    # now try to get into dbus and init gobject
    bus=dbus.SystemBus()
    gobject.threads_init()
    dbus.glib.init_threads()

    # register for a few signals
    bus.add_signal_receiver(
        handle_name_owner_changed,
        'NameOwnerChanged',
        'org.freedesktop.DBus',
        'org.freedesktop.DBus',
        '/org/freedesktop/DBus'
    )

    bus.add_signal_receiver(
        handle_adapter_added_or_removed,
        signal_name='AdapterAdded',
        dbus_interface='org.bluez.Manager',
        member_keyword='signal' 
    )

    bus.add_signal_receiver(
        handle_adapter_added_or_removed,
        signal_name='AdapterRemoved',
        dbus_interface='org.bluez.Manager',
        member_keyword='signal'
    )

    # create the manager and register for init
    try:
        if type_ == 'scanner':
            from scanner import ScanManager
            logger.info("init scanner")
            manager = ScanManager(bus, rpc=server)
        elif type_ == 'uploader':
            logger.info("init uploader")
            from uploader import UploadManager
            manager = UploadManager(bus, rpc=server, loop=loop)
        else:
            for i in pluginsystem.get_plugins('serverxr'):
                if type_==i.provides['serverxr_type']:
                    logger.info("init %s" % i.provides['serverxr_type'])
                    module = __import__("%s.serverxr" % i.name, 
                                        fromlist=[
                            i.provides['serverxr_manager'],])
                    klass = getattr(module, i.provides['serverxr_manager'])
                    manager = klass (bus, rpc=server)
                    break
        if manager is None:
            raise Exception ("Not valid type")
        gobject.timeout_add(100, init) 
        # delay initialization 'til loop is running
    except dbus.DBusException, err:
        logger.info("bluez isn't ready, delaying init")
示例#14
0
        # delay initialization 'til loop is running
    except dbus.DBusException, err:
        logger.info("bluez isn't ready, delaying init")

    # start our loop and setup ping
    flags = gobject.IO_IN | gobject.IO_ERR | gobject.IO_HUP
    gobject.io_add_watch(server.fileno(), flags, poll)
    # give control to the mainloop
    loop.run()

    # if we get here by any how then it's time to restart
    autoreload.RELOAD = True

if __name__ == '__main__':
    from django.core.management import execute_manager, setup_environ
    import settings
    setup_environ(settings)

    # get a list of valid modes
    valid_modes=['scanner', 'uploader']

    valid_modes.extend(
        [ i.provides['serverxr_type'] 
            for i in pluginsystem.get_plugins('serverxr') ] )

    if sys.argv[3] not in valid_modes:
        print "not valid type, you can use any of", valid_modes
        sys.exit(0)

    run(*sys.argv[1:4])
    def render(self, context):
        context['plugins'] = pluginsystem.get_plugins('urls')
	return ''
示例#16
0
    
    # Uncomment the admin/doc line below and add 'django.contrib.admindocs' 
    # to INSTALLED_APPS to enable admin documentation:
#    (r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
    (r'^admin/', include(admin.site.urls),{},"admin"),
    
    (r'^site_media/(?P<path>.*)$', 'django.views.static.serve',
        {       'document_root': os.path.join(os.path.dirname(__file__), 'media')},
        "site-media"
    ),
    
    (r'^notification/', include('notification.urls'),{},"notification"),
)

for plugin in pluginsystem.get_plugins('urls'):
    logger.info("%s provides urls" % plugin.provides.get('name', plugin.name))
    url, path = plugin.provides.get('urls')
    urlpatterns += patterns( '', 
        (r'^%s/' % url, 
            include('%s.%s' % ( plugin.name, path)),
            {},
            plugin.name # allow url to be reverse resolved
    ))

urlpatterns += patterns('', 
    (r'', include('openproximity.urls'),{},"openproximity")
)

示例#17
0
	    
Choose only the templates you want to get automatically filled.

Don\'t forget to mark the <b>Save Settings</b> field if you want changes to be persisted'''
              ))

myadmin = MyAdminSite()
myadmin.register(SensorCampaign, SensorCampaignAdmin)
myadmin.register(SensorSDKBluetoothDongle, SensorDongleAdmin)
myadmin.register(AlertDefinitionTemplate, AlertDefinitionTemplateAdmin)
myadmin.register(AlertDefinition, AlertDefinitionAdmin)
myadmin.register(Alert, AlertAdmin)

# add user creation forms
myadmin.register(User, UserAdmin)

# now it's time to get the rest of the admins
from net.aircable.openproximity.pluginsystem import pluginsystem
for plugin in pluginsystem.get_plugins('sensorsdk'):
    try:
        logger.debug("import admin for plugin %s" % plugin.name)
        mod = __import__("%s.sdkadmin" % plugin.name, fromlist=['register'])
        if not getattr(mod, 'register', None):
            logger.debug("no admin provided by %s" % plugin.name)
            continue
        for k, a in getattr(mod, 'register')():
            myadmin.register(k, a)
        logger.debug("admin loaded for %s" % plugin.name)
    except Exception, err:
        logger.error("couldn't load admin for %s" % plugin.name)