/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: 2012-06-22 23:33:56 UTC
  • Revision ID: teddy@recompile.se-20120622233356-odoqqt2ki2gssn37
* Makefile (check): Also check mandos-ctl.
* mandos-ctl: All options taking a time interval argument can now take
              an RFC 3339 duration.
  (rfc3339_duration_to_delta): New function.
  (string_to_delta): Try rfc3339_duration_to_delta first.
  (main): New "--check" option.
* mandos-ctl.xml (SYNOPSIS, OPTIONS): Document new "--check" option.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
4
4
# Mandos Monitor - Control and monitor the Mandos server
5
5
6
 
# Copyright © 2008-2014 Teddy Hogeborn
7
 
# Copyright © 2008-2014 Björn Påhlsson
 
6
# Copyright © 2008-2012 Teddy Hogeborn
 
7
# Copyright © 2008-2012 Björn Påhlsson
8
8
9
9
# This program is free software: you can redistribute it and/or modify
10
10
# it under the terms of the GNU General Public License as published by
66
66
server_path = "/"
67
67
server_interface = domain + ".Mandos"
68
68
client_interface = domain + ".Mandos.Client"
69
 
version = "1.6.5"
 
69
version = "1.6.0"
70
70
 
71
71
def timedelta_to_milliseconds(td):
72
72
    """Convert a datetime.timedelta object to milliseconds"""
85
85
 
86
86
 
87
87
def rfc3339_duration_to_delta(duration):
88
 
    """Parse an RFC 3339 "duration" and return a datetime.timedelta
 
88
    """Parse a RFC 3339 "duration" and return a datetime.timedelta
89
89
    
90
90
    >>> rfc3339_duration_to_delta("P7D")
91
91
    datetime.timedelta(7)
103
103
    datetime.timedelta(1, 200)
104
104
    """
105
105
    
106
 
    # Parsing an RFC 3339 duration with regular expressions is not
 
106
    # Parsing a RFC 3339 duration with regular expressions is not
107
107
    # possible - there would have to be multiple places for the same
108
 
    # values, like seconds.  The current code, while more esoteric, is
109
 
    # cleaner without depending on a parsing library.  If Python had a
 
108
    # values, like seconds.  This, while more esoteric, is cleaner
 
109
    # without depending on a parsing library.  If Python had a
110
110
    # built-in library for parsing we would use it, but we'd like to
111
111
    # avoid excessive use of external libraries.
112
112
    
199
199
    >>> string_to_delta("5m 30s")
200
200
    datetime.timedelta(0, 330)
201
201
    """
 
202
    value = datetime.timedelta(0)
 
203
    regexp = re.compile(r"(\d+)([dsmhw]?)")
202
204
    
203
205
    try:
204
206
        return rfc3339_duration_to_delta(interval)
205
207
    except ValueError:
206
208
        pass
207
209
    
208
 
    value = datetime.timedelta(0)
209
 
    regexp = re.compile(r"(\d+)([dsmhw]?)")
210
 
    
211
210
    for num, suffix in regexp.findall(interval):
212
211
        if suffix == "d":
213
212
            value += datetime.timedelta(int(num))
331
330
 
332
331
    if options.check:
333
332
        fail_count, test_count = doctest.testmod()
334
 
        sys.exit(os.EX_OK if fail_count == 0 else 1)
 
333
        sys.exit(0 if fail_count == 0 else 1)
335
334
    
336
335
    try:
337
336
        bus = dbus.SystemBus()