コード例 #1
0
 def __init__(self, confs, init=False):
     pprint.pprint(confs)
     self.kafka_topic = confs["kafka_topic"]
     self.team_id = confs["team_id"]
     kafka_servers = confs["kafka_servers"].split(",")
     self.kafka = KafkaProducer(bootstrap_servers=kafka_servers)
     Backend.__init__(self, confs, init)
コード例 #2
0
def helper(capsys, input_transaction_summary_file, input_master_accounts_file,
           expected_new_master_account, expected_tail_of_terminal_output):

    # cleanup package
    reload(app)

    # create a temporary file in the system to store the valid accounts in masterAccountsFile:
    temp_fd2, temp_file2 = tempfile.mkstemp()
    master_accounts_file = temp_file2
    with open(master_accounts_file, 'w') as wf:
        wf.write('\n'.join(input_master_accounts_file))
    temp_fd, temp_file = tempfile.mkstemp()
    merged_transaction_file = temp_file
    with open(merged_transaction_file, 'w') as wf:
        wf.write('\n'.join(input_transaction_summary_file))

    # prepare program parameters
    sys.argv = ['Backend.py', master_accounts_file, merged_transaction_file]

    # run the program
    app.main()

    # capture terminal output / errors
    # assuming that in this case we don't use stderr
    out, err = capsys.readouterr()

    # split terminal output in lines
    out_lines = out.splitlines()

    # compare terminal outputs at the end.`
    for i in range(1, len(expected_tail_of_terminal_output) + 1):
        index = i * -1
        assert expected_tail_of_terminal_output[index] == out_lines[index]

    # compare transactions:
    with open(master_accounts_file, 'r') as of:
        content = of.read().splitlines()
        for ind in range(len(content)):
            assert content[ind] == expected_new_master_account[ind]

    # clean up
    os.close(temp_fd)
    os.remove(temp_file)
    os.close(temp_fd2)
    os.remove(temp_file2)
コード例 #3
0
 def save_answer(self, user_id, survey_id, answer):
     ans_id = Backend.save_answer(self, user_id, survey_id, answer)
     dt = datetime.strptime(answer["ts"], '%Y-%m-%d %H:%M')
     timestamp = (dt - datetime(1970, 1, 1)).total_seconds()
     del answer["ts"]
     payload = {
         "teamId": self.team_id,
         "userId": user_id,
         "timestamp": timestamp,
         "surveyId": survey_id,
         "responses": answer,
         "answerId": ans_id
     }
     print "[posting to kafka: {0}]".format(payload)
     self.post_kafka(json.dumps(payload))
コード例 #4
0
ファイル: tmux_ssh_runs.py プロジェクト: htruong0/pyHepGrid
                            str(port)]).replace(".run", "")
    return window_name


def do_single_run(host, port, runcard, serverloc, tot, desktop_list,
                  run_directory):
    valid_port = get_unblocked_port(host, port)
    print("Using port {0}".format(valid_port))

    window_name = get_window_name(host, runcard, valid_port)
    create_new_session_with_server(window_name, serverloc, tot, host,
                                   valid_port)
    print("Server up and running at {0}:{1}".format(host, valid_port))
    print("TMUX window name: {0}".format(window_name))

    for no, desktop in enumerate(desktop_list):
        create_NNLOJET_instance(valid_port, host, no, tot, window_name,
                                runcard, desktop, run_directory)
        print("NNLOJET instance [{0}/{1}] submitted to {2}.".format(
            no + 1, tot, desktop))
    arrange_tmux_window(window_name)


if __name__ == "__main__":
    for runcard in header.dictCard:
        backend = backend.Backend()
        tag = header.dictCard[runcard]
        run_directory = backend.get_local_dir_name(runcard, tag)
        do_single_run(host, port, runcard, serverloc, tot, desktop_list,
                      run_directory)
コード例 #5
0
# Handles player shooting an arrow. Prompts for a direction, validates it and shoots an arrow in that direction,
# then calls itself recursively until the player has directed the arrow through all three rooms.
def shoot_prompt(itr, roomFrom):
    if backend.getArrowsLeft() < 1:
        print(MSG_NO_ARROWS_LEFT)
        basic_prompt()
        return

    for i in range(itr, 3):
        print(MSG_SHOOT[i])
        direction_input = input(MSG_SHOOT_DIRECTION)

        direction = getAssertDirection(direction_input)
        if not direction == None:
            backend.shoot(direction, roomFrom)
            room = roomFrom.go(direction)
            shoot_prompt(i + 1, room)
            return
        else:
            shoot_prompt(i, roomFrom)
            return

    backend.setCurrentArrows(backend.getArrowsLeft() - 1)
    basic_prompt()


print(MSG_INTRO)
backend = Backend()
basic_prompt()