/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: 2016-06-23 20:10:40 UTC
  • mto: This revision was merged to the branch mainline in revision 861.
  • Revision ID: teddy@recompile.se-20160623201040-33k2tpdbnxjqfjcp
Tags: version-1.7.10-1
* Makefile (version): Change to 1.7.10.
* NEWS (Version 1.7.10): Add new entry.
* debian/changelog (1.7.10-1): - '' -

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
import os
40
40
import collections
41
41
import doctest
42
 
import json
43
42
 
44
43
import dbus
45
44
 
281
280
                        help="Select all clients")
282
281
    parser.add_argument("-v", "--verbose", action="store_true",
283
282
                        help="Print all fields")
284
 
    parser.add_argument("-j", "--dump-json", action="store_true",
285
 
                        help="Dump client data in JSON format")
286
283
    parser.add_argument("-e", "--enable", action="store_true",
287
284
                        help="Enable client")
288
285
    parser.add_argument("-d", "--disable", action="store_true",
331
328
    if has_actions(options) and not (options.client or options.all):
332
329
        parser.error("Options require clients names or --all.")
333
330
    if options.verbose and has_actions(options):
334
 
        parser.error("--verbose can only be used alone.")
335
 
    if options.dump_json and (options.verbose or has_actions(options)):
336
 
        parser.error("--dump-json can only be used alone.")
 
331
        parser.error("--verbose can only be used alone or with"
 
332
                     " --all.")
337
333
    if options.all and not has_actions(options):
338
334
        parser.error("--all requires an action.")
339
 
    
 
335
 
340
336
    if options.check:
341
337
        fail_count, test_count = doctest.testmod()
342
338
        sys.exit(os.EX_OK if fail_count == 0 else 1)
393
389
                sys.exit(1)
394
390
    
395
391
    if not has_actions(options) and clients:
396
 
        if options.verbose or options.dump_json:
 
392
        if options.verbose:
397
393
            keywords = ("Name", "Enabled", "Timeout", "LastCheckedOK",
398
394
                        "Created", "Interval", "Host", "Fingerprint",
399
395
                        "CheckerRunning", "LastEnabled",
404
400
        else:
405
401
            keywords = defaultkeywords
406
402
        
407
 
        if options.dump_json:
408
 
            json.dump({client["Name"]: {key: client[key]
409
 
                                        for key in keywords }
410
 
                       for client in clients.values() },
411
 
                      fp = sys.stdout, indent = 4,
412
 
                      separators = (',', ': '))
413
 
            print()
414
 
        else:
415
 
            print_clients(clients.values(), keywords)
 
403
        print_clients(clients.values(), keywords)
416
404
    else:
417
405
        # Process each client in the list by all selected options
418
406
        for client in clients: