Esempio n. 1
0
    def _test_db(self, time, dbname):
        """
        Verify that the db is valid before saving the value.

        Skips databases that don't match the criteria specified. If
        self.verifytables is set, extra tests are performed to ensure that the
        database contains the requested tables, and that the tables contain
        data.
        """

        self.logger.debug("Test for time=%s =>> %s" % (time, dbname))

        # if os.path.isfile(dbname):
        #    self.dbs[dbname] = {'times': [time,endtime]}
        #    return

        # if self.glob("%s.*" % dbname):
        #    self.dbs[dbname] = {'times': [time,endtime]}
        #    self.logger_instance.warning( "No descriptor file for (%s)." % dbname )
        #    return
        db = None
        dbtbl = None
        try:
            db = datascope.dbopen(dbname, "r")
        except datascope.DatascopeError:
            self.logger.error("Cannot dbopen %s, skipping." % dbname)
            return False
        else:
            for table in self.required_tables:
                try:
                    dbtbl = db.lookup(table=table)
                    try:
                        dbtbl.query(datascope.dbTABLE_PRESENT)
                        records = dbtbl.query(datascope.dbRECORD_COUNT)
                        if not records:
                            self.logger.error(
                                "%s.%s is an empty table. Skipping db."
                                % (dbname, table)
                            )
                            return False
                    except datascope.DatascopeError:
                        self.logger.error(
                            "The table %s.%s is not present. Skipping db."
                            % (dbname, table)
                        )
                        return False
                finally:
                    if dbtbl is not None:
                        datascope.dbfree(dbtbl)
        finally:
            if db is not None:
                datascope.dbclose(db)

        # If we get here, the database passes our tests. Add it to the station_patterns
        return True
def generate_sta_locations(db, mtype, deploytype, year, month, verbose=False, debug=False):
    """Generate station locations for specific
    periods in time and write out to xy files 
    suitable for GMT
    """
    start_time, end_time = generate_times(year, month)

    # Get the networks
    snetptr = antdb.dbopen(db, 'r')
    snetptr = antdb.dbprocess(snetptr,
                            ['dbopen site',
                             'dbjoin snetsta',
                             'dbjoin deployment'])
    snetptr = antdb.dbsort(snetptr,'snet', unique=True)
    usnets = []
    try:
        for i in range(antdb.dbquery(snetptr, antdb.dbRECORD_COUNT )):
            snetptr['record'] = i
            mysnet = antdb.dbgetv(snetptr,'snet')[0]
            usnets.append(mysnet)
        antdb.dbclose(snetptr)
    except Exception, e:
        print "generate_sta_locations(): Exception occurred: %s" % e
                            counter['complete'] += 1
                        elif sensors['MEMS'] and sensors['NCPA']:
                            os.write(infra_tmp_ncpa[0], "%s    %s    # %s \n" % (lat, lon, sta))
                            counter['ncpa'] += 1
                        elif sensors['MEMS'] and sensors['SETRA']:
                            os.write(infra_tmp_setra[0], "%s    %s    # %s \n" % (lat, lon, sta))
                            counter['setra'] += 1
                        elif sensors['MEMS']:
                            os.write(infra_tmp_mems[0], "%s    %s    # %s \n" % (lat, lon, sta))
                            counter['mems'] += 1
            os.close(infra_tmp_all[0])
            os.close(infra_tmp_mems[0])
            if mtype == 'cumulative':
                os.close(infra_tmp_decom[0])
            antdb.dbfree(infraptr_grp)
        antdb.dbclose(infraptr)
    return file_list, counter
 
def generate_sta_locations(db, mtype, deploytype, year, month, verbose=False, debug=False):
    """Generate station locations for specific
    periods in time and write out to xy files 
    suitable for GMT
    """
    start_time, end_time = generate_times(year, month)

    # Get the networks
    snetptr = antdb.dbopen(db, 'r')
    snetptr = antdb.dbprocess(snetptr,
                            ['dbopen site',
                             'dbjoin snetsta',
                             'dbjoin deployment'])