Ejemplo n.º 1
0
def communicate_line(line):
    """This processes each line, and handles any errors which they create
    elegantly.
    """
    global timepoint_count
    timepoint_count += 1
    if config.getboolean("Global", "Debug"):
        print("Csv line is:", line)
    now = datetime.datetime.now()
    log_str = "Running timepoint %i at %s" % (timepoint_count, now)
    print(log_str, end="... ")
    chamber_num = config.get("Global", "Chamber")
    sys.stdout.flush()  # flush to force buffering, so above is printed
    try:
        if config.getboolean("Conviron", "Use"):
            chamber.communicate(line)
        if config.getboolean("Heliospectra", "Use"):
            heliospectra.communicate(line)
        print("Success")
        log_tuple = (chamber_num, "FALSE", log_str)
    except Exception as e:
        print("FAIL")
        if config.getboolean("Global", "Debug"):
            traceback.print_exception(*sys.exc_info())
        traceback_text = traceback.format_exc()
        _email_traceback(traceback_text)
        log_tuple = (chamber_num, "TRUE", "%s\n%s" % (log_str, traceback_text))
    _log_to_postgres(log_tuple)
def communicate_line(line):
    """This processes each line, and handles any errors which they create
    elegantly.
    """
    global timepoint_count
    timepoint_count += 1
    LOG.debug("Csv line is: {0!s}".format(line))
    now = datetime.datetime.now().strftime("%d/%m/%y %H:%M")
    log_str = "Running timepoint {} at {}".format(timepoint_count, now)
    print(log_str, end='... ')
    chamber_num = config.get("Global", "Chamber")
    sys.stdout.flush()  # flush to force buffering, so above is printed
    step = ""
    try:
        if config.getboolean("Heliospectra", "Use"):
            step = "Update Heliospectra Lamps"
            heliospectra.communicate(line)
        if config.getboolean("Conviron", "Use"):
            step = "Update Conviron"
            chamber.communicate(line)
            step = "Log Conviron Conditions"
            chamber.log()
        LOG.info(log_str + " Success")
        print("Success")
        log_tuple = (chamber_num, "FALSE", log_str)
    except Exception as e:
        print("FAIL")
        traceback_text = traceback.format_exc()
        fail_msg = "Step {} Failed with traceback:\n{}".format(step,
                                                               traceback_text)
        LOG.error("Could not run timepoint {}\n{}".format(timepoint_count,
                                                          fail_msg))
        log_tuple = (chamber_num, "TRUE", "%s\n%s" % (log_str, traceback_text))
    if config.getboolean("Postgres", "Use"):
        _log_to_postgres(log_tuple)