def get_json_config( request, c ): response = request.response netpath = request.matchdict.get( 'netpath', 'platform' ) section = request.matchdict.get( 'section', None ) if netpath == 'platform' : settings = request.pa.settings else : settings = request.pa.netpaths[netpath].appsettings setts = settings[section] if section else settings json = h.json_encode( setts ) response.write( json ) response.flush( finishing=True )
def config(self, **kwargs): """:meth:`pluggdapps.interfaces.IConfigDB.config` interface method. Keyword arguments, ``netpath``, Netpath, including subdomain-hostname and script-path, on which web-application is mounted. Optional. ``section``, Section name to get or set config parameter. Optional. ``name``, Configuration name to get or set for ``section``. Optional. ``value``, If present, this method was invoked for setting configuration ``name`` under ``section``. Optional. - if netpath, section, name and value kwargs are supplied, will update config-parameter `name` under webapp's `section` with `value`. Return the updated value. - if netpath, section, name kwargs are supplied, will return configuration `value` for `name` under webapp's `section`. - if netpath, section kwargs are supplied, will return dictionary of all configuration parameters under webapp's section. - if netpath is supplied, will return the entire table as dictionary of sections and settings. - if netpath is not supplied, will use `section`, `name` and `value` arguments in the context of ``platform`` table. """ if self.conn == None: return None netpath = kwargs.get('netpath', 'platform') section = kwargs.get('section', None) name = kwargs.get('name', None) value = kwargs.get('value', None) c = self.conn.cursor() if section: c.execute("SELECT * FROM '%s' WHERE section='%s'" % (netpath, section)) result = list(c) secsetts = h.json_decode(result[0][1]) if result else {} if name and value: secsetts[name] = value secsetts = h.json_encode(secsetts) c.execute("DELETE FROM '%s' WHERE section='%s'" % (netpath, section)) c.execute("INSERT INTO '%s' VALUES ('%s', '%s')" % (netpath, section, secsetts)) self.conn.commit() rc = value elif name: rc = secsetts[name] else: rc = secsetts else: c.execute("SELECT * FROM '%s'" % (netpath, )) rc = {section: h.json_decode(setts) for section, setts in list(c)} return rc
def config( self, **kwargs ): """:meth:`pluggdapps.interfaces.IConfigDB.config` interface method. Keyword arguments, ``netpath``, Netpath, including subdomain-hostname and script-path, on which web-application is mounted. Optional. ``section``, Section name to get or set config parameter. Optional. ``name``, Configuration name to get or set for ``section``. Optional. ``value``, If present, this method was invoked for setting configuration ``name`` under ``section``. Optional. - if netpath, section, name and value kwargs are supplied, will update config-parameter `name` under webapp's `section` with `value`. Return the updated value. - if netpath, section, name kwargs are supplied, will return configuration `value` for `name` under webapp's `section`. - if netpath, section kwargs are supplied, will return dictionary of all configuration parameters under webapp's section. - if netpath is supplied, will return the entire table as dictionary of sections and settings. - if netpath is not supplied, will use `section`, `name` and `value` arguments in the context of ``platform`` table. """ if self.conn == None : return None netpath = kwargs.get( 'netpath', 'platform' ) section = kwargs.get( 'section', None ) name = kwargs.get( 'name', None ) value = kwargs.get( 'value', None ) c = self.conn.cursor() if section : c.execute( "SELECT * FROM '%s' WHERE section='%s'" % (netpath,section)) result = list(c) secsetts = h.json_decode( result[0][1] ) if result else {} if name and value : secsetts[name] = value secsetts = h.json_encode(secsetts) c.execute( "DELETE FROM '%s' WHERE section='%s'" % (netpath, section) ) c.execute( "INSERT INTO '%s' VALUES ('%s', '%s')" % (netpath, section, secsetts) ) self.conn.commit() rc = value elif name : rc = secsetts[name] else : rc = secsetts else : c.execute( "SELECT * FROM '%s'" % (netpath,) ) rc = { section : h.json_decode( setts ) for section, setts in list(c) } return rc