/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 22:44:20 UTC
  • mto: This revision was merged to the branch mainline in revision 724.
  • Revision ID: teddy@recompile.se-20140725224420-4a5ct2ptt0hsc92z
Require Python 2.7.

This is in preparation for the eventual move to Python 3, which will
happen as soon as all Python modules required by Mandos are available.
The mandos-ctl and mandos-monitor programs are already portable
between Python 2.6 and Python 3 without changes; this change will
bring the requirement up to Python 2.7.

* INSTALL (Prerequisites/Libraries/Mandos Server): Document
                                                   requirement of
                                                   Python 2.7; remove
                                                   Python-argparse
                                                   which is in the
                                                   Python 2.7 standard
                                                   library.
* debian/control (Source: mandos/Build-Depends-Indep): Depend on
                                                       exactly the
                                                       python2.7
                                                       package and all
                                                       the Python 2.7
                                                       versions of the
                                                       python modules.
  (Package: mandos/Depends): - '' - but still depend on python (<=2.7)
                            and the generic versions of the Python
                            modules; this is for mandos-ctl and
                            mandos-monitor, both of which are
                            compatible with Python 3, and use
                            #!/usr/bin/python.
* mandos: Use #!/usr/bin/python2.7 instead of #!/usr/bin/python.

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, "")
72
72
server_path = "/"
73
73
server_interface = domain + ".Mandos"
74
74
client_interface = domain + ".Mandos.Client"
75
 
version = "1.6.9"
 
75
version = "1.6.7"
 
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))
76
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,
243
249
    # Print header line
244
250
    print(format_string.format(**tablewords))
245
251
    for client in clients:
246
 
        print(format_string.format(**{ key:
 
252
        print(format_string.format(**dict((key,
247
253
                                           valuetostring(client[key],
248
 
                                                         key)
249
 
                                       for key in keywords }))
 
254
                                                         key))
 
255
                                          for key in keywords)))
250
256
 
251
257
def has_actions(options):
252
258
    return any((options.enable,
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")
366
372
    clients={}
367
373
    
368
374
    if options.all or not options.client:
369
 
        clients = { bus.get_object(busname, path): properties
370
 
                    for path, properties in mandos_clients.items() }
 
375
        clients = dict((bus.get_object(busname, path), properties)
 
376
                       for path, properties in
 
377
                       mandos_clients.items())
371
378
    else:
372
379
        for name in options.client:
373
 
            for path, client in mandos_clients.items():
 
380
            for path, client in mandos_clients.iteritems():
374
381
                if client["Name"] == name:
375
382
                    client_objc = bus.get_object(busname, path)
376
383
                    clients[client_objc] = client
377
384
                    break
378
385
            else:
379
 
                print("Client not found on server: {!r}"
 
386
                print("Client not found on server: {0!r}"
380
387
                      .format(name), file=sys.stderr)
381
388
                sys.exit(1)
382
389
    
405
412
                """Set a Client D-Bus property, converted
406
413
                from a string to milliseconds."""
407
414
                set_client_prop(prop,
408
 
                                string_to_delta(value).total_seconds()
409
 
                                * 1000)
 
415
                                timedelta_to_milliseconds
 
416
                                (string_to_delta(value)))
410
417
            if options.remove:
411
418
                mandos_serv.RemoveClient(client.__dbus_object_path__)
412
419
            if options.enable: