def start(self):
        try:
            use_message = """usage: %prog [options]"""
            option_list = []
            option_list.append(optparse.make_option("-c", "--config-file", dest="config_file", action="store", help="config file for the process manager"))
            option_list.append(optparse.make_option("-p", "--process-file", dest="process_file", action="store", help="list of processes to manage"))
            option_list.append(optparse.make_option("-s", "--state-database", dest="state_database", action="store", help="process state configurations"))
            parser = optparse.OptionParser(option_list=option_list, usage=use_message)
            options, args = parser.parse_args()

            config_file = "processes.config"
            process_file = "processes.list"
            state_db = ".processes.sqlite"
            if os.environ.has_key("HOME"):
                state_db = "%s/%s" % (os.environ["HOME"], state_db)

            if options.config_file:
                config_file = options.config_file
            if options.process_file:
                process_file = options.process_file
            if options.state_database:
                state_db = options.state_database

            print "Config file: %s" % config_file
            print "Process file: %s" % config_file
            print "State database: %s" % state_db

            config = Config.parse(config_file)
            processes = Config.parse(process_file)

            log_path = ''
            try: # Check for log directory
                log_path = os.path.abspath(config['log-path'])
                #self._log("log directory is '%s'" % log_path)
            except Exception, e:
                self._log("Config [log]:> %s" % (str(e),))

            if not os.path.exists(log_path):
                log_path = '.'

            self.t('log').logger.set_log_path(log_path)

            #self._log("Config file is '%s'" % (config_file,))
            #self._log("Config contents: %s" % (str(config),))

            try: # Check for screen logging
                if config['log-to-screen'].lower() == 'true':
                    self.t('log').logger.set_log_to_screen(True)
                    str_screen_logging = "Enabled"
                else:
                    self.t('log').logger.set_log_to_screen(False)
                    str_screen_logging = "Disabled"
            except Exception, e:
                self._log("Config [log-to-screen]:> %s" % (str(e),))
示例#2
0
    def start(self):
        xmax_switches = {
        #   name           flag     arg?
            'config'        : ('-g',    True),
            'description'   : ('-i',    True),
            'earthquake'    : ('-k',    True),
            'picks'         : ('-p',    True),
            'quality'       : ('-q',    True),

            'display'       : ('-f',    True),
            'format'        : ('-F',    True),
            'unit'          : ('-u',    True),
            'order'         : ('-o',    True),

            'data'          : ('-d',    True),
            'block'         : ('-L',    True),
            'merge'         : ('-m',    False),
            'temp'          : ('-t',    False),
            'dump'          : ('-T',    False),

            'network'       : ('-n',    True),
            'station'       : ('-s',    True),
            'location'      : ('-l',    True),
            'channel'       : ('-c',    True),
        }

        xmax_options = {
        #   name          value (or False to exclude this option by default)
            'config'        : False,
            'description'   : False,
            'earthquake'    : False,
            'picks'         : False,
            'quality'       : False,

            'display'       : '1',
            'format'        : False,
            'order'         : False,
            'unit'          : '1',

            'data'          : False,
            'block'         : False,
            'merge'         : False,
            'temp'          : False,
            'dump'          : False,

            'network'       : False,
            'station'       : False,
            'location'      : False,
            'channel'       : False,

            'begin'         : False,
            'end'           : False,
        }

        options, args = self.parser.parse_args()

        config_file = os.path.abspath(os.environ['HOME'] + "/.xmax.config")
        if not os.path.isfile(config_file):
            config_file = ""

        if options.config_file:
            config_file = options.config_file

        if config_file != "" and not os.path.isfile(config_file):
            print "xmax launch script config file '%s' not found"
            sys.exit(1)

        config = {}
        if config_file != "":
            try:
                config = Config.parse(config_file)
            except Config.ConfigException, ex:
                print "error parsing config file:", str(ex)
                sys.exit(1)