Beispiel #1
0
def read_pf_to_dict(pfname: str,
                    load_extra: bool = True,
                    extra_pf_keyname: str = "extra_pf_names") -> dict:
    """Read a parameter file and optional extra parameter files as a dict.

    Antelope's PF mechanism is a bit redundant compared to Python's native dict handling. This function allows one to read a given parameter file in as a dict directly, and optionally load any extra parameter files as nested key-values inside the main dict.

    The idea behind the load_extra option is to work around Antelope's broken &ref() function. Man pf(5) indicates that one can load an arbitrary value from a foreign parameter file. This apparently only works with scalar values however - foreign values that are of type &Arr and &Tbl result in a segmentation fault as of Antelope 5.9.

    """
    result = stock.pfread(pfname).pf2dict()

    if load_extra:
        if extra_pf_keyname in result:
            for extra_pfname in result[extra_pf_keyname]:
                LOGGER.debug("Attempting to load extra pf %s", extra_pfname)
                result[extra_pfname] = stock.pfread(extra_pfname).pf2dict()
        else:
            LOGGER.debug(
                "extra_pf_keyname %s does not exist in pf %s, not loading extra pf files.",
                extra_pf_keyname,
                pfname,
            )

    return result
Beispiel #2
0
def parse_mail(pffile):
    _modules = {}
    pf = pfread(pffile)
    logging.config.dictConfig(recursive_auto_convert(pf["logging"]))
    try:
        # dotted quads get converted to unix times due to a bug in C is_epoch_str()
        # so turn on auto_convert after we read it
        pf.auto_convert = False
        host = pf["imap"].get("host", "localhost")
        pf.auto_convert = True
        handlers = pf["Handlers"]
        username = pf["imap"]["username"]
        password = pf["imap"]["password"]
        port = pf["imap"].get("port", None)
        mailbox = pf["imap"].get("mailbox", None)
        ssl = pf["imap"].get("ssl", False)
    except KeyError as e:
        raise Exception("Invalid pf file %r" % pffile)
    if not handlers:
        raise Exception("No handlers configured")
    for handler in handlers:
        _modules[handler["handler"]] = import_module("mailparser_" +
                                                     handler["handler"])
    h = ImapHelper(username, password, host, port, mailbox, ssl).login()
    with logouting(h):
        for num, flags, msg in h.getnew():
            for handler in handlers:
                if not search(handler["sender"], msg["From"]):
                    continue
                if not search(handler["subject"], msg["Subject"]):
                    continue
                _modules[handler["handler"]].handle(msg, handler)
                if not handler.get("continue", False):
                    break
