~cr3/ubuntu-friendly/854636

« back to all changes in this revision

Viewing changes to apps/results/api.py

  • Committer: mikeh
  • Date: 2011-10-07 15:22:48 UTC
  • Revision ID: mikeh@ubuntu-20111007152248-8zib6z6p7uh2xgnb
skippable mouse and keyboard tests, system page layout to show core and additional components, change importer to accept number of hours for minimum age of result to import

Show diffs side-by-side

added added

removed removed

Lines of Context:
92
92
    'audio/alsa_record_playback_usb',
93
93
    'bluetooth/file-transfer',
94
94
    'firewire/hdd',
 
95
    'input devices/keyboard',
 
96
    'input devices/mouse',
95
97
    'mediacards/sd',
96
98
    'mediacards/sd_after_suspend',
97
99
    'vga external video/hdmi',
120
122
}
121
123
 
122
124
 
 
125
def get_core_and_additional_categories(system):
 
126
    if system.form_factor == 'desktop':
 
127
        CORE = CORE_DESKTOP
 
128
        ADDITIONAL = ADDITIONAL_DESKTOP
 
129
 
 
130
    if system.form_factor == 'laptop':
 
131
        CORE = CORE_LAPTOP
 
132
        ADDITIONAL = ADDITIONAL_LAPTOP
 
133
 
 
134
    return (CORE, ADDITIONAL)
 
135
 
 
136
 
123
137
class ResultsRecordImporter:
124
138
 
125
139
    def __init__(self, record):
173
187
 
174
188
        return config
175
189
 
176
 
    def _get_core_and_additional_categories(self, system):
177
 
        if system.form_factor == 'desktop':
178
 
            CORE = CORE_DESKTOP
179
 
            ADDITIONAL = ADDITIONAL_DESKTOP
180
 
 
181
 
        if system.form_factor == 'laptop':
182
 
            CORE = CORE_LAPTOP
183
 
            ADDITIONAL = ADDITIONAL_LAPTOP
184
 
 
185
 
        return (CORE, ADDITIONAL)
186
 
 
187
190
    def _import_unit(self, system):
188
191
        r = self.record.get_record()
189
192
        unit, created = SystemUnit.objects.get_or_create(
193
196
        unit.test_run_source = r.get('test_run_source', '')
194
197
        unit.save()
195
198
        for d in r['test_results']:
196
 
            CORE, ADDITIONAL = self._get_core_and_additional_categories(system)
 
199
            CORE, ADDITIONAL = get_core_and_additional_categories(system)
197
200
            if d['category'] not in CORE and d['category'] not in ADDITIONAL:
198
201
                # we don't care about this test
199
202
                continue
248
251
        penalties = Decimal('0.00')
249
252
        results = SystemUnitTestResult.objects.filter(unit=unit)
250
253
 
251
 
        CORE, ADDITIONAL = self._get_core_and_additional_categories(system)
 
254
        CORE, ADDITIONAL = get_core_and_additional_categories(system)
252
255
 
253
256
        for r in results:
254
257
            if r.category in CORE:
474
477
    optionally tests run from a certain time onwards (once the api supports it)
475
478
    """
476
479
 
477
 
    def __init__(self, release, trigger='Manual'):
478
 
        self.trigger = trigger
 
480
    def __init__(self, release, age=2):
479
481
        self.release = release
 
482
        self.age = age
480
483
        from launchpadlib.launchpad import Launchpad
481
484
        self.api = Launchpad.login_anonymously(
482
485
                    'Launchpad Results', settings.LP_ROOT)
483
486
 
484
487
    def _get_test_runs(self, distro_series):
485
 
        from results.models import ImportRun
486
488
        import datetime
487
489
        r_distro = self.api.distributions['ubuntu']
488
490
        distro_series = r_distro.getSeries(name=distro_series.codename)
489
 
        import_run, created = ImportRun.objects.get_or_create(triggered_by=self.trigger)
490
 
        if created:
491
 
            return distro_series.searchTestRuns()
492
 
        else:
493
 
            start_time = datetime.datetime.now()
494
 
            runs = distro_series.searchTestRuns(created_after=import_run.last_run)
495
 
            import_run.last_run = start_time
496
 
            import_run.save()
497
 
            return runs
 
491
        print datetime.datetime.now()-datetime.timedelta(hours=self.age)
 
492
        return distro_series.searchTestRuns(
 
493
            created_after=datetime.datetime.now()-datetime.timedelta(hours=self.age))
498
494
 
499
495
    def import_results(self):
500
496
        import time