~roadmr/ubuntu/precise/checkbox/0.13.1

« back to all changes in this revision

Viewing changes to checkbox/lib/template.py

  • Committer: Bazaar Package Importer
  • Author(s): Marc Tardif, Gabor Keleman
  • Date: 2009-08-19 15:36:05 UTC
  • Revision ID: james.westby@ubuntu.com-20090819153605-weo6htup3yi6zn0t
Tags: 0.8~alpha4
* New upstream version:
  * Changed icon.
  * Added timeout property to lock_prompt plugin.
  * Added concept of attachments to tests.
  * Added support for backslahes in templates to wrap lines.
  * Added support blacklisting and whitelisting both tests and suites.
  * Introduced the concept of jobs for suites, tests and attachments.
  * Removed upstart event which is no longer needed.
  * Replaced architecture and category with requires in test definitions.
* Fixed pygst dependency (LP: #334442)
* Fixed configuration file updates during install (LP: #330596)
* Fixed and expanded translations (LP: #347038)
* Fixed ignored system proxy settings (LP: #345548)
* Fixed parsing blank lines in templates (LP: #393907)
* Fixed escaping of lists (LP: #394001)
* Fixed timeout in manual tests (LP: #377986)
* Fixed CLI interface dialog.
* Fixed support for FreeDesktop XDG base directory specification (LP: #363549)
* Added general and package specific apport hooks

[ Gabor Keleman ]
* Fixed untranslated strings in tests (LP: #374666)
* Fixed untranslated last screen (LP: #374646)

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
# You should have received a copy of the GNU General Public License
17
17
# along with Checkbox.  If not, see <http://www.gnu.org/licenses/>.
18
18
#
19
 
import os
20
19
import re
21
20
import logging
22
 
import posixpath
 
21
 
 
22
 
 
23
EXTENDED_STRING = "_extended"
23
24
 
24
25
 
25
26
class Template(object):
26
27
 
27
 
    def __init__(self, filename_field=None, unique_fields=[]):
28
 
        self._filename_field = filename_field
29
 
        self._unique_fields = unique_fields
30
 
 
31
 
    def _reader(self, file, size=4096, delimiter="\n\n"):
 
28
    def _reader(self, file, size=4096, delimiter=r"\n{2,}"):
32
29
        buffer_old = ""
33
30
        while True:
34
31
            buffer_new = file.read(size)
35
32
            if not buffer_new:
36
33
                break
37
34
 
38
 
            lines = (buffer_old + buffer_new).split(delimiter)
 
35
            lines = re.split(delimiter, buffer_old + buffer_new)
39
36
            buffer_old = lines.pop(-1)
40
37
 
41
38
            for line in lines:
61
58
                                % (filename, field, value)
62
59
                    element[field] = value
63
60
                    if extended:
64
 
                        element["%s_extended" % field] = extended
 
61
                        element["%s%s" % (field, EXTENDED_STRING)] = extended
65
62
 
66
63
            string = string.strip("\n")
67
64
            field = value = extended = ""
92
89
                if match:
93
90
                    bit = match.groups()[0].rstrip()
94
91
                    if len(extended) and not re.search(r"[\n ]$", extended):
95
 
                        extended += " "
 
92
                        if extended.endswith("\\"):
 
93
                            extended = extended[:-1].rstrip() + " "
 
94
                        else:
 
95
                            extended += "\n"
96
96
 
97
97
                    extended += bit
98
98
                    continue
102
102
 
103
103
            _save(field, value, extended)
104
104
 
105
 
            # Sanity checks
106
 
            if self._filename_field:
107
 
                if self._filename_field in element:
108
 
                    raise Exception, \
109
 
                        "Template %s already contains filename field: %s" \
110
 
                        % (filename, self._filename_field)
111
 
                element[self._filename_field] = posixpath.basename(filename)
112
 
 
113
 
            for unique_field in self._unique_fields:
114
 
                if [e for e in elements \
115
 
                   if e[unique_field] == element[unique_field]]:
116
 
                    raise Exception, \
117
 
                        "Template %s contains duplicate fields: %s" \
118
 
                        % (filename, unique_field)
119
 
 
120
105
            elements.append(element)
121
106
 
122
107
        return elements
126
111
 
127
112
        file = open(filename, "r")
128
113
        return self.load_file(file, filename)
129
 
 
130
 
    def load_directory(self, directory, blacklist=[], whitelist=[]):
131
 
        logging.info("Loading filenames from directory: %s", directory)
132
 
 
133
 
        whitelist_patterns = [re.compile(r"^%s$" % r) for r in whitelist]
134
 
        blacklist_patterns = [re.compile(r"^%s$" % r) for r in blacklist]
135
 
 
136
 
        elements = []
137
 
        for name in os.listdir(directory):
138
 
            if name.startswith(".") or name.endswith("~"):
139
 
                logging.info("Ignored filename: %s", name)
140
 
                continue
141
 
 
142
 
            if whitelist_patterns:
143
 
                if not [name for p in whitelist_patterns if p.match(name)]:
144
 
                    logging.info("Not whitelisted filename: %s", name)
145
 
                    continue
146
 
            elif blacklist_patterns:
147
 
                if [name for p in blacklist_patterns if p.match(name)]:
148
 
                    logging.info("Blacklisted filename: %s", name)
149
 
                    continue
150
 
 
151
 
            filename = posixpath.join(directory, name)
152
 
            elements.extend(self.load_filename(filename))
153
 
 
154
 
        return elements
155
 
 
156
 
    def load_directories(self, directories, blacklist=[], whitelist=[]):
157
 
        elements = []
158
 
        for directory in directories:
159
 
            elements.extend(self.load_directory(directory, blacklist, whitelist))
160
 
 
161
 
        return elements