Beispiel #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
    '''
    logger = logging.getLogger(__name__)
    logger.debug('Look for parameter file: %s' % pf)

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

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

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

    try:
        return stock.pfread(pf)
    except Exception as ex:
        logger.error('Problem looking for %s => %s' % (pf, ex))
Beispiel #4
0
    def _read_pf(self, pf):

        self.logging.info('Read values from pf file %s' % pf)

        temp = stock.pfread( pf )

        dataloggers = temp.get('dataloggers')

        if not dataloggers:
            self.logging.warning( 'Nothing in the dataloggers parameter for %s' % pf )
        else:
            #self.logging.debug( dataloggers )
            pass


        for line in dataloggers:

            parts = line.split()
            new_serial = parts[3]

            if  new_serial in self.serials and self.serials[ new_serial ]['dlname'].strip() == parts[0].strip():
                self.logging.debug( 'Same value for %s: %s => %s' % \
                        ( new_serial, self.serials[ new_serial ]['dlname'], parts[0]) )
            elif  new_serial in self.serials:
                self.logging.info( 'Updating value for %s: %s => %s' % \
                        ( new_serial, self.serials[ new_serial ]['dlname'], parts[0]) )
            else:
                self.logging.info( 'New serial %s: %s ' % ( parts[0], new_serial ) )

            self.serials[ new_serial ] = {
                        'dlname': parts[0],
                        'sta': parts[2],
                        'snet': parts[1]
                    }
Beispiel #5
0
    def _init_pf(self):
        """Load values from the parameter file."""

        self.logger.info("Read parameters from pf file %s" % self.options.pfname)
        self.pf = stock.pfread(self.options.pfname)
        # Get MongoDb parameters from PF file

        MONGO_PF_KEYS = ["user", "host", "password", "collection", "namespace"]
        ORB_PF_KEYS = [
            "orbserver",
            "orb_select",
            "orb_reject",
            "default_orb_read",
            "reap_wait",
            "reap_timeout",
            "timeout_exit",
            "parse_opt",
            "indexing",
        ]

        SENSITIVE_FIELD_NAMES = ["password"]

        for k in ("mongo_" + x for x in MONGO_PF_KEYS):
            v = self.pf.get(k)
            sens = ("mongo_" + x for x in SENSITIVE_FIELD_NAMES)
            if k in sens and v is not None:
                v = "**REDACTED**"
            self.logger.debug("%s => [%s]" % (k, v))

        for k in ORB_PF_KEYS:
            v = self.pf.get(k)
            self.logger.debug("%s => [%s]" % (k, v))
Beispiel #6
0
def _parse_pf(params):
    """Parse parameter file, return results.

    Arguments:
    params - All parameters <dict>
    params['pf'] - Parameter file <str>
    params['email'] - Email(s) <str>

    Side Effects:
    Converts params['email'] from <str> to <list>

    Return Values:
    <dict> of parameters

    """
    import sys
    import os

    sys.path.append("%s/data/python" % os.environ["ANTELOPE"])
    from antelope.stock import pfread

    sys.path.remove("%s/data/python" % os.environ["ANTELOPE"])
    pf = pfread(params.pop("pf"))
    # pf = pfread('/home/mcwhite/src/anfsrc/anf/bin/utility/auto_qc/qc_report')
    for k in pf.keys():
        params[k] = pf[k]
    params["email"] = params["email"].split(",")
    return _eval_recursive(params)
Beispiel #7
0
def get_pf(pfname):
    pf = stock.pfread(pfname)
    tstep = float(pf.get('tstep'))
    tpad = float(pf.get('tpad'))
    filter = pf.get('filter')
    stachans = pf.get('stachan')
    animation_params = pf.get('animation_params')
    gmt_params = pf.get('gmt_params')
    sta = []
    chan = []
    for i in range(0, len(stachans)):
	if len(stachans[i]) != 0:
	    k = 0
	    tempsta = ''
	    tempchan = ''
	    for j in range(0, len(stachans[i])):
		if (stachans[i][j] == ' ' or stachans[i][j] == ':'):
		    sta.append(tempsta)
		    break
		else:
		    tempsta = tempsta + stachans[i][j]

	    for j in range(0, len(stachans[i])):
		if (stachans[i][j] == ':'):
		    tempchan = ''
		else:
		    tempchan = tempchan + stachans[i][j]
	    chan.append(tempchan)

    return (tstep, tpad, filter, sta, chan, animation_params, gmt_params)
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
    '''
    logger = logging.getLogger(__name__)
    logger.debug('Look for parameter file: %s' % pf)

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

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

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

    try:
        return stock.pfread(pf)
    except Exception as ex:
        logger.error('Problem looking for %s => %s' % (pf, ex))
Beispiel #9
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))
Beispiel #10
0
def _parse_pf(params):
    """Parse parameter file, return results.

    Arguments:
    params - All parameters <dict>
    params['pf'] - Parameter file <str>
    params['email'] - Email(s) <str>

    Side Effects:
    Converts params['email'] from <str> to <list>

    Return Values:
    <dict> of parameters

    """
    import sys
    import os
    sys.path.append('%s/data/python' % os.environ['ANTELOPE'])
    from antelope.stock import pfread
    sys.path.remove('%s/data/python' % os.environ['ANTELOPE'])
    pf = pfread(params.pop('pf'))
    #pf = pfread('/home/mcwhite/src/anfsrc/anf/bin/utility/auto_qc/qc_report')
    for k in pf.keys():
        params[k] = pf[k]
    params['email'] = params['email'].split(',')
    return _eval_recursive(params)
Beispiel #11
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:
        antelope.stock.ParameterFile
    """

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

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

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

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

    try:
        return stock.pfread(pf)
    except Exception as e:
        logger.error("Problem looking for %s => %s" % (pf, e))
Beispiel #12
0
def get_pf(pfname):
    """Return a dict from a pf file"""
    if hasattr(stock, 'pfread'):
        return stock.pfread(pfname).pf2dict()
    elif hasattr(stock, 'pfget'):
        return stock.pfget(pfname)
    else:
        raise AttributeError("No pf function available")
Beispiel #13
0
def pfile_2_cfg(pfile, config_file):
    '''
    Convert an Antelope .pf parameter file to a generic Python .cfg
    configuration file.

    Arguments:
    pfile - Path to parameter file or None. If pfile is None, the $PFPATH is searched
    for a parameter file named 3Dreloc.pf.
    config_file - Desired path to output configuration file.

    Returns:
    0 - Success

    Behaviour:
    This method will read in a parameter file, convert all parameters
    to .cfg configuration file format equivalent and write out a .cfg
    file.

    Example:
    In [1]: from loctools3D.ant import pfile_2_cfg

    In [2]: pfile_2_cfg(None, 'test_pfile_2_cfg')
    Out[2]: 0

    In [3]: pfile_2_cfg('/Users/mcwhite/src/3DSeisTools/location/pyloceq',
                     'test_pfile_2_cfg')
    Out[3]: 0
    '''
    import ConfigParser
    from antelope.stock import pfin,\
                               pfread
    config_file = '%s.cfg' % config_file
    if os.path.isfile(config_file):
        try:
            os.remove(config_file)
        except OSError:
            print 'Could not remove potentially stale configuration file - %s.'\
                    '\nPlease remove and try again.' % config_file
            sys.exit(-1)
    config = ConfigParser.RawConfigParser()
    config.add_section('misc')
    if pfile:
        if os.path.splitext(pfile)[1] != '.pf':
            pfile = '%s.pf' %pfile 
        pfile = pfin(pfile)
    else:
        pfile = pfread('3Drelocate')
    for key1 in pfile.keys():
        if isinstance(pfile[key1], dict):
            config.add_section(key1)
            for key2 in pfile[key1]:
                config.set(key1, key2, pfile[key1][key2])
        else:
            config.set('misc', key1, pfile[key1])
    config_file =  open(config_file, 'w')
    config.write(config_file)
    config_file.close()
    return 0
Beispiel #14
0
    def _parse_pf(self, pfname):
        """Parse parameter file."""

        pf_file = stock.pffiles(pfname)[-1]

        if not os.path.isfile(pf_file):
            self.logger.critical("Cannot find parameter file [%s]" % pfname)
            return -1

        pf = stock.pfread(pfname)
        self.pf = pf

        # matlab inversion parameters
        self.loaddatafile = float(safe_pf_get(pf, "loaddatafile"))
        self.domeas = float(safe_pf_get(pf, "domeasurement"))
        self.doinversion = float(safe_pf_get(pf, "doinversion"))
        self.dojackknife = float(safe_pf_get(pf, "dojackknife"))
        self.azband = float(safe_pf_get(pf, "azband"))
        self.dobootstrap = float(safe_pf_get(pf, "dobootstrap"))
        self.nb = float(safe_pf_get(pf, "nb"))
        self.bconf = float(safe_pf_get(pf, "bconf"))
        self.niter = float(safe_pf_get(pf, "niter"))
        self.testfault = float(safe_pf_get(pf, "testfault"))

        # folder and path params
        self.image_dir = os.path.relpath(
            safe_pf_get(pf, "image_dir", "second_moment_images"))
        self.temp_dir = os.path.relpath(
            safe_pf_get(pf, "temp_dir", ".second_moment"))
        self.model_path = safe_pf_get(pf, "model_path")
        if not self.options.model:
            self.options.model = safe_pf_get(pf, "velocity_model")

        # on/off for features
        self.auto_arrival = safe_pf_get(pf, "auto_arrival")

        # egf selection criteria
        self.loc_margin = float(safe_pf_get(pf, "location_margin"))
        self.dep_margin = float(safe_pf_get(pf, "depth_margin"))
        self.time_margin = float(safe_pf_get(pf, "time_margin"))

        # filter and time window
        if not self.options.filter:
            self.options.filter = safe_pf_get(pf, "filter")

        if not self.options.tw:
            self.options.tw = safe_pf_get(pf, "time_window")

        # L-curve time duration maximum
        self.stf_duration_criteria = float(safe_pf_get(pf, "misfit_criteria"))

        self.matlab_code_path = safe_pf_get(pf, "matlab_code_path")
        self.matlab_path = safe_pf_get(pf, "matlab_path")
        self.matlab_flags = safe_pf_get(pf, "matlab_flags")
        self.xvfb_path = safe_pf_get(pf, "xvfb_path")

        # Get model information
        self.model = get_model_pf(self.options.model, self.model_path)
Beispiel #15
0
def parse_pf(pfname):
    """Parse parameter file

    """
    parsed_pf = {}

    try:
        pf = stock.pfread(pfname)
    except Exception,e:
        sys.exit('Cannot read %s => %s' % (pfname,e))
Beispiel #16
0
def parse_pf(pfname, pf_keys=PF_REQUIRED_KEYS):
    """Parse parameter file, looking for explicit keys"""

    parsed_pf = {}

    pf = stock.pfread(pfname)

    for key in pf_keys:
        parsed_pf[key] = pf.get(key)

    return parsed_pf
Beispiel #17
0
    def __init__(self, opt=False):

        self.logging = getLogger('Dlmon')

        self.logging.info( 'New Dlmon object' )

        self._clean()

        #self.export_format = export_format

        self.parse_opt = opt

        self.rules = stock.pfread('dlmon_rules.pf')
Beispiel #18
0
    def __init__(self, opt=False):
        """Initialize a new Dlmon object.

        Sets up logging, and reads parameters for classifying data.
        """

        self.logger = getLogger(fullname(self))

        self.logger.info("New Dlmon object")

        self._clean()

        # self.export_format = export_format

        self.parse_opt = opt

        self.rules = stock.pfread("dlmon_rules.pf")
Beispiel #19
0
    def _read_pf(self, pf):

        self.logging.info("Read values from pf file %s" % pf)

        temp = stock.pfread(pf)

        dataloggers = temp.get("dataloggers")

        if not dataloggers:
            self.logging.warning("Nothing in the dataloggers parameter for %s" % pf)
        else:
            # self.logging.debug( dataloggers )
            pass

        for line in dataloggers:

            parts = line.split()
            new_serial = parts[3]

            if (
                new_serial in self.serials
                and self.serials[new_serial]["dlname"].strip() == parts[0].strip()
            ):
                self.logging.debug(
                    "Same value for %s: %s => %s"
                    % (new_serial, self.serials[new_serial]["dlname"], parts[0])
                )
            elif new_serial in self.serials:
                self.logging.info(
                    "Updating value for %s: %s => %s"
                    % (new_serial, self.serials[new_serial]["dlname"], parts[0])
                )
            else:
                self.logging.info("New serial %s: %s " % (parts[0], new_serial))

            self.serials[new_serial] = {
                "dlname": parts[0],
                "sta": parts[2],
                "snet": parts[1],
            }
Beispiel #20
0
    def _init_load_pf(self):
        """Get data from parameter file.

        Return:
            True if successful, False otherwise

        """

        self.logger.info("Read parameters from pf file %s" % self.options.pf)
        self.pf = stock.pfread(self.options.pf)

        # Get MongoDb parameters from PF file
        self.mongo_user = self.pf.get("mongo_user")
        self.mongo_host = self.pf.get("mongo_host")
        self.mongo_password = self.pf.get("mongo_password")
        self.mongo_namespace = self.pf.get("mongo_namespace")

        # Verify we have a valid "refresh" value in PF file
        try:
            refresh = int(self.pf["refresh"])
            if not refresh:
                raise KeyError
        except KeyError:
            refresh = 60

        self.refresh = refresh

        self.logger.info("refresh every [%s]secs" % self.refresh)

        # Get list from PF file
        self.module_params = self.pf.get("modules")
        if not isinstance(self.module_params, collections.Mapping):
            raise ValueError("Parameter File modules must be an Arr")

        self.logger.notify("Modules to load: " +
                           ", ".join(self.module_params.keys()))

        return True
Beispiel #21
0
    def __init__(self, argv=None):
        """Initialize object, read config."""
        # Read configuration from command-line
        usage = "Usage: %prog [options]"

        parser = OptionParser(usage=usage)
        parser.add_option(
            "-s",
            action="store",
            dest="state",
            help="track orb id on this state file",
            default=False,
        )
        parser.add_option(
            "-c",
            action="store_true",
            dest="clean",
            help="clean 'drop' collection on start",
            default=False,
        )
        parser.add_option(
            "-v",
            action="store_true",
            dest="verbose",
            help="verbose output",
            default=False,
        )
        parser.add_option("-d",
                          action="store_true",
                          dest="debug",
                          help="debug output",
                          default=False)
        parser.add_option(
            "-p",
            "--pf",
            action="store",
            dest="pf",
            type="string",
            help="parameter file path",
            default="poc2mongo",
        )

        (self.options, self.args) = parser.parse_args()

        self.options.loglevel = "WARNING"
        if self.options.debug:
            self.options.loglevel = "DEBUG"
        elif self.options.verbose:
            self.options.loglevel = "INFO"

        self.logger = getLogger(fullname(__name__))

        # Get PF file values
        self.logger.info("Read parameters from pf file %s" % self.options.pf)
        self.pf = stock.pfread(self.options.pf)

        # Get MongoDb parameters from PF file
        self.options.mongo = MongoDbConfig(
            user=self.pf.get("mongo_user"),
            host_and_port=self.pf.get("mongo_host"),
            password=self.pf.get("mongo_password"),
            namespace=self.pf.get("mongo_namespace"),
            collection=self.pf.get("mongo_collection"),
        )

        self.options.orbserver = self.pf.get("orbserver")
        self.options.orb_select = self.pf.get("orb_select")
        self.options.orb_reject = self.pf.get("orb_reject")
        self.options.default_orb_read = self.pf.get("default_orb_read")
        self.options.include_pocc2 = self.pf.get("include_pocc2")
        self.options.reap_wait = self.pf.get("reap_wait")
        self.options.reap_timeout = self.pf.get("reap_timeout")
        self.options.timeout_exit = self.pf.get("timeout_exit")
Beispiel #22
0
    def __init__(self):
        self.event = 'false'
        self.pfname = 'dbwfserver'
        self.style = 'cupertino'
        self.nickname = ''
        self.application_title = ''
        self.static_dir = ''
        self.jquery_dir = ''
        self.template = ''
        self.plot_template = ''
        self.local_data = ''
        self.antelope = ''
        self.dbname = ''
        self.proxy_url = ''
        self.port = -1
        self.max_traces = -1
        self.max_points = -1
        self.realtime = 'false'
        self.apply_calib = False
        self.display_tracebacks = False
        self.display_arrivals = True
        self.display_points = False
        self.verbose = False
        self.debug = False
        self.daemonize = False
        self.default_time_window = -1
        self.filters = []
        self.run_server = {}

        try:
            opts, pargs = getopt.getopt(sys.argv[1:], 'dp:P:vVern:')
        except getopt.GetoptError:
            self.usage()
            sys.exit(-1)

        if (len(pargs) == 1):

            self.dbname = pargs[0]

        for option, value in opts:

            if '-e' in option:
                self.event = 'true'

            if '-p' in option:
                self.pfname = str(value)

            if '-r' in option:
                self.realtime = 'true'

            if '-d' in option:
                self.daemonize = True

            if '-V' in option:
                self.debug = True
                self.verbose = True

            if '-v' in option:
                self.verbose = True

            if '-P' in option:
                self.port = int(value)

            if '-n' in option:
                self.nickname = str(value)

        #
        # Get values from pf file
        #
        pf = stock.pfread(self.pfname)

        if self.port == -1:
            self.port = pf.get("port")

        try:
            self.max_points = pf.get("max_points")
        except:
            pass
        try:
            self.max_traces = pf.get("max_traces")
        except:
            pass
        try:
            self.jquery_dir = pf.get("jquery_dir")
        except:
            pass
        try:
            self.static_dir = pf.get("static_dir")
        except:
            pass
        try:
            self.template = pf.get("template")
        except:
            pass
        try:
            self.plot_template = pf.get("plot_template")
        except:
            pass
        try:
            self.local_data = pf.get("local_data")
        except:
            pass
        try:
            self.style = pf.get("jquery_ui_style")
        except:
            pass
        try:
            self.antelope = pf.get("antelope")
        except:
            pass
        try:
            self.application_title = pf.get("application_title")
        except:
            pass
        try:
            self.proxy_url = pf.get("proxy_url")
        except:
            pass
        try:
            self.apply_calib = pf.get("apply_calib")
        except:
            pass
        try:
            self.display_tracebacks = pf.get("display_tracebacks")
        except:
            pass
        try:
            self.display_arrivals = pf.get("display_arrivals")
        except:
            pass
        try:
            self.display_points = pf.get("display_points")
        except:
            pass
        try:
            self.default_time_window = pf.get("default_time_window")
        except:
            pass
        try:
            self.filters = list(pf.get("filters"))
        except:
            pass
Beispiel #23
0
    def __init__(self):
        """Initialize the DbwfserverConfig object."""
        self.event = "false"
        self.pfname = "dbwfserver"
        self.nickname = ""
        self.application_title = ""
        self.dbname = ""
        self.port = None
        self.realtime = "false"
        self.verbose = False
        self.debug = False
        self.daemonize = False
        self.run_server = {}

        try:
            opts, pargs = getopt.getopt(sys.argv[1:], "dp:P:vVern:")
        except getopt.GetoptError:
            usage()
            sys.exit(-1)

        if len(pargs) == 1:

            self.dbname = pargs[0]

        for option, value in opts:

            if "-e" in option:
                self.event = "true"

            if "-p" in option:
                self.pfname = str(value)

            if "-r" in option:
                self.realtime = "true"

            if "-d" in option:
                self.daemonize = True

            if "-V" in option:
                self.debug = True
                self.verbose = True

            if "-v" in option:
                self.verbose = True

            if "-P" in option:
                self.port = int(value)

            if "-n" in option:
                self.nickname = str(value)

        #
        # Get values from pf file
        #
        pf = stock.pfread(self.pfname)

        if self.port is None:
            self.port = pf.get("port", 80)

        self.max_points = pf.get("max_points", -1)
        self.max_traces = pf.get("max_traces", -1)
        self.jquery_dir = pf.get("jquery_dir", "")
        self.static_dir = pf.get("static_dir", "")
        self.template = pf.get("template", "")
        self.plot_template = pf.get("plot_template", "")
        self.local_data = pf.get("local_data", "")
        self.style = pf.get("jquery_ui_style", "cupertino")
        self.antelope = pf.get("antelope", "")
        self.application_title = pf.get("application_title")
        self.proxy_url = pf.get("proxy_url", "")
        self.apply_calib = pf.get("apply_calib", False)
        self.display_tracebacks = pf.get("display_tracebacks", False)
        self.display_arrivals = pf.get("display_arrivals", True)
        self.display_points = pf.get("display_points", False)
        self.default_time_window = pf.get("default_time_window", -1)
        self.filters = list(pf.get("filters", []))
Beispiel #24
0
    def __init__(self):
        self.event               = 'false'
        self.pfname              = 'dbwfserver'
        self.style               = 'cupertino'
        self.nickname            = ''
        self.application_title   = ''
        self.static_dir          = ''
        self.jquery_dir          = ''
        self.template            = ''
        self.plot_template       = ''
        self.local_data          = ''
        self.antelope            = ''
        self.dbname              = ''
        self.proxy_url           = ''
        self.port                = -1
        self.max_traces          = -1
        self.max_points          = -1
        self.realtime            = 'false'
        self.apply_calib         = False
        self.display_tracebacks  = False
        self.display_arrivals    = True
        self.display_points      = False
        self.verbose             = False
        self.debug               = False
        self.daemonize           = False
        self.default_time_window = -1
        self.filters             = []
        self.run_server          = {}

        try:
            opts, pargs = getopt.getopt(sys.argv[1:], 'dp:P:vVern:')
        except getopt.GetoptError:
            self.usage()
            sys.exit(-1)

        if( len(pargs) == 1):

            self.dbname = pargs[0]

        for option, value in opts:

            if '-e' in option:
                self.event = 'true'

            if '-p' in option:
                self.pfname = str(value)

            if '-r' in option:
                self.realtime = 'true'

            if '-d' in option:
                self.daemonize = True

            if '-V' in option:
                self.debug = True
                self.verbose = True

            if '-v' in option:
                self.verbose = True

            if '-P' in option:
                self.port = int(value)

            if '-n' in option:
                self.nickname = str(value)

        #
        # Get values from pf file
        #
        pf = stock.pfread( self.pfname )

        if self.port == -1:
            self.port = pf.get( "port" )

        try:
            self.max_points = pf.get( "max_points" )
        except:
            pass
        try:
            self.max_traces = pf.get( "max_traces" )
        except:
            pass
        try:
            self.jquery_dir = pf.get( "jquery_dir" )
        except:
            pass
        try:
            self.static_dir = pf.get( "static_dir" )
        except:
            pass
        try:
            self.template = pf.get( "template" )
        except:
            pass
        try:
            self.plot_template = pf.get( "plot_template" )
        except:
            pass
        try:
            self.local_data = pf.get( "local_data" )
        except:
            pass
        try:
            self.style = pf.get( "jquery_ui_style" )
        except:
            pass
        try:
            self.antelope = pf.get( "antelope" )
        except:
            pass
        try:
            self.application_title = pf.get( "application_title" )
        except:
            pass
        try:
            self.proxy_url = pf.get( "proxy_url" )
        except:
            pass
        try:
            self.apply_calib = pf.get( "apply_calib" )
        except:
            pass
        try:
            self.display_tracebacks = pf.get( "display_tracebacks" )
        except:
            pass
        try:
            self.display_arrivals = pf.get( "display_arrivals" )
        except:
            pass
        try:
            self.display_points = pf.get( "display_points" )
        except:
            pass
        try:
            self.default_time_window = pf.get( "default_time_window" )
        except:
            pass
        try:
            self.filters = list(pf.get( "filters" ) )
        except:
            pass
Beispiel #25
0
def main(argv=None):
    """Run the rotation_comparison command."""
    # Configure parameters from command-line.

    usage = "%prog [options] database time/orid"

    parser = OptionParser(usage=usage)

    # Verbose output
    parser.add_option(
        "-v", action="store_true", dest="verbose", default=False, help="verbose output"
    )

    # Parameter file
    parser.add_option(
        "-p",
        action="store",
        dest="pf",
        type="string",
        default="rotation_comparison.pf",
        help="parameter file",
    )

    # Filter
    parser.add_option(
        "-f", action="store", dest="filter", type="string", default=None, help="filter"
    )

    # Time window
    parser.add_option(
        "-t", action="store", dest="tw", type="float", default=None, help="time window"
    )

    # Mode
    parser.add_option(
        "-o", action="store_true", dest="origin", default=False, help="arg2 is orid"
    )

    # Mode
    parser.add_option(
        "-r",
        action="store",
        dest="reference",
        type="string",
        default=None,
        help="reference regex",
    )

    # Stations
    parser.add_option(
        "-c",
        action="store",
        dest="compare",
        type="string",
        default=False,
        help="comparison regex",
    )

    # Plot each data group for a site and wait.
    parser.add_option(
        "-x",
        action="store_true",
        dest="debug_plot",
        default=False,
        help="debug output each station plot",
    )

    # Plot results
    parser.add_option(
        "--noplot",
        action="store_true",
        dest="noplot",
        default=False,
        help="plot azimuth rotation results",
    )

    parser.add_option(
        "--nosave",
        action="store_true",
        dest="nosave",
        default=False,
        help="save results to csv file",
    )

    (options, args) = parser.parse_args(argv[1:])

    # If we don't have 2 arguments then exit.
    if len(args) != 2:
        parser.error("Incorrect number of arguments.")

    # If we don't have station list or reference station than exit

    # Set log level
    loglevel = "WARNING"
    if options.verbose:
        loglevel = "INFO"

    # New logger object and set loglevel
    logger = getAppLogger(__name__, loglevel)
    logger.info("loglevel=%s" % loglevel)

    # parse arguments from command-line
    databasename = args[0]
    logger.info("Database [%s]" % databasename)

    # read parameters from parameter file
    logger.info("Parameter file to use [%s]" % options.pf)

    stock.pfread(options.pf)

    rot_compare = Comparison(options, databasename)
    rot_compare.comp(args[1])
    return 0