/mandos/release

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

« back to all changes in this revision

Viewing changes to mandos-ctl

  • Committer: Teddy Hogeborn
  • Date: 2014-08-06 20:47:42 UTC
  • mfrom: (237.7.275 trunk)
  • Revision ID: teddy@recompile.se-20140806204742-tpy81dsvwt2zl975
MergeĀ fromĀ trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
 
43
43
import dbus
44
44
 
45
 
if sys.version_info[0] == 2:
 
45
if sys.version_info.major == 2:
46
46
    str = unicode
47
47
 
48
48
locale.setlocale(locale.LC_ALL, "")
74
74
client_interface = domain + ".Mandos.Client"
75
75
version = "1.6.7"
76
76
 
77
 
def timedelta_to_milliseconds(td):
78
 
    """Convert a datetime.timedelta object to milliseconds"""
79
 
    return ((td.days * 24 * 60 * 60 * 1000)
80
 
            + (td.seconds * 1000)
81
 
            + (td.microseconds // 1000))
82
 
 
83
77
def milliseconds_to_string(ms):
84
78
    td = datetime.timedelta(0, 0, 0, ms)
85
79
    return ("{days}{hours:02}:{minutes:02}:{seconds:02}"
86
 
            .format(days = "{0}T".format(td.days) if td.days else "",
 
80
            .format(days = "{}T".format(td.days) if td.days else "",
87
81
                    hours = td.seconds // 3600,
88
82
                    minutes = (td.seconds % 3600) // 60,
89
83
                    seconds = td.seconds % 60,
157
151
    token_duration = Token(re.compile(r"P"), None,
158
152
                           frozenset((token_year, token_month,
159
153
                                      token_day, token_time,
160
 
                                      token_week))),
 
154
                                      token_week)))
161
155
    # Define starting values
162
156
    value = datetime.timedelta() # Value so far
163
157
    found_token = None
164
 
    followers = frozenset(token_duration,) # Following valid tokens
 
158
    followers = frozenset((token_duration,)) # Following valid tokens
165
159
    s = duration                # String left to parse
166
160
    # Loop until end token is found
167
161
    while found_token is not token_end:
249
243
    # Print header line
250
244
    print(format_string.format(**tablewords))
251
245
    for client in clients:
252
 
        print(format_string.format(**dict((key,
 
246
        print(format_string.format(**{ key:
253
247
                                           valuetostring(client[key],
254
 
                                                         key))
255
 
                                          for key in keywords)))
 
248
                                                         key)
 
249
                                       for key in keywords }))
256
250
 
257
251
def has_actions(options):
258
252
    return any((options.enable,
277
271
def main():
278
272
    parser = argparse.ArgumentParser()
279
273
    parser.add_argument("--version", action="version",
280
 
                        version = "%(prog)s {0}".format(version),
 
274
                        version = "%(prog)s {}".format(version),
281
275
                        help="show version number and exit")
282
276
    parser.add_argument("-a", "--all", action="store_true",
283
277
                        help="Select all clients")
372
366
    clients={}
373
367
    
374
368
    if options.all or not options.client:
375
 
        clients = dict((bus.get_object(busname, path), properties)
376
 
                       for path, properties in
377
 
                       mandos_clients.items())
 
369
        clients = { bus.get_object(busname, path): properties
 
370
                    for path, properties in mandos_clients.items() }
378
371
    else:
379
372
        for name in options.client:
380
 
            for path, client in mandos_clients.iteritems():
 
373
            for path, client in mandos_clients.items():
381
374
                if client["Name"] == name:
382
375
                    client_objc = bus.get_object(busname, path)
383
376
                    clients[client_objc] = client
384
377
                    break
385
378
            else:
386
 
                print("Client not found on server: {0!r}"
 
379
                print("Client not found on server: {!r}"
387
380
                      .format(name), file=sys.stderr)
388
381
                sys.exit(1)
389
382
    
412
405
                """Set a Client D-Bus property, converted
413
406
                from a string to milliseconds."""
414
407
                set_client_prop(prop,
415
 
                                timedelta_to_milliseconds
416
 
                                (string_to_delta(value)))
 
408
                                string_to_delta(value).total_seconds()
 
409
                                * 1000)
417
410
            if options.remove:
418
411
                mandos_serv.RemoveClient(client.__dbus_object_path__)
419
412
            if options.enable: