def test_method_open(self): db = antdb.dbopen(self.testdbname, 'r') self.assertTrue(db[0] >= 0) self.assertEqual(db[1], -501) self.assertEqual(db[2], -501) self.assertEqual(db[3], -501) db.close()
def test_method_lookup_clusters(self): db = antdb.dbopen(self.testdbname, 'r') db.lookup(table='clusters') self.assertTrue(db[0] >= 0) self.assertEqual(db[1], 0) self.assertEqual(db[2], -501) self.assertEqual(db[3], -501) db.close()
def test_method_paths(self): db = antdb.dbopen(self.testdbname, 'r') db.lookup(table='clusters') db.subset('clustername =~ /%s/' % self.testclustername) db[3]=0 dbcentral = DbCentral(self.testdbname, self.testclustername, False) paths = dbcentral.namelist() self.assertTrue(len(paths) > 0) db.close()
def test_method_lookup_clustername(self): db = antdb.dbopen(self.testdbname, 'r') db.lookup(table='clusters') db.subset('clustername =~ /%s/' % self.testclustername) self.assertTrue(db.query('dbRECORD_COUNT') >= 0) self.assertTrue(db.table >= 0) self.assertEqual(db[2], -501) self.assertEqual(db[3], -501) db.close()
def get_decom_stations(): """Return a list of all decommissioned stations """ db = datascope.dbopen(dbmaster, 'r') db.lookup('', 'deployment', '', '') db.subset('snet=~/TA/') db.sort(['sta','time']) db.group('sta') stas = group_loop(db) return stas
def get_nulls(): """Return all the null values for the defined fields """ nulls_dict = {} db = datascope.dbopen(dbmaster, 'r') db.lookup('', 'deployment', '', '') for f in dbmaster_fields: db.lookup('', '', f, 'dbNULL') nulls_dict[f] = db.getv(f)[0] return nulls_dict
def namelist(self): """Get the list of resolved paths """ if not os.path.exists(self.path) and not os.path.isfile(self.path): if not legacy: antelog.elog_die("%s %s *die*: Dbpath '%s' does not exist." % (self.errstr, self.base, self.path)) else: antstock.elog_die("%s %s *die*: Dbpath '%s' does not exist." % (self.errstr, self.base, self.path)) db = antdb.dbopen(self.path, 'r') db.lookup(table='clusters') db.lookup(record='dbNULL') try: null_time, null_endtime = db.getv('time', 'endtime') except Exception, e: if not legacy: antelog.elog_die("%s %s *die*: %s" % (self.errstr, self.base, e)) else: antstock.elog_die("%s %s *die*: %s" % (self.errstr, self.base, e))
def main(): """Process all decommissioned stations """ if verbose: print "Start updating RRD archive at %s" % strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime()) print "ACTIVE DATALOGGER RRD DB: %s" % rrddb print "ACTIVE COMMS RRD DB: %s" % rrddb_im print "ACTIVE VTW RRD DB: %s" % rrddb_vtw print "DBMASTER: %s" % dbmaster print "Get Antelope NULL values" dbnulls_dict = get_nulls() if verbose: print "Get endtimes for decommissioned stations" sta_grps = get_decom_stations() for rp_key,rp_val in rrd_pointers.items(): dbpt = rrd_pointers[rp_key] if verbose: print " - Start: Update RRD %s cache archive (%s)" % (rp_key, dbpt) dbrrd = datascope.dbopen(dbpt, 'r+') dbrrd.lookup('', 'rrdcache', '', '') dbrrd.subset("net=~/TA/ && endtime == '%.5f'" % dbnulls_dict['endtime']) dbrrd.sort('sta') for j in range(dbrrd.query('dbRECORD_COUNT')): dbrrd[3] = j rrd_sta, rrd_sta_var, rrd_sta_time, rrd_sta_endtime = dbrrd.getv('sta', 'rrdvar', 'time', 'endtime') if rrd_sta in sta_grps: print ' - Sta: %s, Rrdvar: %s, Current endtime: %.5f, New endtime: %.5f' % (rrd_sta, rrd_sta_var, rrd_sta_endtime, sta_grps[rrd_sta]['endtime']) dbrrd.putv('endtime', '%s' % sta_grps[rrd_sta]['endtime']) if verbose: print ' - End: Update RRD %s cache archive (%s)' % (rp_key, dbpt) print 'Finished updating all RRD cache archives' if verbose: print "Finished updating RRD archive at %s\n" % strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime())