~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/scripts/utilities/settingsauditor.py

  • Committer: j.c.sackett
  • Date: 2011-04-25 20:17:33 UTC
  • mto: This revision was merged to the branch mainline in revision 12963.
  • Revision ID: jonathan.sackett@canonical.com-20110425201733-wimiblogx65kwnj7
Lint fixes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
from collections import defaultdict
13
13
import re
14
14
 
 
15
 
15
16
class SettingsAuditor:
16
17
    """Reads the security.cfg file and collects errors.
17
18
 
19
20
    specialized parsing--not interpreting the settings, but verifying."""
20
21
 
21
22
    header_regex = re.compile(r'.*?(?=\[)', re.MULTILINE|re.DOTALL)
22
 
    section_regex = re.compile(r'\[.*?\].*?(?=(\[)|($\Z))', re.MULTILINE|re.DOTALL)
 
23
    section_regex = re.compile(
 
24
        r'\[.*?\].*?(?=(\[)|($\Z))', re.MULTILINE|re.DOTALL)
23
25
    section_label_regex = re.compile(r'\[.*\]')
24
 
    
 
26
 
25
27
    def __init__(self, data):
26
28
        self.data = data
27
29
        self.errors = {}
31
33
    def _getHeader(self):
32
34
        """Removes the header comments from the security file.
33
35
 
34
 
        The comments at the start of the file aren't something we want to kill.
 
36
        The comments at the start of the file aren't something we
 
37
        want to kill.
35
38
        """
36
39
        header = self.header_regex.match(self.data)
37
40
        if header is not None:
60
63
            label = self.section_label_regex.match(section).group()
61
64
            self.config_labels.append(label)
62
65
            self.config_blocks[label] = section
63
 
        
 
66
 
64
67
    def _processBlocks(self):
65
68
        for block in self.config_labels:
66
69
            data = set(self.config_blocks[block].split('\n')[1:])
92
95
        for label in self.config_labels:
93
96
            data.append(self.config_blocks[label])
94
97
        return '%s%s' % (header, '\n\n'.join(data))
95
 
       
96
98
 
97
99
    @property
98
100
    def error_data(self):