~laney/ubuntu-archive-tools/retry-autopkgtest-regressions-bileto-v2

« back to all changes in this revision

Viewing changes to qatracker.py

  • Committer: Colin Watson
  • Date: 2012-12-13 14:50:11 UTC
  • Revision ID: cjwatson@canonical.com-20121213145011-8xvn3h432hz4197x
make all scripts pass current stricter pep8(1) in raring

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
qatracker_product_status = ["Active", "Disabled"]
41
41
qatracker_product_type = ["iso", "package", "hardware"]
42
42
qatracker_product_download_type = ["HTTP", "RSYNC", "ZSYNC",
43
 
                                    "GPG signature", "MD5 checksum", "Comment",
44
 
                                    "Torrent"]
 
43
                                   "GPG signature", "MD5 checksum", "Comment",
 
44
                                   "Torrent"]
45
45
qatracker_testsuite_testcase_status = ["Mandatory", "Disabled", "Run-once",
46
 
                                        "Optional"]
 
46
                                       "Optional"]
47
47
qatracker_result_result = ["Failed", "Passed", "In progress"]
48
48
qatracker_result_status = ["Active", "Disabled"]
49
49
### <- AUTO-GENERATED
70
70
            elif key in self.CONVERT_DATE:
71
71
                try:
72
72
                    setattr(self, key, datetime.strptime(rpc_dict[key],
73
 
                                                        '%Y-%m-%d %H:%M:%S'))
 
73
                                                         '%Y-%m-%d %H:%M:%S'))
74
74
                except ValueError:
75
75
                    setattr(self, key, None)
76
76
            else:
104
104
    def add_result(self, testcase, result, comment='', hardware='', bugs={}):
105
105
        """Add a result to the build"""
106
106
 
107
 
        if self.tracker.access not in ("user", "admin") and \
108
 
           self.tracker.access is not None:
 
107
        if (self.tracker.access not in ("user", "admin") and
 
108
                self.tracker.access is not None):
109
109
            raise Exception("Access denied, you need 'user' but are '%s'" %
110
 
                                self.tracker.access)
 
110
                            self.tracker.access)
111
111
 
112
112
        build_testcase = None
113
113
 
124
124
            raise TypeError("result must be a string or an integer")
125
125
 
126
126
        build_result = self.tracker._get_valid_id_list(qatracker_result_result,
127
 
                                                        result)
 
127
                                                       result)
128
128
 
129
129
        if not isinstance(bugs, dict):
130
130
            raise TypeError("bugs must be a dict")
168
168
            raise IndexError("Couldn't find testcase: %s" % (testcase,))
169
169
 
170
170
        record_filter = self.tracker._get_valid_id_list(
171
 
                                                qatracker_result_status,
172
 
                                                status)
 
171
            qatracker_result_status, status)
173
172
 
174
173
        if len(record_filter) == 0:
175
174
            return []
176
175
 
177
176
        results = []
178
 
        for entry in self.tracker.tracker.results.get_list(self.id,
179
 
                                                        build_testcase,
180
 
                                                        list(record_filter)):
 
177
        for entry in self.tracker.tracker.results.get_list(
 
178
                self.id, build_testcase, list(record_filter)):
181
179
            results.append(QATrackerResult(self.tracker, entry))
182
180
 
183
181
        return results
206
204
 
207
205
        if self.tracker.access != "admin" and self.tracker.access is not None:
208
206
            raise Exception("Access denied, you need 'admin' but are '%s'" %
209
 
                                self.tracker.access)
 
207
                            self.tracker.access)
210
208
 
211
209
        if not isinstance(notify, bool):
212
210
            raise TypeError("notify must be a boolean")
219
217
            valid_products = self.tracker.get_products(0)
220
218
 
221
219
            for entry in valid_products:
222
 
                if entry.title.lower() == str(product).lower() or \
223
 
                   entry.id == product:
 
220
                if (entry.title.lower() == str(product).lower() or
 
221
                        entry.id == product):
224
222
                    build_product = entry
225
223
                    break
226
224
 
231
229
            raise TypeError("Only active products are accepted")
232
230
 
233
231
        self.tracker.tracker.builds.add(build_product.id, self.id,
234
 
                                            str(version), str(note), notify)
 
232
                                        str(version), str(note), notify)
235
233
 
236
234
        new_build = None
237
235
        for entry in self.get_builds(0):
238
 
            if entry.productid == build_product.id \
239
 
               and entry.version == str(version):
 
236
            if (entry.productid == build_product.id
 
237
                    and entry.version == str(version)):
240
238
                new_build = entry
241
239
                break
242
240
 
246
244
        """Get a list of builds for the milestone"""
247
245
 
248
246
        record_filter = self.tracker._get_valid_id_list(
249
 
                                        qatracker_build_milestone_status,
250
 
                                        status)
 
247
            qatracker_build_milestone_status, status)
251
248
 
252
249
        if len(record_filter) == 0:
253
250
            return []
254
251
 
255
252
        builds = []
256
253
        for entry in self.tracker.tracker.builds.get_list(self.id,
257
 
                                                        list(record_filter)):
 
254
                                                          list(record_filter)):
258
255
            builds.append(QATrackerBuild(self.tracker, entry))
259
256
 
260
257
        return builds
264
261
    CONVERT_INT = ['id', 'type', 'status']
265
262
 
266
263
    def get_testcases(self, series,
267
 
                        status=qatracker_testsuite_testcase_status):
 
264
                      status=qatracker_testsuite_testcase_status):
268
265
        """Get a list of testcases associated with the product"""
269
266
 
270
267
        record_filter = self.tracker._get_valid_id_list(
271
 
                                        qatracker_testsuite_testcase_status,
272
 
                                        status)
 
268
            qatracker_testsuite_testcase_status, status)
273
269
 
274
270
        if len(record_filter) == 0:
275
271
            return []
283
279
                            " instance or an integer")
284
280
 
285
281
        testcases = []
286
 
        for entry in self.tracker.tracker.testcases.get_list(self.id, seriesid,
287
 
                                                        list(record_filter)):
 
282
        for entry in self.tracker.tracker.testcases.get_list(
 
283
                self.id, seriesid, list(record_filter)):
288
284
            testcases.append(QATrackerTestcase(self.tracker, entry))
289
285
 
290
286
        return testcases
292
288
 
293
289
class QATrackerResult(QATrackerRPCObject):
294
290
    CONVERT_INT = ['id', 'reporterid', 'revisionid', 'result', 'changedby',
295
 
                    'status']
 
291
                   'status']
296
292
    CONVERT_DATE = ['date', 'lastchange']
297
293
    __deleted = False
298
294
 
302
298
    def delete(self):
303
299
        """Remove the result from the tracker"""
304
300
 
305
 
        if self.tracker.access not in ("user", "admin") and \
306
 
           self.tracker.access is not None:
 
301
        if (self.tracker.access not in ("user", "admin") and
 
302
                self.tracker.access is not None):
307
303
            raise Exception("Access denied, you need 'user' but are '%s'" %
308
 
                                self.tracker.access)
 
304
                            self.tracker.access)
309
305
 
310
306
        if self.__deleted:
311
307
            raise IndexError("Result has already been removed")
320
316
    def save(self):
321
317
        """Save any change that happened on this entry"""
322
318
 
323
 
        if self.tracker.access not in ("user", "admin") and \
324
 
           self.tracker.access is not None:
 
319
        if (self.tracker.access not in ("user", "admin") and
 
320
                self.tracker.access is not None):
325
321
            raise Exception("Access denied, you need 'user' but are '%s'" %
326
 
                                self.tracker.access)
 
322
                            self.tracker.access)
327
323
 
328
324
        if self.__deleted:
329
325
            raise IndexError("Result no longer exists")
330
326
 
331
327
        retval = self.tracker.tracker.results.update(self.id, self.result,
332
 
                                                        self.comment,
333
 
                                                        self.hardware,
334
 
                                                        self.bugs)
 
328
                                                     self.comment,
 
329
                                                     self.hardware,
 
330
                                                     self.bugs)
335
331
        if retval is not True:
336
332
            raise Exception("Failed to update result")
337
333
 
345
341
        manifest_entries = []
346
342
        for entry in self.tracker.tracker.series.get_manifest(self.id):
347
343
            manifest_entries.append(QATrackerSeriesManifest(
348
 
                                        self.tracker, entry))
 
344
                self.tracker, entry))
349
345
 
350
346
        return manifest_entries
351
347
 
378
374
        if username and password:
379
375
            try:
380
376
                auth = str(base64.b64encode(
381
 
                            bytes('%s:%s' % (username, password), 'utf-8')),
382
 
                            'utf-8')
 
377
                    bytes('%s:%s' % (username, password), 'utf-8')),
 
378
                    'utf-8')
383
379
            except TypeError:
384
380
                auth = base64.b64encode('%s:%s' % (username, password))
385
381
 
474
470
        """Get a list of all series"""
475
471
 
476
472
        record_filter = self._get_valid_id_list(
477
 
                                            qatracker_milestone_series_status,
478
 
                                            status)
 
473
            qatracker_milestone_series_status, status)
479
474
 
480
475
        if len(record_filter) == 0:
481
476
            return []