Пример #1
0
def getLogs(day, pattern):
    tmpDir = util.tmpdir()
    tmpFilepath = tmpDir + "/temp.temp"
    data = []
    #parse the config file to get the exec servers
    cfg = config.load_trade_config(os.environ['CONFIG_DIR'] + '/exec.conf')
    for host, port in cfg["servers"]:
        src = SFTPSource(host, "ase", None)
        try:
            if day <= "20110802":
                #get the exec number
                m = re.match(r"exectrade(\d).jc", host)
                if m is None:
                    raise Exception(
                        "Failed to parse host name to get its number for historical data. host={}"
                        .format(host))
                else:
                    number = m.group(1)
                remoteDir = os.path.join(
                    "/spare/local/guillotine_old.20110802", "log",
                    "rts1_{}.{}".format(number, day))
            else:
                remoteDir = os.path.join(os.environ["EXEC_ROOT_DIR"], "log",
                                         day)
            src.cwd(remoteDir)
            files = src.list(pattern)
            if len(files) != 1:
                raise Exception("Found {} {} files in {}:{}".format(
                    len(files), pattern, host, remoteDir))
            src.copy(remoteDir + "/" + files[0][0], tmpFilepath)
            with open(tmpFilepath, "r") as file:
                for line in file:
                    data.append(line.strip())
        except Exception, e:
            util.warning(str(e))
Пример #2
0
def main (win):
    parser = OptionParser()
    parser.add_option("-d", "--debug", default=False, action="store_true", dest="debug")
    parser.add_option('-n', '--name', dest='name', help='name of this client to give to server')
    (opt, args) = parser.parse_args()

    if opt.debug:
        util.set_debug()
    else:
        util.set_log_file()

    util.info('launching guillotine commander')
    cfg_file = os.environ['CONFIG_DIR'] + '/exec.conf'
    util.info("loading config file: %s" % cfg_file)
    trade_cfg = config.load_trade_config(cfg_file)

    gtc = guillotine.multiplex_channel()
    name = "gt-watch from "+(gethostname().split('.',1))[0] if opt.name is None else "gt_watch_" + os.environ['STRAT']
    gtc.connect(trade_cfg['servers'], trade_cfg['account'], trade_cfg['password'], name=name)
    
    w = watcher(win, gtc)
    gtc.register(w)
    asyncore.loop(0.2, use_poll=True)
Пример #3
0
    util.check_running()
    util.check_include()

    parser = OptionParser()
    parser.add_option("-d",
                      "--debug",
                      default=False,
                      action="store_true",
                      dest="debug")
    (options, args) = parser.parse_args()

    if options.debug:
        util.set_debug()
    else:
        util.set_log_file()

    util.info('launching quotes listener')
    cfg_file = os.environ['CONFIG_DIR'] + '/exec.conf'
    util.info("loading config file: %s" % cfg_file)
    trade_cfg = config.load_trade_config(cfg_file)

    gtc = guillotine.multiplex_channel()
    gtc.connect(trade_cfg['servers'],
                trade_cfg['account'],
                trade_cfg['password'],
                name="quotes_listener_" + os.environ['STRAT'])
    gtc.register(quotes_listener(gtc))

    timeout = 0.2  #polling frequency in seconds
    asyncore.loop(timeout, use_poll=True)