def load_module (name, dirname): # Sanity check if not name: return # Check the different plug-in dirs srv = get_server() for path in srv.plugin_paths: mod_path = os.path.abspath (os.path.join (path, dirname)) fullpath = os.path.join (mod_path, "%s.py"%(name)) if os.access (fullpath, os.R_OK): break # Shortcut: it might be loaded if sys.modules.has_key (name): if sys.modules[name].__file__ == fullpath: return sys.modules[name] # Load the plug-in fullpath = os.path.join (mod_path, "%s.py"%(name)) try: return imp.load_source (name, fullpath) except IOError: print "Could not load '%s'." %(fullpath) raise
def __init__ (self, key, modules, **kwargs): def key_to_url (key): return ''.join ([('_',c)[c in string.letters + string.digits] for c in key]) Widget.__init__ (self) # Properties self._key = key self._mods = modules active_name = cfg.get_val (self._key) # URL self._url = '/plugin_content_%s' %(key_to_url(key)) srv = get_server() if srv.use_sec_submit: self._url += '?key=%s' %(srv.sec_submit) # Widgets self.selector_widget = ComboCfg (key, modules) self.plugin = instance_plugin (active_name, key, **kwargs) # Register hidden URL for the plugin content publish (r'^/plugin_content_%s' %(key_to_url(key)), PluginInstanceProxy, key=key, modules=modules, method='POST', **kwargs)
def load_module(name, dirname): # Sanity check if not name: return # Check the different plug-in dirs srv = get_server() for path in srv.plugin_paths: mod_path = os.path.abspath(os.path.join(path, dirname)) fullpath = os.path.join(mod_path, "%s.py" % (name)) if os.access(fullpath, os.R_OK): break # Shortcut: it might be loaded if sys.modules.has_key(name): loaded_mod_file = sys.modules[name].__file__ if loaded_mod_file.endswith('.pyc'): loaded_mod_file = loaded_mod_file[:-1] if loaded_mod_file == fullpath: return sys.modules[name] # Load the plug-in fullpath = os.path.join(mod_path, "%s.py" % (name)) try: return imp.load_source(name, fullpath) except IOError: print "Could not load '%s'." % (fullpath) raise
def __init__(self, key, modules, **kwargs): def key_to_url(key): return ''.join([('_', c)[c in string.letters + string.digits] for c in key]) Widget.__init__(self) # Properties self._key = key self._mods = modules active_name = cfg.get_val(self._key) # URL self._url = '/plugin_content_%s' % (key_to_url(key)) srv = get_server() if srv.use_sec_submit: self._url += '?key=%s' % (srv.sec_submit) # Widgets self.selector_widget = ComboCfg(key, modules) self.plugin = instance_plugin(active_name, key, **kwargs) # Register hidden URL for the plugin content publish(r'^/plugin_content_%s' % (key_to_url(key)), PluginInstanceProxy, key=key, modules=modules, method='POST', **kwargs)
def __init__(self, submit_url): Container.__init__(self) self.url = submit_url self.id = "submitter%d" % (self.uniq_id) # Secure submit srv = get_server() if srv.use_sec_submit: self.url += '?key=%s' % (srv.sec_submit)
def __init__ (self, submit_url): Container.__init__ (self) self.url = submit_url self.id = "submitter%d" %(self.uniq_id) # Secure submit srv = get_server() if srv.use_sec_submit: self.url += '?key=%s' %(srv.sec_submit)
def __init__ (self, key, url, optional=False, props=None): self.key = key self.url = url TextCfg.__init__ (self, key, optional, props) # Secure submit srv = get_server() if srv.use_sec_submit: self.url += '?key=%s' %(srv.sec_submit)
def __init__(self, key, url, optional=False, props=None): self.key = key self.url = url TextCfg.__init__(self, key, optional, props) # Secure submit srv = get_server() if srv.use_sec_submit: self.url += '?key=%s' % (srv.sec_submit)
def __init__ (self, callback, container, *args, **kwargs): Table.__init__ (self, *args, **kwargs) self.id = "sortablelist_%d" %(self.uniq_id) self.url = "/sortablelist_%d"%(self.uniq_id) self.container = container # Secure submit srv = get_server() if srv.use_sec_submit: self.url += '?key=%s' %(srv.sec_submit) # Register the public URL publish (r"^/sortablelist_%d"%(self.uniq_id), changed_handler_func, method='POST', callback=callback, key_id='%s_order'%(self.id), **kwargs)
from Server import get_server def Ajax(url, data='', type='POST', async=True, dataType='json', success=None, error=None, complete=None): if not success: success = '' if type.upper() == 'POST': srv = get_server() if srv.use_sec_submit: url += '?key=%s' % (srv.sec_submit) async_s = ['false', 'true'][async] js = "$.ajax ({type: '%(type)s', url: '%(url)s', async: %(async_s)s" % ( locals()) if data: js += ", data: %(data)s, dataType: '%(dataType)s'" % (locals()) js += """, success: function (data) { %(success)s; /* Modified: Save button */ var modified = data['modified'];
from Client.Client import create_client import threading from Server import get_server create_client() server = get_server() def setUp(): serverThread = threading.Thread(target=server.serve) serverThread.start() def testServer1(server): assert server.data[0][1] == 55.09 assert server.data[4][1] == 55.77 assert server.data[4][0] == '2019-01-01 01:15:00' def testServer2(server): assert isinstance(server_pb2.reading, server.getReading('2019-01-01 05:15:00', 63.52)) def testServerClient(): ## go to http://localhost:8888/ ## ensure JSON data is pulled when button is pressed assert True
# 02110-1301, USA. # """ The CTK.JS module wraps several utility Javascript functions. """ from Server import get_server def Ajax (url, data='', type='POST', async=True, dataType='json', success=None, error=None, complete=None): if not success: success='' if type.upper() == 'POST': srv = get_server() if srv.use_sec_submit: url += '?key=%s' %(srv.sec_submit) async_s = ['false','true'][async] js = "$.ajax ({type: '%(type)s', url: '%(url)s', async: %(async_s)s" %(locals()) if data: js += ", data: %(data)s, dataType: '%(dataType)s'" %(locals()) js += """, success: function (data) { %(success)s; /* Modified: Save button */ var modified = data['modified']; var not_modified = data['not-modified'];