/mandos/trunk

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/trunk

« back to all changes in this revision

Viewing changes to mandos-ctl

  • Committer: Teddy Hogeborn
  • Date: 2014-07-24 01:35:55 UTC
  • Revision ID: teddy@recompile.se-20140724013555-zrgds2ft5cmwhugb
Fix two mutually cancelling bugs.

* mandos (rfc3339_duration_to_delta): Set "token_duration" to be a
                                      token (and not a tuple) by
                                      removing the final comma.
                                      Construct the needed tuple later
                                      when initializing the
                                      "followers" variable.
* mandos-ctl (rfc3339_duration_to_delta): - '' -

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
from __future__ import (division, absolute_import, print_function,
27
27
                        unicode_literals)
28
28
 
29
 
from future_builtins import *
 
29
try:
 
30
    from future_builtins import *
 
31
except ImportError:
 
32
    pass
30
33
 
31
34
import sys
32
35
import argparse
39
42
 
40
43
import dbus
41
44
 
 
45
if sys.version_info[0] == 2:
 
46
    str = unicode
 
47
 
42
48
locale.setlocale(locale.LC_ALL, "")
43
49
 
44
50
tablewords = {
66
72
server_path = "/"
67
73
server_interface = domain + ".Mandos"
68
74
client_interface = domain + ".Mandos.Client"
69
 
version = "1.6.5"
 
75
version = "1.6.7"
70
76
 
71
77
def timedelta_to_milliseconds(td):
72
78
    """Convert a datetime.timedelta object to milliseconds"""
151
157
    token_duration = Token(re.compile(r"P"), None,
152
158
                           frozenset((token_year, token_month,
153
159
                                      token_day, token_time,
154
 
                                      token_week))),
 
160
                                      token_week)))
155
161
    # Define starting values
156
162
    value = datetime.timedelta() # Value so far
157
163
    found_token = None
158
 
    followers = frozenset(token_duration,) # Following valid tokens
 
164
    followers = frozenset((token_duration,)) # Following valid tokens
159
165
    s = duration                # String left to parse
160
166
    # Loop until end token is found
161
167
    while found_token is not token_end:
230
236
        if keyword in ("Timeout", "Interval", "ApprovalDelay",
231
237
                       "ApprovalDuration", "ExtendedTimeout"):
232
238
            return milliseconds_to_string(value)
233
 
        return unicode(value)
 
239
        return str(value)
234
240
    
235
241
    # Create format string to print table rows
236
242
    format_string = " ".join("{{{key}:{width}}}".format(
310
316
    parser.add_argument("--approval-duration",
311
317
                        help="Set duration of one client approval")
312
318
    parser.add_argument("-H", "--host", help="Set host for client")
313
 
    parser.add_argument("-s", "--secret", type=file,
 
319
    parser.add_argument("-s", "--secret",
 
320
                        type=argparse.FileType(mode="rb"),
314
321
                        help="Set password blob (file) for client")
315
322
    parser.add_argument("-A", "--approve", action="store_true",
316
323
                        help="Approve any current client request")
367
374
    if options.all or not options.client:
368
375
        clients = dict((bus.get_object(busname, path), properties)
369
376
                       for path, properties in
370
 
                       mandos_clients.iteritems())
 
377
                       mandos_clients.items())
371
378
    else:
372
379
        for name in options.client:
373
380
            for path, client in mandos_clients.iteritems():