コード例 #1
0
    def __init__(self, *args):

        self.logging = getLogger()

        self.logging.debug('New Document')

        self.data = args[0]
コード例 #2
0
    def __init__(self, *args):

        self.logging = getLogger()

        self.logging.debug('New Document')

        self.data = args[0]
コード例 #3
0
def open_verify_pf(pf, mttime=False):
    """
    Verify that we can get the file and check
    the value of PF_MTTIME if needed.
    Returns pf_object
    """

    logging = getLogger()

    logging.debug("Look for parameter file: %s" % pf)

    if mttime:
        logging.debug("Verify that %s is newer than %s" % (pf, mttime))

        PF_STATUS = stock.pfrequire(pf, mttime)
        if PF_STATUS == stock.PF_MTIME_NOT_FOUND:
            logging.warning("Problems looking for %s. PF_MTTIME_NOT_FOUND." % pf)
            logging.error("No MTTIME in PF file. Need a new version of the %s file!!!" % pf)
        elif PF_STATUS == stock.PF_MTIME_OLD:
            logging.warning("Problems looking for %s. PF_MTTIME_OLD." % pf)
            logging.error("Need a new version of the %s file!!!" % pf)
        elif PF_STATUS == stock.PF_SYNTAX_ERROR:
            logging.warning("Problems looking for %s. PF_SYNTAX_ERROR." % pf)
            logging.error("Need a working version of the %s file!!!" % pf)
        elif PF_STATUS == stock.PF_NOT_FOUND:
            logging.warning("Problems looking for %s. PF_NOT_FOUND." % pf)
            logging.error("No file  %s found!!!" % pf)

        logging.debug("%s => PF_MTIME_OK" % pf)

    try:
        return stock.pfread(pf)
    except Exception, e:
        logging.error("Problem looking for %s => %s" % (pf, e))
コード例 #4
0
    def __init__(self, database=None, dbpointer=None, table=None):

        self.logging = getLogger()
        self.logging.debug('New Collection')

        self.documents = {}

        self.database = database  # database name
        self.db = dbpointer  # database pointer
        self.table = table  # database table name

        self.db = verify_table(self.table, self.database, self.db)
コード例 #5
0
    def __init__(self, database=None, dbpointer=None, table=None ):

        self.logging = getLogger()
        self.logging.debug('New Collection')

        self.documents = {}

        self.database = database    # database name
        self.db = dbpointer         # database pointer
        self.table = table         # database table name

        self.db = verify_table(self.table, self.database, self.db)
コード例 #6
0
def safe_pf_get(pf, field, defaultval=False):
    '''
    Safe method to extract values from parameter file
    with a default value option.
    '''
    logging = getLogger()

    value = defaultval
    if pf.has_key(field):
        try:
            value = pf.get(field, defaultval)
        except Exception, e:
            logging.warning('Problems safe_pf_get(%s,%s)' % (field, e))
            pass
コード例 #7
0
def safe_pf_get(pf, field, defaultval=False):
    """
    Safe method to extract values from parameter file
    with a default value option.
    """
    logging = getLogger()

    value = defaultval
    if pf.has_key(field):
        try:
            value = pf.get(field, defaultval)
        except Exception, e:
            logging.warning("Problems safe_pf_get(%s,%s)" % (field, e))
            pass
コード例 #8
0
    def __init__(
        self,
        database=None,
        dbpointer=None,
        magnitude_type_subset=[".*"],
        event_auth_select=None,
        event_auth_reject=None,
        origin_auth_select=None,
        origin_auth_reject=None,
        arrival_auth_select=None,
        arrival_auth_reject=None,
        netmag_auth_select=None,
        netmag_auth_reject=None,
        mt_auth_select=None,
        mt_auth_reject=None,
        fplane_auth_select=None,
        fplane_auth_reject=None,
        detection_state_select=None,
        detection_state_reject=None,
    ):

        self.logging = getLogger("Event")

        self.database = database  # database name
        self.db = dbpointer  # database pointer

        self.magnitude_type_subset = magnitude_type_subset

        self.event_auth_select = event_auth_select
        self.event_auth_reject = event_auth_reject
        self.origin_auth_select = origin_auth_select
        self.origin_auth_reject = origin_auth_reject
        self.arrival_auth_select = arrival_auth_select
        self.arrival_auth_reject = arrival_auth_reject
        self.detection_state_select = detection_state_select
        self.detection_state_reject = detection_state_reject
        self.netmag_auth_select = netmag_auth_select
        self.netmag_auth_reject = netmag_auth_reject
        self.mt_auth_select = mt_auth_select
        self.mt_auth_reject = mt_auth_reject
        self.fplane_auth_select = fplane_auth_select
        self.fplane_auth_reject = fplane_auth_reject

        self.logging.debug("Init Event Class: db=%s" % self.database)

        self.db = verify_table("event", self.database, self.db)

        self._clean()
コード例 #9
0
def simple_table_present(table, dbpointer):
    '''
    Verify if we have a table before we run the command.

    Similar to verify_table but without rising exceptions
    and without returning any objects back. It will only work
    out a dbpointer and not a database name. The pointer
    should be verified already.
    '''

    logging = getLogger()

    # Test if we have an event table first.
    logging.debug('dbTALBE_PRESENT( %s )' % table)

    try:
        view = dbpointer.lookup(table=table)
    except Exception, e:
        logging.warning('export_events.simple_table_present: %s ' % s)
        return False
コード例 #10
0
def simple_table_present(table, dbpointer):
    """
    Verify if we have a table before we run the command.

    Similar to verify_table but without rising exceptions
    and without returning any objects back. It will only work
    out a dbpointer and not a database name. The pointer
    should be verified already.
    """

    logging = getLogger()

    # Test if we have an event table first.
    logging.debug("dbTALBE_PRESENT( %s )" % table)

    try:
        view = dbpointer.lookup(table=table)
    except Exception, e:
        logging.warning("export_events.simple_table_present: %s " % s)
        return False
コード例 #11
0
def verify_table(table=False, database=False, dbpointer=False):
    '''
    Open a database or database pointer and verify a table

    On multiple objects (classes) we perform the same process
    of verifying the presence of a table before we get to
    interact with it. This will make that process easy since
    you can get to that point either from a database name
    or from a database pointer. The function will return
    the database pointer that you are responsible for
    cleaning later. The local view of the table will be
    freed.
    '''

    logging = getLogger()

    # Get db ready
    if not database and not dbpointer:
        logging.warning(
            'export_events.verify_table: Need database or dbpointer')
        return False

    if not dbpointer:
        logging.debug('dbopen( %s )' % database)
        dbpointer = datascope.dbopen(database, "r")

    if table:
        # Test if we have some table first.
        logging.debug('db.lookup( %s )' % table)
        view = dbpointer.lookup(table=table)

        if not view.query(datascope.dbTABLE_PRESENT):
            logging.warning(
                'export_events.verify_table: Missing [%s] table in database' %
                table)
            return False
        else:
            logging.debug( 'db.query(dbTABLE_PRESENT ) => %s' % \
                    view.query(datascope.dbTABLE_PRESENT))

    return dbpointer
コード例 #12
0
def get_all_fields(dbpointer, nulls={}):
    '''
    At a given database pointer to a particular record query for valid
    table fields and pull all values. Return a dictionary with the values.
    '''

    logging = getLogger()

    results = {}

    if not dbpointer:
        logging.warning('export_events.get_all_fields: Need dbpointer')
        return results

    try:
        if not dbpointer.query(datascope.dbTABLE_PRESENT):
            logging.warning('export_events.get_all_fields: No records')
            return results
    except Exception, e:
        logging.warning('export_events.get_all_fields: Error on dbpointer')
        return results
コード例 #13
0
def get_all_fields(dbpointer, nulls={}):
    """
    At a given database pointer to a particular record query for valid
    table fields and pull all values. Return a dictionary with the values.
    """

    logging = getLogger()

    results = {}

    if not dbpointer:
        logging.warning("export_events.get_all_fields: Need dbpointer")
        return results

    try:
        if not dbpointer.query(datascope.dbTABLE_PRESENT):
            logging.warning("export_events.get_all_fields: No records")
            return results
    except Exception, e:
        logging.warning("export_events.get_all_fields: Error on dbpointer")
        return results
コード例 #14
0
ファイル: event.py プロジェクト: basaks/antelope_contrib
    def __init__(self, database=None, dbpointer=None,
                magnitude_type_subset=['.*'],
                event_auth_select=None, event_auth_reject=None,
                origin_auth_select=None, origin_auth_reject=None,
                arrival_auth_select=None, arrival_auth_reject=None,
                netmag_auth_select=None, netmag_auth_reject=None,
                mt_auth_select=None, mt_auth_reject=None,
                fplane_auth_select=None, fplane_auth_reject=None,
                detection_state_select=None, detection_state_reject=None):

        self.logging = getLogger('Event')


        self.database = database    # database name
        self.db = dbpointer         # database pointer

        self.magnitude_type_subset = magnitude_type_subset

        self.event_auth_select = event_auth_select
        self.event_auth_reject = event_auth_reject
        self.origin_auth_select = origin_auth_select
        self.origin_auth_reject = origin_auth_reject
        self.arrival_auth_select = arrival_auth_select
        self.arrival_auth_reject = arrival_auth_reject
        self.detection_state_select = detection_state_select
        self.detection_state_reject = detection_state_reject
        self.netmag_auth_select = netmag_auth_select
        self.netmag_auth_reject = netmag_auth_reject
        self.mt_auth_select = mt_auth_select
        self.mt_auth_reject = mt_auth_reject
        self.fplane_auth_select = fplane_auth_select
        self.fplane_auth_reject = fplane_auth_reject


        self.logging.debug( 'Init Event Class: db=%s' % self.database )

        self.db = verify_table('event', self.database, self.db)

        self._clean()
コード例 #15
0
def open_verify_pf(pf, mttime=False):
    '''
    Verify that we can get the file and check
    the value of PF_MTTIME if needed.
    Returns pf_object
    '''

    logging = getLogger()

    logging.debug('Look for parameter file: %s' % pf)

    if mttime:
        logging.debug('Verify that %s is newer than %s' % (pf, mttime))

        PF_STATUS = stock.pfrequire(pf, mttime)
        if PF_STATUS == stock.PF_MTIME_NOT_FOUND:
            logging.warning('Problems looking for %s. PF_MTTIME_NOT_FOUND.' %
                            pf)
            logging.error(
                'No MTTIME in PF file. Need a new version of the %s file!!!' %
                pf)
        elif PF_STATUS == stock.PF_MTIME_OLD:
            logging.warning('Problems looking for %s. PF_MTTIME_OLD.' % pf)
            logging.error('Need a new version of the %s file!!!' % pf)
        elif PF_STATUS == stock.PF_SYNTAX_ERROR:
            logging.warning('Problems looking for %s. PF_SYNTAX_ERROR.' % pf)
            logging.error('Need a working version of the %s file!!!' % pf)
        elif PF_STATUS == stock.PF_NOT_FOUND:
            logging.warning('Problems looking for %s. PF_NOT_FOUND.' % pf)
            logging.error('No file  %s found!!!' % pf)

        logging.debug('%s => PF_MTIME_OK' % pf)

    try:
        return stock.pfread(pf)
    except Exception, e:
        logging.error('Problem looking for %s => %s' % (pf, e))
コード例 #16
0
def verify_table(table=False, database=False, dbpointer=False):
    """
    Open a database or database pointer and verify a table

    On multiple objects (classes) we perform the same process
    of verifying the presence of a table before we get to
    interact with it. This will make that process easy since
    you can get to that point either from a database name
    or from a database pointer. The function will return
    the database pointer that you are responsible for
    cleaning later. The local view of the table will be
    freed.
    """

    logging = getLogger()

    # Get db ready
    if not database and not dbpointer:
        logging.warning("export_events.verify_table: Need database or dbpointer")
        return False

    if not dbpointer:
        logging.debug("dbopen( %s )" % database)
        dbpointer = datascope.dbopen(database, "r")

    if table:
        # Test if we have some table first.
        logging.debug("db.lookup( %s )" % table)
        view = dbpointer.lookup(table=table)

        if not view.query(datascope.dbTABLE_PRESENT):
            logging.warning("export_events.verify_table: Missing [%s] table in database" % table)
            return False
        else:
            logging.debug("db.query(dbTABLE_PRESENT ) => %s" % view.query(datascope.dbTABLE_PRESENT))

    return dbpointer