/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-08-10 14:13:02 UTC
  • Revision ID: teddy@recompile.se-20140810141302-8q1xaaxlh8ho5joz
Emit D-Bus "org.freedesktop.DBus.Properties.PropertiesChanged" signal.

This deprecates the "se.recompile.Mandos.Client.PropertyChanged"
signal.  The new signal also adds support for noticing changes to the
"se.recompile.Mandos.Client.Secret" write-only property.

* mandos (dbus_annotations): Fix usage example in doc string.
  (DBusObjectWithProperties.PropertiesChanged): New; from D-Bus
                                                standard.
  (ClientDBus._interface): Set early instead of later.
  (ClientDBus.notifychangeproperty): Take new "invalidate_only"
                                     parameter, and pass in _interface
                                     as a default keyword argument.
  (ClientDBus.notifychangeproperty/setter): Also emit
                                            PropertiesChanged signal;
                                            emit new value or
                                            invalidation depending on
                                            "invalidate_only".
  (ClientDBus.secret): Apply notifychangeproperty with
                       "invalidate_only=True".
  (ClientDBus._foo): Removed defunct interface annotation.
  (ClientDBus.PropertyChanged): Add annotation; this method is now
                                deprecated.
  (main/MandosDBusService.GetAllClientsWithProperties): Use dictionary
                                                        comprehension.
* DBUS-API (Mandos Client Interface/Signals/PropertyChanged): Removed.
* mandos-monitor: Use standard "PropertiesChanged" signal instead of
                  old signal "PropertyChanged".
  (MandosClientPropertyCache.__init__): Connect to signal
                                        PropertiesChanged instead of
                                        PropertyChanged.
  (MandosClientPropertyCache._property_changed): Removed.
  (MandosClientPropertyCache.property_changed): Renamed to
                                                "properties_changed"
                                                and adapted to new
                                                call signature.
  (MandosClientWidget.properties_changed): - '' -

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, "")
72
72
server_path = "/"
73
73
server_interface = domain + ".Mandos"
74
74
client_interface = domain + ".Mandos.Client"
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))
 
75
version = "1.6.8"
82
76
 
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,
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: