Exemple #1
0
    def emit(self, record):
        """
        Emit a record.

        The record is handed off to the various elog routines based on
        the record's priority.

        Although the underlying C library in Antelope has more severity levels,
        only debug, notify, alert, and complain work without terminating the
        python script. This breaks the normal behavior of the python logging
        module.

        Thus, logging.DEBUG maps to elog.debug, logging.INFO maps to
        elog.notify, logging.WARNING maps to elog_alert() via ctypes,
        and everything else (ERROR, CRITICAL, NOLEVELSET) maps to elog.complain
        """

        msg = self.format(record)

        if record.levelno == logging.DEBUG:
            elog.debug(msg)
        elif record.levelno == logging.INFO:
            elog.notify(msg)
        elif record.levelno == logging.WARNING:
            self._elog_alert(msg)
        else: # logging.ERROR, logging.CRITICAL
            elog.complain(msg)
Exemple #2
0
    def emit(self, record):
        """Emit a log record.

        The record is handed off to the various elog routines based on
        the record's priority.

        Although the underlying C library in Antelope has more severity levels,
        only debug, notify, alert, and complain work without terminating the
        python script. This breaks the normal behavior of the python logging
        module.

        Thus, in order to keep the program from exiting unexpectedly, we don't
        map to elog.die().

        The default Python `logging levels
        <https://docs.python.org/3/library/logging.html#levels>`
        default Python levels map to the following numeric levels
            ============  =============  ==============
            Python Level  Numeric Value  Antelope Level
            ============  =============  ==============
            CRITICAL      50             complain
            ERROR         40             complain
            WARNING       30             alert
            NOTIFY [1]_   25             notify
            INFO          20             notify
            DEBUG         10             debug
            NOTSET        0              complain


        [1] Defined in anf.logutil. Can be added by running addNotifyLevel()
            Note that if custom `logging` levels are set that fall between two
            default levels, the level is effectively "rounded down" to the
            closest default `logging` level. So for example, the
            `anf.logutil.logging.NOTIFY` level is defined at a numeric value of
            25. This would map to the `elog.NOTIFY` level, along with the
            `logging.INFO` level.


        """
        msg = self.format(record)

        # logging module levels are numeric, with NOTSET being the lowest.
        if record.levelno == logging.NOTSET:
            elog.complain(msg)
        if record.levelno < logging.INFO:
            elog.debug(msg)
        elif record.levelno < logging.WARNING:
            elog.notify(msg)
        elif record.levelno < logging.ERROR:
            self._elog_alert(msg.encode())
        else:  # logging.ERROR, logging.CRITICAL, everything else.
            elog.complain(msg)
def gmt_fix_land_below_sealevel(regionname, description, region, center,
        outfile, wet_rgb):
    """run psclip to fix coloring of dry areas that are below sea-level"""

    # like original calls, assume data files are all in "data/"
    landfile="data/land_only.cpt"
    grdfile="data/" + regionname + ".grd"
    gradientfile="data/" + regionname + ".grad"
    xyfile="data/" + regionname + ".xy"

   # Define a clip region
    try:
        retcode = check_call("psclip %s -R%s -JE%s -V -K -O >> %s" % (xyfile,
                    region, center, outfile), shell=True)
    except OSError, e:
        elog.complain (description + " psclip execution failed")
        raise
    Returns path if valid and we see data.
    """

    try:
        import antelope.elog as elog
        import antelope.stock as stock
        import antelope.datascope as datascope
    except Exception,e:
        raise sta2jsonException( 'Problems loading Antelope libs: %s' % e )

    path = False

    try:
        with datascope.closing(datascope.dbopen( dbname , 'r' )) as db:
            db = db.lookup( table=tbl )

            if not db.query(datascope.dbTABLE_PRESENT):
                if verbose: elog.complain( 'No dbTABLE_PRESENT on %s' % dbname )
                return False

            if not db.record_count:
                if verbose: elog.complain( 'No %s.record_count' % dbname )
                return False

            path = db.query('dbTABLE_FILENAME')
    except Exception,e:
        elog.complain("Prolembs with db[%s]: %s" % (dbname,e) )
        return False

    return path
   # Define a clip region
    try:
        retcode = check_call("psclip %s -R%s -JE%s -V -K -O >> %s" % (xyfile,
                    region, center, outfile), shell=True)
    except OSError, e:
        elog.complain (description + " psclip execution failed")
        raise

    # Make area 'land-only' and put into the clipping region
    try:
        retcode = check_call("grdimage %s -V -R%s -JE%s -C%s -I%s -O -K >> %s"
                % (grdfile, region, center, landfile, gradientfile, outfile),
                shell=True)
    except OSError, e:
        elog.complain (description + " grdimage execution failed")
        raise

    # Color the actual water areas blue
    try:
        retcode = check_call("pscoast -V -R%s -JE%s -C%s -Df -O -K >> %s" % (
                    region, center, wet_rgb, outfile), shell=True)
    except OSError, e:
        elog.complain (description + " pscoast execution failed")
        raise

    # Close psclip
    try:
        retcode = check_call("psclip -C -K -O >> %s" % outfile, shell=True)
    except OSError, e:
        elog.complain (description + " psclip execution failed")
    try:
        import antelope.elog as elog
        import antelope.stock as stock
        import antelope.datascope as datascope
    except Exception, e:
        raise sta2jsonException('Problems loading Antelope libs: %s' % e)

    path = False

    try:
        with datascope.closing(datascope.dbopen(dbname, 'r')) as db:
            db = db.lookup(table=tbl)

            if not db.query(datascope.dbTABLE_PRESENT):
                if verbose: elog.complain('No dbTABLE_PRESENT on %s' % dbname)
                return False

            if not db.record_count:
                if verbose: elog.complain('No %s.record_count' % dbname)
                return False

            path = db.query('dbTABLE_FILENAME')
    except Exception, e:
        elog.complain("Prolembs with db[%s]: %s" % (dbname, e))
        return False

    return path


def get_md5(test_file, debug=False):