1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 from mx import DateTime
20 from math import ceil, floor
21 from cPickle import dump, load, HIGHEST_PROTOCOL
22 from datetime import datetime
23 import re
24 import textwrap
25
27 tracename=tracefile.split("/")[-1].split(".")[0]
28
29 if injectedfile != None and injectedfile != "None":
30 injectname=injectedfile.split("/")[-1].split(".")[0]
31 name = tracename + "+" + injectname
32 else:
33 name = tracename
34
35 name = profile + "_" + name
36 return name
37
39 return DateTime.DateTimeDelta(d.day, d.hour, d.minute, int(ceil(d.second)))
40
42 d += DateTime.TimeDelta(seconds=0.5)
43 return DateTime.DateTime(d.year, d.month, d.day, d.hour, d.minute, int(floor(d.second)))
44
46 return DateTime.TimestampFromTicks(t)
47
48
50 if len(vnodes) == 0:
51 return "UNUSED"
52 else:
53 return ",".join(["L"+`l`+"V"+`v` for (l, v) in vnodes])
54
55
57 import inspect
58 caller = inspect.stack()[1][3]
59 raise NotImplementedError(caller + ' must be implemented in subclass')
60
62 f = open (filename, "w")
63 dump(data, f, protocol = HIGHEST_PROTOCOL)
64 f.close()
65
67 f = open (filename, "r")
68 data = load(f)
69 f.close()
70 return data
71
72
73 LEASE_ID = 1
74
80
84
86 pnodes = list(set(nodes.values()))
87 normmap = [([y[0] for y in nodes.items() if y[1]==x], x) for x in pnodes]
88 for m in normmap: m[0].sort()
89 s = " ".join([", ".join(["V"+`y` for y in x[0]])+" -> P" + `x[1]` for x in normmap])
90 return s
91
93 bandwidthMBs = float(bandwidth) / 8
94 seconds = size / bandwidthMBs
95 return round_datetime_delta(DateTime.TimeDelta(seconds = seconds))
96
98 if isinstance(value, DateTime.DateTimeType):
99 return datetime.fromtimestamp(value)
100 elif isinstance(value, DateTime.DateTimeDeltaType):
101 return value.seconds
102 else:
103 return value
104
106 fq_name = fq_name.split(".")
107 package_name = ".".join(fq_name[:-1])
108 class_name = fq_name[-1]
109 module = __import__(package_name, globals(), locals(), [class_name])
110 exec("cls = module.%s" % class_name)
111 return cls
112
114 from docutils.core import publish_string
115 latex = textwrap.dedent(text).strip()
116 latex = publish_string(latex, writer_name="latex")
117 latex = re.compile("\\\\begin{document}\n\n\\\\setlength{\\\\locallinewidth}{\\\\linewidth}\n\n(.*)\\\\end{document}", flags=re.DOTALL).search(latex)
118 latex = latex.group(1)
119 return latex
120
122 """
123 A singleton metaclass.
124 From: http://en.wikipedia.org/wiki/Singleton_pattern#Python
125 """
129
135
138
142
146
150
154
157
159 - def __init__(self, initial_state, transitions, state_str = None):
163
170
173
175 if self.state_str == None:
176 return "%s" % state
177 else:
178 return self.state_str[state]
179
187