125
def string_to_delta(interval):
126
"""Parse a string and return a datetime.timedelta
128
>>> string_to_delta('7d')
129
datetime.timedelta(7)
130
>>> string_to_delta('60s')
131
datetime.timedelta(0, 60)
132
>>> string_to_delta('60m')
133
datetime.timedelta(0, 3600)
134
>>> string_to_delta('24h')
135
datetime.timedelta(1)
136
>>> string_to_delta(u'1w')
137
datetime.timedelta(7)
140
suffix=unicode(interval[-1])
141
value=int(interval[:-1])
143
delta = datetime.timedelta(value)
145
delta = datetime.timedelta(0, value)
147
delta = datetime.timedelta(0, 0, 0, 0, value)
149
delta = datetime.timedelta(0, 0, 0, 0, 0, value)
151
delta = datetime.timedelta(0, 0, 0, 0, 0, 0, value)
154
except (ValueError, IndexError):
124
159
parser = OptionParser()
125
160
parser.add_option("-i", "--interface", type="string",
144
179
parser.add_option("-t", "--timeout", type="string", # Parsed later
146
181
help="Amount of downtime allowed for clients")
182
parser.add_option("--interval", type="string", # Parsed later
184
help="How often to check that a client is up")
185
parser.add_option("--check", action="store_true", default=False,
186
help="Run self-test")
147
187
(options, args) = parser.parse_args()
149
# Parse the time argument
194
# Parse the time arguments
151
suffix=options.timeout[-1]
152
value=int(options.timeout[:-1])
154
options.timeout = datetime.timedelta(value)
156
options.timeout = datetime.timedelta(0, value)
158
options.timeout = datetime.timedelta(0, 0, 0, 0, value)
160
options.timeout = datetime.timedelta(0, 0, 0, 0, 0, value)
162
options.timeout = datetime.timedelta(0, 0, 0, 0, 0, 0,
166
except (ValueError, IndexError):
196
options.timeout = string_to_delta(options.timeout)
167
198
parser.error("option --timeout: Unparseable time")
201
options.interval = string_to_delta(options.interval)
203
parser.error("option --interval: Unparseable time")
169
205
cert = gnutls.crypto.X509Certificate(open(options.cert).read())
170
206
key = gnutls.crypto.X509PrivateKey(open(options.key).read())
171
207
ca = gnutls.crypto.X509Certificate(open(options.ca).read())