/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-07-25 23:00:45 UTC
  • mto: (237.7.272 trunk)
  • mto: This revision was merged to the branch mainline in revision 321.
  • Revision ID: teddy@recompile.se-20140725230045-94y6ghmwqkb00ffw
Use dictionary comprehensions.

* mandos (Client.start_checker): Use a dictionary comprehension when
                                 creating the "escaped_attrs" mapping.
* mandos-ctl (print_clients): Use a dictionary comprehension when
                              creating keyword arguments to the
                              .format string method.
  (main): Use a dictionary comprehension when creating the "clients"
          mapping.

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.major == 2:
 
45
if sys.version_info[0] == 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
 
77
83
def milliseconds_to_string(ms):
78
84
    td = datetime.timedelta(0, 0, 0, ms)
79
85
    return ("{days}{hours:02}:{minutes:02}:{seconds:02}"
80
 
            .format(days = "{}T".format(td.days) if td.days else "",
 
86
            .format(days = "{0}T".format(td.days) if td.days else "",
81
87
                    hours = td.seconds // 3600,
82
88
                    minutes = (td.seconds % 3600) // 60,
83
89
                    seconds = td.seconds % 60,
271
277
def main():
272
278
    parser = argparse.ArgumentParser()
273
279
    parser.add_argument("--version", action="version",
274
 
                        version = "%(prog)s {}".format(version),
 
280
                        version = "%(prog)s {0}".format(version),
275
281
                        help="show version number and exit")
276
282
    parser.add_argument("-a", "--all", action="store_true",
277
283
                        help="Select all clients")
370
376
                    for path, properties in mandos_clients.items() }
371
377
    else:
372
378
        for name in options.client:
373
 
            for path, client in mandos_clients.items():
 
379
            for path, client in mandos_clients.iteritems():
374
380
                if client["Name"] == name:
375
381
                    client_objc = bus.get_object(busname, path)
376
382
                    clients[client_objc] = client
377
383
                    break
378
384
            else:
379
 
                print("Client not found on server: {!r}"
 
385
                print("Client not found on server: {0!r}"
380
386
                      .format(name), file=sys.stderr)
381
387
                sys.exit(1)
382
388
    
405
411
                """Set a Client D-Bus property, converted
406
412
                from a string to milliseconds."""
407
413
                set_client_prop(prop,
408
 
                                string_to_delta(value).total_seconds()
409
 
                                * 1000)
 
414
                                timedelta_to_milliseconds
 
415
                                (string_to_delta(value)))
410
416
            if options.remove:
411
417
                mandos_serv.RemoveClient(client.__dbus_object_path__)
412
418
            if options.enable: