~cr3/launchpad-results/encoding

« back to all changes in this revision

Viewing changes to scripts/submission_prober

  • Committer: Marc Tardif
  • Date: 2011-09-28 15:18:09 UTC
  • Revision ID: marc.tardif@canonical.com-20110928151809-rwn04clcebacbnfm
Added processor states for system units.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/python
 
2
#
 
3
# Copyright 2010-2011 Canonical Ltd.  This software is licensed under the
 
4
# GNU Affero General Public License version 3 (see the file LICENSE).
2
5
 
 
6
import posixpath
3
7
import pytz
4
8
import simplejson
5
9
import transaction
10
14
    timedelta,
11
15
    )
12
16
from optparse import OptionGroup
13
 
from os import path
14
17
from Queue import Empty
15
18
from cStringIO import StringIO
16
19
 
75
78
        """See Application."""
76
79
        super(SubmissionProber, self).parseOptions(options, args)
77
80
 
 
81
        # Get submissions from command line arguments or options
78
82
        if args:
79
83
            self.submissions = [self.getSubmission(arg) for arg in args]
80
84
        elif options.submitted_before or options.submitted_after:
82
86
                submitted_before=options.submitted_before,
83
87
                submitted_after=options.submitted_after)
84
88
        else:
 
89
            self.submissions = None
 
90
 
 
91
    def preProcess(self):
 
92
        """See Application."""
 
93
        super(SubmissionProber, self).preProcess()
 
94
 
 
95
        # Otherwise, get submissions from current and last activities
 
96
        if self.submissions is None:
85
97
            activity = getUtility(IActivitySet).getLastActivity(self.name)
86
98
            if activity:
87
99
                submitted_after = activity.date_started
88
100
            else:
89
101
                submitted_after = datetime.now(tz=UTC) - timedelta(hours=1)
90
102
            self.submissions = self.getSubmissions(
 
103
                submitted_before=self.activity_started,
91
104
                submitted_after=submitted_after)
92
105
 
93
106
    def process(self):
 
107
        """See Application."""
94
108
        launchpad = self.getLaunchpad()
95
109
        for owner, date, link in self.submissions:
96
110
            self.handleSubmission(launchpad, owner, date, link)
107
121
 
108
122
        submission = simplejson.loads(unicode(submission_data))
109
123
        if submission["owner_link"]:
110
 
            owner = path.basename(submission["owner_link"])[1:]
 
124
            owner = posixpath.basename(submission["owner_link"])[1:]
111
125
        else:
112
126
            owner = u""
113
127
 
121
135
            this date.
122
136
        """
123
137
        launchpad = self.getLaunchpad()
124
 
        hwdb = launchpad.load(path.join(str(launchpad._root_uri), "+hwdb"))
 
138
        hwdb = launchpad.load(
 
139
            posixpath.join(str(launchpad._root_uri), "+hwdb"))
125
140
        for submission in hwdb.search(
126
141
            submitted_before=submitted_before,
127
142
            submitted_after=submitted_after):
128
143
 
129
144
            if submission.owner_link:
130
 
                owner = unicode(path.basename(submission.owner_link)[1:])
 
145
                owner = unicode(posixpath.basename(submission.owner_link)[1:])
131
146
            else:
132
147
                owner = u""
133
148
 
151
166
            date_created=date_created)
152
167
 
153
168
        # Build raw submission link to save an API call
154
 
        raw_bz2_link = path.join(link, "raw_submission")
155
 
        raw_bz2_file = self.getURL(raw_bz2_link)
 
169
        raw_link = posixpath.join(link, "raw_submission")
 
170
        raw_file = self.getURL(raw_link)
156
171
        try:
157
 
            raw_bz2_data = raw_bz2_file.read()
 
172
            raw_data = raw_file.read()
158
173
        finally:
159
 
            raw_bz2_file.close()
160
 
 
161
 
        raw_data = decompress(raw_bz2_data)
 
174
            raw_file.close()
 
175
 
 
176
        try:
 
177
            raw_data = decompress(raw_data)
 
178
        except IOError:
 
179
            pass
 
180
 
 
181
        # Some raw data might contain invalid characters
 
182
        raw_data = raw_data.replace("\xFF", "")
 
183
 
162
184
        protocol = CheckboxProtocol(StringIO(raw_data))
163
185
 
164
186
        try:
165
187
            protocol.run(test_run_factory, person=person)
166
 
        except ApplicationError, error:
167
 
            self.logger.error(error)
168
 
        except IOError, error:
169
 
            self.logger.error(error)
 
188
        except AssertionError, error:
 
189
            self.logger.error("Parsing submission %s: %s"
 
190
                % (posixpath.basename(link), error))
 
191
        except Exception, error:
 
192
            self.logger.exception("Parsing submission %s: %s"
 
193
                % (posixpath.basename(link), error))
170
194
 
171
195
 
172
196
def create_test_run(