-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.py
50 lines (36 loc) · 1.02 KB
/
helpers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
WeChat: cstutorcs
QQ: 749389476
Email: tutorcs@163.com
# Distance Vector project for CS 6250: Computer Networks
#
# Helper functions for the DistanceVector project. Students should not
# modify this file.
#
# Copyright 2015 Sean Donovan, adapted for new VM by Jared Scott and James Lohse
"""Helpers for Distance Vector project"""
logfile = None
current_logs = None
ROUND_SEP = "-----\n"
ALPHABETIZE = True
def open_log(filename):
global logfile
global current_logs
logfile = open(filename, "w")
current_logs = dict()
def add_entry(switch, logstring):
global current_logs
current_logs[switch] = logstring
print((switch + ":" + logstring))
def finish_round():
global logfile
global current_logs
indices = list(current_logs.keys())
if ALPHABETIZE:
indices = sorted(indices)
for index in indices:
logfile.write(index + ":" + current_logs[index] + "\n")
logfile.write(ROUND_SEP)
current_logs = dict()
def finish_log():
global logfile
logfile.close()