def test_name(self): # Access name assigned during creation. name, db = self.temp_db() self.assertTrue(db.name == name) # Access lazily loaded name, self.assertTrue(client.Database(db.resource.url).name == name)
def test_exists(self): self.assertTrue(self.db) self.assertFalse(client.Database('couchdb-python/missing'))
feedId = args[0] feedStatus = False if string.lower(args[1]) in [ "true", "on", "activate", "yes", "indubitably", "positive", "1", "start" ]: feedStatus = True docId = feedId if '.' in docId: lst = docId.split('.') docId = lst[len(lst) - 1] couchhost = options.couchdb if couchhost[-1] == '/': couchhost = couchhost[:-1] db = couch.Database('%s/feedshub_status/' % options.couchdb) statusDoc = db.get(docId + "_status") if statusDoc == None: print "Unable to find the status for feed id " + docId sys.exit(1) routingkey = feedId if statusDoc['type'] == 'terminal-status': configDoc = db.get(feedId) routingkey = '' for server in configDoc['servers']: routingkey += '%s.' % server['server'] routingkey += '%s' % feedId statusDoc['active'] = feedStatus
elif view_arg == 'servers': view = '_design/servers/_view/join' entry_type = 'server' elif view_arg == 'terminals': view = '_design/terminals/_view/join' entry_type = 'terminal' args = args[1:] entry_status = entry_type + '-status' if options.active_only: view = view + "_active" couchdb = options.couchdb if couchdb[-1] == '/': couchdb = couchdb[:-1] db = couch.Database("%s/feedshub_status" % couchdb) for row in db.view(view, group=True): if row.value != None: doc_id = row.value[entry_type]['_id'] if len(args) > 0 and not doc_id in args: continue if options.dump: s = json.dumps(row.value, sort_keys=True, indent=4) print '\n'.join([l.rstrip() for l in s.splitlines()]) else: active = 'inactive' if row.value[entry_status]['active']: active = 'active' print row.value[entry_type]['_id'] + '\t' + active
def __init__(self, config): self.__monitor = threading.RLock() msghostspec = config['messageserver'] self.__conn = amqp_connection_from_config(msghostspec) self.__channel = self.__conn.channel() self.__channel.tx_select() self.__publication_error = False self.__log = self.__conn.channel() # a new channel which isn't tx'd self.build_loggers_and_notifier(config) if 'database' in config and config['database'] is not None: self.__db = couch.Database(config['database']) else: self.__db = None settings = dict((item['name'], item['value']) for item in config['plugin_type'] ['global_configuration_specification']) settings.update(config['configuration']) self._static_config = settings self._instance_config = config['configuration'] for name, exchange in config['outputs'].iteritems(): if name not in self.OUTPUTS: self.OUTPUTS[name] = name setattr( self, self.OUTPUTS[name], self._make_exchange_publisher(self.__channel, exchange, '')) def handler(fun): def handle(msg): if 'application_headers' in msg.properties: headers = msg.properties['application_headers'] if headers and PLUGIN_CONFIG_HEADER in headers: config = headers[PLUGIN_CONFIG_HEADER] self.debug("Plugin config found: %r" % config) try: headerConfig = config if not isinstance(headerConfig, dict): raise "Not a dict" except: self.error( "Could not use config: %r; ignoring message" % config) return dynamic = self.interpolate(headerConfig, self._static_config) return fun(msg, dynamic) return fun(msg, self.interpolate({}, self._static_config)) return handle for name, queue in config['inputs'].iteritems(): if name not in self.INPUTS: self.INPUTS[name] = name method = getattr(self, self.INPUTS[name]) self._subscribe_to_queue(queue, handler(method)) self.info( pformat({ "event": "configured", "args": { "config": settings } }))
def __init__(self, config): super(Server, self).__init__(config) self.__server_id = config['server_id'] self.__terminalsDb = couch.Database(config['terminals_database'])