/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-25 23:44:04 UTC
  • mfrom: (723.1.7 python27)
  • Revision ID: teddy@recompile.se-20140725234404-m6c733af4i3zs0la
Merge from Python 2.7 branch.

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,
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")
382
376
                    clients[client_objc] = client
383
377
                    break
384
378
            else:
385
 
                print("Client not found on server: {0!r}"
 
379
                print("Client not found on server: {!r}"
386
380
                      .format(name), file=sys.stderr)
387
381
                sys.exit(1)
388
382
    
411
405
                """Set a Client D-Bus property, converted
412
406
                from a string to milliseconds."""
413
407
                set_client_prop(prop,
414
 
                                timedelta_to_milliseconds
415
 
                                (string_to_delta(value)))
 
408
                                string_to_delta(value).total_seconds()
 
409
                                * 1000)
416
410
            if options.remove:
417
411
                mandos_serv.RemoveClient(client.__dbus_object_path__)
418
412
            if options.enable: