id
int64
0
843k
repository_name
stringlengths
7
55
file_path
stringlengths
9
332
class_name
stringlengths
3
290
human_written_code
stringlengths
12
4.36M
class_skeleton
stringlengths
19
2.2M
total_program_units
int64
1
9.57k
total_doc_str
int64
0
4.2k
AvgCountLine
float64
0
7.89k
AvgCountLineBlank
float64
0
300
AvgCountLineCode
float64
0
7.89k
AvgCountLineComment
float64
0
7.89k
AvgCyclomatic
float64
0
130
CommentToCodeRatio
float64
0
176
CountClassBase
float64
0
48
CountClassCoupled
float64
0
589
CountClassCoupledModified
float64
0
581
CountClassDerived
float64
0
5.37k
CountDeclInstanceMethod
float64
0
4.2k
CountDeclInstanceVariable
float64
0
299
CountDeclMethod
float64
0
4.2k
CountDeclMethodAll
float64
0
4.2k
CountLine
float64
1
115k
CountLineBlank
float64
0
9.01k
CountLineCode
float64
0
94.4k
CountLineCodeDecl
float64
0
46.1k
CountLineCodeExe
float64
0
91.3k
CountLineComment
float64
0
27k
CountStmt
float64
1
93.2k
CountStmtDecl
float64
0
46.1k
CountStmtExe
float64
0
90.2k
MaxCyclomatic
float64
0
759
MaxInheritanceTree
float64
0
16
MaxNesting
float64
0
34
SumCyclomatic
float64
0
6k
145,648
Linaro/squad
Linaro_squad/squad/core/migrations/0077_knownissue.py
squad.core.migrations.0077_knownissue.Migration
class Migration(migrations.Migration): dependencies = [ ('core', '0076_patch_builds'), ] operations = [ migrations.CreateModel( name='KnownIssue', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('title', models.CharField(max_length=1024)), ('test_name', models.CharField(max_length=1024)), ('url', models.URLField(blank=True, null=True)), ('notes', models.TextField(blank=True, null=True)), ('active', models.BooleanField(default=True)), ('intermittent', models.BooleanField(default=False)), ('environment', models.ManyToManyField(to='core.Environment')), ], ), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
21
2
19
3
18
0
3
3
2
0
1
0
0
145,649
Linaro/squad
Linaro_squad/squad/core/migrations/0078_cache_test_run_counts.py
squad.core.migrations.0078_cache_test_run_counts.Migration
class Migration(migrations.Migration): dependencies = [ ('core', '0077_knownissue'), ] operations = [ migrations.AddField( model_name='projectstatus', name='test_runs_completed', field=models.IntegerField(default=0), ), migrations.AddField( model_name='projectstatus', name='test_runs_incomplete', field=models.IntegerField(default=0), ), migrations.AddField( model_name='projectstatus', name='test_runs_total', field=models.IntegerField(default=0), ), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
23
2
21
3
20
0
3
3
2
0
1
0
0
145,650
Linaro/squad
Linaro_squad/squad/core/migrations/0079_init_cache_test_run_counts.py
squad.core.migrations.0079_init_cache_test_run_counts.Migration
class Migration(migrations.Migration): dependencies = [ ('core', '0078_cache_test_run_counts'), ] operations = [ migrations.RunPython(update, reverse_code=migrations.RunPython.noop) ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
9
2
7
3
6
0
3
3
2
0
1
0
0
145,651
Linaro/squad
Linaro_squad/squad/core/migrations/0080_auto_20180810_0047.py
squad.core.migrations.0080_auto_20180810_0047.Migration
class Migration(migrations.Migration): dependencies = [ ('core', '0079_init_cache_test_run_counts'), ] operations = [ migrations.CreateModel( name='NotificationDelivery', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('subject', models.CharField(blank=True, max_length=40, null=True)), ('txt', models.CharField(blank=True, max_length=40, null=True)), ('html', models.CharField(blank=True, max_length=40, null=True)), ('status', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='delivery', to='core.ProjectStatus')), ], ), migrations.AlterUniqueTogether( name='notificationdelivery', unique_together=set([('status', 'subject', 'txt', 'html')]), ), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
22
2
20
3
19
0
3
3
2
0
1
0
0
145,652
Linaro/squad
Linaro_squad/squad/api/rest.py
squad.api.rest.MetricViewSet
class MetricViewSet(NestedViewSetMixin, ModelViewSet): queryset = Metric.objects.prefetch_related('suite', 'metadata').all() project_lookup_key = 'build__project__in' serializer_class = MetricSerializer filterset_class = MetricFilter filter_class = filterset_class # TODO: remove when django-filters 1.x is not supported anymore pagination_class = CursorPaginationWithPageSize ordering = ('id',)
class MetricViewSet(NestedViewSetMixin, ModelViewSet): pass
1
0
0
0
0
0
0
0.13
2
0
0
0
0
0
0
2
9
1
8
8
7
1
8
8
7
0
2
0
0
145,653
Linaro/squad
Linaro_squad/squad/api/rest.py
squad.api.rest.MetricThresholdViewSet
class MetricThresholdViewSet(viewsets.ModelViewSet): queryset = MetricThreshold.objects.all() serializer_class = MetricThresholdSerializer filterset_fields = ('name', 'value', 'is_higher_better', 'environment', 'project') filter_fields = filterset_fields # TODO: remove when django-filters 1.x is not supported anymore ordering_fields = ('id', 'environment', 'name', 'project') filterset_class = MetricThresholdFilter filter_class = filterset_class
class MetricThresholdViewSet(viewsets.ModelViewSet): pass
1
0
0
0
0
0
0
0.25
1
0
0
0
0
0
0
0
9
1
8
8
7
2
8
8
7
0
1
0
0
145,654
Linaro/squad
Linaro_squad/squad/core/admin.py
squad.core.admin.AdminSubscriptionInline
class AdminSubscriptionInline(admin.StackedInline): model = models.AdminSubscription fields = ['email'] extra = 0
class AdminSubscriptionInline(admin.StackedInline): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
4
0
4
4
3
0
4
4
3
0
1
0
0
145,655
Linaro/squad
Linaro_squad/squad/api/rest.py
squad.api.rest.MetricThresholdSerializer
class MetricThresholdSerializer(DynamicFieldsModelSerializer, serializers.HyperlinkedModelSerializer): id = serializers.IntegerField(read_only=True) class Meta: model = MetricThreshold fields = '__all__' def pre_save(self, data): try: threshold, created = MetricThreshold.objects.update_or_create(**data) except Exception as e: raise serializers.ValidationError({'duplicated_thresholds': [e]}) return threshold def update(self, instance, validated_data): return self.pre_save(validated_data) def create(self, validated_data): return self.pre_save(validated_data)
class MetricThresholdSerializer(DynamicFieldsModelSerializer, serializers.HyperlinkedModelSerializer): class Meta: def pre_save(self, data): pass def update(self, instance, validated_data): pass def create(self, validated_data): pass
5
0
3
0
3
0
1
0
2
2
1
0
3
0
3
4
20
5
15
9
10
0
15
8
10
2
2
1
4
145,656
Linaro/squad
Linaro_squad/squad/core/migrations/0082_populate_status_has_metrics.py
squad.core.migrations.0082_populate_status_has_metrics.Migration
class Migration(migrations.Migration): dependencies = [ ('core', '0081_status_has_metrics'), ] if SQLITE: operations = [] else: operations = [ migrations.RunSQL(SQL, reverse_sql=migrations.RunSQL.noop), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
12
2
10
3
9
0
5
3
4
0
1
1
0
145,657
Linaro/squad
Linaro_squad/squad/core/migrations/0083_rename_knownissue_environments.py
squad.core.migrations.0083_rename_knownissue_environments.Migration
class Migration(migrations.Migration): dependencies = [ ('core', '0082_populate_status_has_metrics'), ] operations = [ migrations.RenameField( model_name='knownissue', old_name='environment', new_name='environments', ), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
13
2
11
3
10
0
3
3
2
0
1
0
0
145,658
Linaro/squad
Linaro_squad/squad/core/migrations/0084_projectstatus_regressions_fixes.py
squad.core.migrations.0084_projectstatus_regressions_fixes.Migration
class Migration(migrations.Migration): dependencies = [ ('core', '0083_rename_knownissue_environments'), ] operations = [ migrations.AddField( model_name='projectstatus', name='fixes', field=models.TextField(blank=True, null=True, validators=[squad.core.utils.yaml_validator]), ), migrations.AddField( model_name='projectstatus', name='regressions', field=models.TextField(blank=True, null=True, validators=[squad.core.utils.yaml_validator]), ), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
18
2
16
3
15
0
3
3
2
0
1
0
0
145,659
Linaro/squad
Linaro_squad/squad/api/rest.py
squad.api.rest.MetricSerializer
class MetricSerializer(DynamicFieldsModelSerializer, serializers.HyperlinkedModelSerializer): id = serializers.IntegerField(read_only=True) def __init__(self, *args, **kwargs): remove_fields = kwargs.pop('remove_fields', None) super(MetricSerializer, self).__init__(*args, **kwargs) if remove_fields: # for multiple fields in a list for field_name in remove_fields: self.fields.pop(field_name) name = serializers.CharField(source='full_name', read_only=True) short_name = serializers.CharField(source='name') measurement_list = serializers.ListField(read_only=True) class Meta: model = Metric exclude = ['measurements']
class MetricSerializer(DynamicFieldsModelSerializer, serializers.HyperlinkedModelSerializer): def __init__(self, *args, **kwargs): pass class Meta:
3
0
7
0
6
1
3
0.07
2
1
0
0
1
0
1
2
19
4
14
10
11
1
14
10
11
3
2
2
3
145,660
Linaro/squad
Linaro_squad/squad/api/rest.py
squad.api.rest.LatestTestResultsSerializer
class LatestTestResultsSerializer(serializers.BaseSerializer): def to_representation(self, build): metadata = self.context.get('metadata') project_environments = self.context.get('environments') suite = self.context.get('suite') test_runs = {tr.id: tr.environment for tr in build.test_runs.all()} tests = Test.objects.filter( test_run_id__in=test_runs.keys(), metadata=metadata, ).prefetch_related('metadata').order_by() environments = { e: { 'test': TestSerializer(None, context=self.context).data, 'environment': EnvironmentSerializer(e, context=self.context).data } for e in project_environments } for test in tests.all(): e = test_runs[test.test_run_id] test.suite = suite is_duplicate = False if environments[e]['test']['test_run']: # Duplicate found. is_duplicate = True environments[e]['test'] = TestSerializer(test, context=self.context, remove_fields=['known_issues']).data if is_duplicate: environments[e]['test']['status'], environments[e]['test']['confidence'] = test_confidence(test) environments[e]['test_url_path'] = reverse('test_history', args=[ build.project.group.slug, build.project.slug, build.version, test.test_run_id, metadata.suite.replace('/', '$'), metadata.name ]) serialized_obj = { 'build': BuildSerializer(build, context=self.context).data, 'build_url_path': reverse( 'build', args=[ build.project.group.slug, build.project.slug, build.version ]), 'environments': environments.values() } return serialized_obj
class LatestTestResultsSerializer(serializers.BaseSerializer): def to_representation(self, build): pass
2
0
49
3
45
1
4
0.02
1
4
4
0
1
1
1
1
50
3
46
12
44
1
20
11
18
4
1
2
4
145,661
Linaro/squad
Linaro_squad/squad/core/migrations/0085_projectstatus_defaults.py
squad.core.migrations.0085_projectstatus_defaults.Migration
class Migration(migrations.Migration): dependencies = [ ('core', '0084_projectstatus_regressions_fixes'), ] operations = [ migrations.AlterField( model_name='projectstatus', name='tests_fail', field=models.IntegerField(default=0), ), migrations.AlterField( model_name='projectstatus', name='tests_pass', field=models.IntegerField(default=0), ), migrations.AlterField( model_name='projectstatus', name='tests_skip', field=models.IntegerField(default=0), ), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
23
2
21
3
20
0
3
3
2
0
1
0
0
145,662
Linaro/squad
Linaro_squad/squad/api/rest.py
squad.api.rest.KnownIssueViewSet
class KnownIssueViewSet(viewsets.ModelViewSet): queryset = KnownIssue.objects.prefetch_related('environments').all() serializer_class = KnownIssueSerializer filterset_class = KnownIssueFilter filter_class = filterset_class # TODO: remove when django-filters 1.x is not supported anymore filterset_fields = ('title', 'test_name', 'active', 'intermittent', 'environments') filter_fields = filterset_fields # TODO: remove when django-filters 1.x is not supported anymore ordering_fields = ('title', 'id')
class KnownIssueViewSet(viewsets.ModelViewSet): pass
1
0
0
0
0
0
0
0.25
1
0
0
0
0
0
0
0
9
1
8
8
7
2
8
8
7
0
1
0
0
145,663
Linaro/squad
Linaro_squad/squad/core/migrations/0086_xfail.py
squad.core.migrations.0086_xfail.Migration
class Migration(migrations.Migration): dependencies = [ ('core', '0085_projectstatus_defaults'), ] operations = [ migrations.AddField( model_name='projectstatus', name='tests_xfail', field=models.IntegerField(default=0), ), migrations.AddField( model_name='status', name='tests_xfail', field=models.IntegerField(default=0), ), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
18
2
16
3
15
0
3
3
2
0
1
0
0
145,664
Linaro/squad
Linaro_squad/squad/core/migrations/0087_test_known_issues.py
squad.core.migrations.0087_test_known_issues.Migration
class Migration(migrations.Migration): dependencies = [ ('core', '0086_xfail'), ] operations = [ migrations.AddField( model_name='test', name='known_issues', field=models.ManyToManyField(to='core.KnownIssue'), ), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
13
2
11
3
10
0
3
3
2
0
1
0
0
145,665
Linaro/squad
Linaro_squad/squad/core/migrations/0088_user_subscriptions.py
squad.core.migrations.0088_user_subscriptions.Migration
class Migration(migrations.Migration): dependencies = [ migrations.swappable_dependency(settings.AUTH_USER_MODEL), ('core', '0087_test_known_issues'), ] operations = [ migrations.AddField( model_name='subscription', name='user', field=models.ForeignKey(blank=True, default=None, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL), ), migrations.AlterField( model_name='subscription', name='email', field=models.CharField(blank=True, max_length=1024, null=True, validators=[django.core.validators.EmailValidator()]), ), migrations.AlterUniqueTogether( name='subscription', unique_together=set([('project', 'user')]), ), migrations.RunPython(existing_subscriptions, reverse_existing_subscriptions), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
25
2
23
3
22
0
3
3
2
0
1
0
0
145,666
Linaro/squad
Linaro_squad/squad/core/migrations/0081_status_has_metrics.py
squad.core.migrations.0081_status_has_metrics.Migration
class Migration(migrations.Migration): dependencies = [ ('core', '0080_auto_20180810_0047'), ] operations = [ migrations.AddField( model_name='status', name='has_metrics', field=models.BooleanField(default=False), ), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
13
2
11
3
10
0
3
3
2
0
1
0
0
145,667
Linaro/squad
Linaro_squad/squad/core/migrations/0071_migrate_old_tokens.py
squad.core.migrations.0071_migrate_old_tokens.Migration
class Migration(migrations.Migration): dependencies = [ ('core', '0070_create_suite_test_and_metric_metadata'), ] operations = [ migrations.RunPython(migrate_tokens) ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
9
2
7
3
6
0
3
3
2
0
1
0
0
145,668
Linaro/squad
Linaro_squad/squad/core/migrations/0070_create_suite_test_and_metric_metadata.py
squad.core.migrations.0070_create_suite_test_and_metric_metadata.Migration
class Migration(migrations.Migration): dependencies = [ ('core', '0069_suite_metadata'), ] operations = [ migrations.RunSQL(sql, reverse_sql=reverse_sql) for sql, reverse_sql in STEPS ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
10
2
8
3
7
0
3
3
2
0
1
0
0
145,669
Linaro/squad
Linaro_squad/squad/core/migrations/0069_suite_metadata.py
squad.core.migrations.0069_suite_metadata.Migration
class Migration(migrations.Migration): dependencies = [ ('core', '0068_suite_version'), ] operations = [ migrations.CreateModel( name='SuiteMetadata', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('suite', models.CharField(max_length=256)), ('kind', models.CharField(choices=[('suite', 'Suite'), ('test', 'Test'), ('metric', 'Metric')], max_length=6)), ('name', models.CharField(max_length=256, null=True)), ('description', models.TextField(blank=True, null=True)), ('instructions_to_reproduce', models.TextField(blank=True, null=True)), ], options={ 'verbose_name_plural': 'Suite metadata', }, ), migrations.AlterUniqueTogether( name='suitemetadata', unique_together=set([('kind', 'suite', 'name')]), ), migrations.AddField( model_name='metric', name='metadata', field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='+', to='core.SuiteMetadata'), ), migrations.AddField( model_name='suite', name='metadata', field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='+', to='core.SuiteMetadata'), ), migrations.AddField( model_name='test', name='metadata', field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='+', to='core.SuiteMetadata'), ), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
41
2
39
3
38
0
3
3
2
0
1
0
0
145,670
Linaro/squad
Linaro_squad/squad/core/migrations/0046_projectstatus_last_updated.py
squad.core.migrations.0046_projectstatus_last_updated.Migration
class Migration(migrations.Migration): dependencies = [ ('core', '0045_adminsubscription'), ] operations = [ migrations.AddField( model_name='projectstatus', name='last_updated', field=models.DateTimeField(null=True), ), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
13
2
11
3
10
0
3
3
2
0
1
0
0
145,671
Linaro/squad
Linaro_squad/squad/core/migrations/0047_populate_projectstatus_last_updated.py
squad.core.migrations.0047_populate_projectstatus_last_updated.Migration
class Migration(migrations.Migration): dependencies = [ ('core', '0046_projectstatus_last_updated'), ] operations = [ migrations.RunSQL( "UPDATE core_projectstatus SET last_updated = created_at", reverse_sql=migrations.RunSQL.noop, ), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
12
2
10
3
9
0
3
3
2
0
1
0
0
145,672
Linaro/squad
Linaro_squad/squad/core/migrations/0048_moderate_notifications.py
squad.core.migrations.0048_moderate_notifications.Migration
class Migration(migrations.Migration): dependencies = [ ('core', '0047_populate_projectstatus_last_updated'), ] operations = [ migrations.AddField( model_name='project', name='moderate_notifications', field=models.BooleanField(default=False), ), migrations.AddField( model_name='projectstatus', name='approved', field=models.BooleanField(default=False), ), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
18
2
16
3
15
0
3
3
2
0
1
0
0
145,673
Linaro/squad
Linaro_squad/squad/core/migrations/0049_projectstatus_plural.py
squad.core.migrations.0049_projectstatus_plural.Migration
class Migration(migrations.Migration): dependencies = [ ('core', '0048_moderate_notifications'), ] operations = [ migrations.AlterModelOptions( name='projectstatus', options={'verbose_name_plural': 'Project statuses'}, ), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
12
2
10
3
9
0
3
3
2
0
1
0
0
145,674
Linaro/squad
Linaro_squad/squad/core/migrations/0050_projectstatus_finished.py
squad.core.migrations.0050_projectstatus_finished.Migration
class Migration(migrations.Migration): dependencies = [ ('core', '0049_projectstatus_plural'), ] operations = [ migrations.AddField( model_name='projectstatus', name='finished', field=models.BooleanField(default=False), ), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
13
2
11
3
10
0
3
3
2
0
1
0
0
145,675
Linaro/squad
Linaro_squad/squad/core/migrations/0051_build_status.py
squad.core.migrations.0051_build_status.Migration
class Migration(migrations.Migration): dependencies = [ ('core', '0050_projectstatus_finished'), ] operations = [ migrations.AlterField( model_name='projectstatus', name='build', field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='status', to='core.Build'), ), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
13
2
11
3
10
0
3
3
2
0
1
0
0
145,676
Linaro/squad
Linaro_squad/squad/core/migrations/0052_recreate_projectstatus_data.py
squad.core.migrations.0052_recreate_projectstatus_data.Migration
class Migration(migrations.Migration): dependencies = [ ('core', '0051_build_status'), ] operations = [ migrations.RunPython( create_or_update_projectstatus, reverse_code=migrations.RunPython.noop, ), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
12
2
10
3
9
0
3
3
2
0
1
0
0
145,677
Linaro/squad
Linaro_squad/squad/core/migrations/0053_remove_projectstatus_previous.py
squad.core.migrations.0053_remove_projectstatus_previous.Migration
class Migration(migrations.Migration): dependencies = [ ('core', '0052_recreate_projectstatus_data'), ] operations = [ migrations.RemoveField( model_name='projectstatus', name='previous', ), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
12
2
10
3
9
0
3
3
2
0
1
0
0
145,678
Linaro/squad
Linaro_squad/squad/core/migrations/0054_custom_email_template.py
squad.core.migrations.0054_custom_email_template.Migration
class Migration(migrations.Migration): dependencies = [ ('core', '0053_remove_projectstatus_previous'), ] operations = [ migrations.CreateModel( name='EmailTemplate', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('name', models.CharField(max_length=100, unique=True)), ('plain_text', models.TextField(help_text='Jinja2 template for text/plain content')), ('html', models.TextField(blank=True, help_text='Jinja2 template for text/html content', null=True)), ], ), migrations.AddField( model_name='project', name='custom_email_template', field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='core.EmailTemplate'), ), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
22
2
20
3
19
0
3
3
2
0
1
0
0
145,679
Linaro/squad
Linaro_squad/squad/core/migrations/0055_emailtemplate_subject.py
squad.core.migrations.0055_emailtemplate_subject.Migration
class Migration(migrations.Migration): dependencies = [ ('core', '0054_custom_email_template'), ] operations = [ migrations.AddField( model_name='emailtemplate', name='subject', field=models.CharField(blank=True, help_text='Jinja2 template for subject (single line)', max_length=1024, null=True), ), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
13
2
11
3
10
0
3
3
2
0
1
0
0
145,680
Linaro/squad
Linaro_squad/squad/core/migrations/0056_project_description.py
squad.core.migrations.0056_project_description.Migration
class Migration(migrations.Migration): dependencies = [ ('core', '0055_emailtemplate_subject'), ] operations = [ migrations.AddField( model_name='project', name='description', field=models.TextField(blank=True, null=True), ), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
13
2
11
3
10
0
3
3
2
0
1
0
0
145,681
Linaro/squad
Linaro_squad/squad/core/migrations/0057_projectstatus_has_metrics.py
squad.core.migrations.0057_projectstatus_has_metrics.Migration
class Migration(migrations.Migration): dependencies = [ ('core', '0056_project_description'), ] operations = [ migrations.AddField( model_name='projectstatus', name='has_metrics', field=models.BooleanField(default=False), ), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
13
2
11
3
10
0
3
3
2
0
1
0
0
145,682
Linaro/squad
Linaro_squad/squad/core/migrations/0058_populate_projectstatus_has_metrics.py
squad.core.migrations.0058_populate_projectstatus_has_metrics.Migration
class Migration(migrations.Migration): dependencies = [ ('core', '0057_projectstatus_has_metrics'), ] operations = [ migrations.RunSQL( SQL, reverse_sql=migrations.RunSQL.noop, ), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
12
2
10
3
9
0
3
3
2
0
1
0
0
145,683
Linaro/squad
Linaro_squad/squad/core/migrations/0059_project_important_metadata_keys.py
squad.core.migrations.0059_project_important_metadata_keys.Migration
class Migration(migrations.Migration): dependencies = [ ('core', '0058_populate_projectstatus_has_metrics'), ] operations = [ migrations.AddField( model_name='project', name='important_metadata_keys', field=models.TextField(blank=True, null=True), ), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
13
2
11
3
10
0
3
3
2
0
1
0
0
145,684
Linaro/squad
Linaro_squad/squad/core/migrations/0060_test_log.py
squad.core.migrations.0060_test_log.Migration
class Migration(migrations.Migration): dependencies = [ ('core', '0059_project_important_metadata_keys'), ] operations = [ migrations.AddField( model_name='test', name='log', field=models.TextField(blank=True, null=True), ), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
13
2
11
3
10
0
3
3
2
0
1
0
0
145,685
Linaro/squad
Linaro_squad/squad/core/migrations/0061_project_enabled_plugins_list.py
squad.core.migrations.0061_project_enabled_plugins_list.Migration
class Migration(migrations.Migration): dependencies = [ ('core', '0060_test_log'), ] operations = [ migrations.AddField( model_name='project', name='enabled_plugins_list', field=models.TextField(default='', help_text='One per line. Non-existing plugins are ignored.', validators=[django.core.validators.RegexValidator(regex='^$|^[a-zA-Z0-9][a-zA-Z0-9_.-]*(\\s+[a-zA-Z0-9][a-zA-Z0-9_.-]*)*$')]), ), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
13
2
11
3
10
0
3
3
2
0
1
0
0
145,686
Linaro/squad
Linaro_squad/squad/core/migrations/0062_project_allow_empty_enabled_plugin_list.py
squad.core.migrations.0062_project_allow_empty_enabled_plugin_list.Migration
class Migration(migrations.Migration): dependencies = [ ('core', '0061_project_enabled_plugins_list'), ] operations = [ migrations.AlterField( model_name='project', name='enabled_plugins_list', field=models.TextField(blank=True, default='', help_text='One per line. Non-existing plugins are ignored.', validators=[django.core.validators.RegexValidator(regex='^$|^[a-zA-Z0-9][a-zA-Z0-9_.-]*(\\s+[a-zA-Z0-9][a-zA-Z0-9_.-]*)*$')]), ), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
13
2
11
3
10
0
3
3
2
0
1
0
0
145,687
Linaro/squad
Linaro_squad/squad/core/migrations/0063_project_wait_before_notification.py
squad.core.migrations.0063_project_wait_before_notification.Migration
class Migration(migrations.Migration): dependencies = [ ('core', '0062_project_allow_empty_enabled_plugin_list'), ] operations = [ migrations.AddField( model_name='project', name='wait_before_notification', field=models.IntegerField(help_text='Wait this many seconds before sending notifications', null=True), ), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
13
2
11
3
10
0
3
3
2
0
1
0
0
145,688
Linaro/squad
Linaro_squad/squad/core/migrations/0064_project_notification_timeout.py
squad.core.migrations.0064_project_notification_timeout.Migration
class Migration(migrations.Migration): dependencies = [ ('core', '0063_project_wait_before_notification'), ] operations = [ migrations.AddField( model_name='project', name='notification_timeout', field=models.IntegerField(help_text='Force sending build notifications after this many seconds', null=True), ), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
13
2
11
3
10
0
3
3
2
0
1
0
0
145,689
Linaro/squad
Linaro_squad/squad/core/migrations/0065_projectstatus_notified_on_timeout.py
squad.core.migrations.0065_projectstatus_notified_on_timeout.Migration
class Migration(migrations.Migration): dependencies = [ ('core', '0064_project_notification_timeout'), ] operations = [ migrations.AddField( model_name='projectstatus', name='notified_on_timeout', field=models.BooleanField(default=False), ), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
13
2
11
3
10
0
3
3
2
0
1
0
0
145,690
Linaro/squad
Linaro_squad/squad/core/migrations/0066_environment_description.py
squad.core.migrations.0066_environment_description.Migration
class Migration(migrations.Migration): dependencies = [ ('core', '0065_projectstatus_notified_on_timeout'), ] operations = [ migrations.AddField( model_name='environment', name='description', field=models.TextField(blank=True, null=True), ), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
13
2
11
3
10
0
3
3
2
0
1
0
0
145,691
Linaro/squad
Linaro_squad/squad/core/migrations/0067_accept_blank_suite_name.py
squad.core.migrations.0067_accept_blank_suite_name.Migration
class Migration(migrations.Migration): dependencies = [ ('core', '0066_environment_description'), ] operations = [ migrations.AlterField( model_name='suite', name='name', field=models.CharField(blank=True, max_length=256, null=True), ), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
13
2
11
3
10
0
3
3
2
0
1
0
0
145,692
Linaro/squad
Linaro_squad/squad/core/migrations/0068_suite_version.py
squad.core.migrations.0068_suite_version.Migration
class Migration(migrations.Migration): dependencies = [ ('core', '0067_accept_blank_suite_name'), ] operations = [ migrations.CreateModel( name='SuiteVersion', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('version', models.CharField(max_length=40, null=True)), ('first_seen', models.DateTimeField(auto_now_add=True)), ('suite', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='versions', to='core.Suite')), ], ), migrations.AlterUniqueTogether( name='suiteversion', unique_together=set([('suite', 'version')]), ), migrations.AddField( model_name='status', name='suite_version', field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='core.SuiteVersion'), ), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
26
2
24
3
23
0
3
3
2
0
1
0
0
145,693
Linaro/squad
Linaro_squad/squad/core/migrations/0003_testrun_log_file.py
squad.core.migrations.0003_testrun_log_file.Migration
class Migration(migrations.Migration): dependencies = [ ('core', '0002_auto_20160525_1403'), ] operations = [ migrations.AddField( model_name='testrun', name='log_file', field=models.TextField(null=True), ), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
13
2
11
3
10
0
3
3
2
0
1
0
0
145,694
Linaro/squad
Linaro_squad/squad/core/migrations/0002_auto_20160525_1403.py
squad.core.migrations.0002_auto_20160525_1403.Migration
class Migration(migrations.Migration): dependencies = [ ('core', '0001_initial'), ] operations = [ migrations.AddField( model_name='testrun', name='metrics_file', field=models.TextField(null=True), ), migrations.AddField( model_name='testrun', name='tests_file', field=models.TextField(null=True), ), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
18
2
16
3
15
0
3
3
2
0
1
0
0
145,695
Linaro/squad
Linaro_squad/squad/core/migrations/0001_initial.py
squad.core.migrations.0001_initial.Migration
class Migration(migrations.Migration): initial = True dependencies = [ ] operations = [ migrations.CreateModel( name='Metric', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('result', models.FloatField()), ('measurements', models.TextField()), ], ), migrations.CreateModel( name='Build', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('version', models.CharField(max_length=100)), ('created_at', models.DateTimeField(auto_now_add=True)), ], ), migrations.CreateModel( name='Environment', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('slug', models.CharField(max_length=100)), ('name', models.CharField(max_length=100, null=True)), ], ), migrations.CreateModel( name='Group', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('slug', models.CharField(max_length=100, unique=True)), ('name', models.CharField(max_length=100, null=True)), ], ), migrations.CreateModel( name='Project', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('slug', models.CharField(max_length=100)), ('name', models.CharField(max_length=100, null=True)), ('group', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='projects', to='core.Group')), ], ), migrations.CreateModel( name='Suite', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('slug', models.CharField(max_length=100)), ('name', models.CharField(max_length=100, null=True)), ('project', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='suites', to='core.Project')), ], ), migrations.CreateModel( name='Test', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('result', models.BooleanField()), ('suite', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.Suite')), ], ), migrations.CreateModel( name='TestRun', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('created_at', models.DateTimeField(auto_now_add=True)), ('build', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='test_runs', to='core.Build')), ('environment', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='test_runs', to='core.Environment')), ], ), migrations.AddField( model_name='test', name='test_run', field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='tests', to='core.TestRun'), ), migrations.AddField( model_name='environment', name='project', field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='environments', to='core.Project'), ), migrations.AddField( model_name='build', name='project', field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='builds', to='core.Project'), ), migrations.AddField( model_name='metric', name='suite', field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.Suite'), ), migrations.AddField( model_name='metric', name='test_run', field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='metrics', to='core.TestRun'), ), migrations.AlterUniqueTogether( name='suite', unique_together=set([('project', 'slug')]), ), migrations.AlterUniqueTogether( name='project', unique_together=set([('group', 'slug')]), ), migrations.AlterUniqueTogether( name='environment', unique_together=set([('project', 'slug')]), ), migrations.AlterUniqueTogether( name='build', unique_together=set([('project', 'version')]), ), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
117
3
114
4
113
0
4
4
3
0
1
0
0
145,696
Linaro/squad
Linaro_squad/squad/core/management/commands/users.py
squad.core.management.commands.users.Command
class Command(BaseCommand): help = "Manage users" def add_arguments(self, parser): cmd = self class SubParser(CommandParser): """ Sub-parsers constructor that mimic Django constructor. See http://stackoverflow.com/a/37414551 """ def __init__(self, **kwargs): kwargs.update( { "called_from_command_line": getattr( cmd, "_called_from_command_line", None ) } ) super().__init__(**kwargs) sub = parser.add_subparsers( dest="sub_command", help="Sub commands", parser_class=SubParser ) sub.required = True # "add" sub-command add_parser = sub.add_parser("add", help="Add a user") add_parser.add_argument("username", help="Username of the user") add_parser.add_argument( "--email", type=str, default=None, help="email of the user" ) add_parser.add_argument( "--passwd", type=str, default=None, help="Password for this user. If empty, a random password is generated.", ) add_parser.add_argument( "--staff", default=False, action="store_true", help="Make this user a staff member", ) add_parser.add_argument( "--superuser", default=False, action="store_true", help="Make this user a super user", ) # "update" sub-command update_parser = sub.add_parser("update", help="Update an existing user") update_parser.add_argument("username", help="Username of the user") update_parser.add_argument( "--email", type=str, default=None, help="Change email of the user" ) active_parser = update_parser.add_mutually_exclusive_group(required=False) active_parser.add_argument( "--active", dest="active", action="store_const", const=True, # not a boolean help="Make this user active", ) active_parser.add_argument( "--not-active", dest="active", action="store_const", const=False, help="Make this user inactive", ) active_parser.set_defaults(active=None) # tri-state - None, True, False staff_parser = update_parser.add_mutually_exclusive_group(required=False) staff_parser.add_argument( "--staff", dest="staff", action="store_const", const=True, help="Make this user a staff member", ) staff_parser.add_argument( "--not-staff", dest="staff", action="store_const", const=False, help="Make this user no longer a staff member", ) staff_parser.set_defaults(staff=None) superuser_parser = update_parser.add_mutually_exclusive_group(required=False) superuser_parser.add_argument( "--superuser", dest="superuser", action="store_const", const=True, help="Make this user a superuser", ) superuser_parser.add_argument( "--not-superuser", dest="superuser", action="store_const", const=False, help="Make this user no longer a superuser", ) superuser_parser.set_defaults(superuser=None) # "details" sub-command details_parser = sub.add_parser("details", help="User details") details_parser.add_argument("username", help="Username of the user") # "list" sub-command list_parser = sub.add_parser("list", help="List users") list_parser.add_argument( "--all", dest="all", default=False, action="store_true", help="Show all users including inactive ones", ) list_parser.add_argument( "--csv", dest="csv", default=False, action="store_true", help="Print as csv" ) token_parser = sub.add_parser("set-token", help="Set API token") token_parser.add_argument("username", help="Username for setting the token") token_parser.add_argument("token", help="Token string") def handle(self, *args, **options): """ Forward to the right sub-handler """ if options["sub_command"] == "add": self.handle_add(options) elif options["sub_command"] == "update": self.handle_update(options) elif options["sub_command"] == "details": self.handle_details(options["username"]) elif options["sub_command"] == "list": self.handle_list(options["all"], options["csv"]) elif options["sub_command"] == "set-token": self.handle_token(options["username"], options['token']) def handle_token(self, username, token): try: user = User.objects.get(username=username) except User.DoesNotExist: raise CommandError("User %s does not exist" % username) if token is None: raise CommandError("Token is required") Token.objects.filter(user=user).delete() Token.objects.create(user=user, key=token[0:40]) def handle_add(self, options): """ Create a new user """ username = options["username"] passwd = options["passwd"] if passwd is None: passwd = User.objects.make_random_password() user = User.objects.create_user(username, options["email"], passwd) if options["staff"]: user.is_staff = True if options["superuser"]: user.is_superuser = True user.save() if options["passwd"] is None: self.stdout.write(passwd) def handle_update(self, options): # pylint: disable=no-self-use """ Update existing user""" username = options["username"] try: user = User.objects.get(username=username) except User.DoesNotExist: raise CommandError("User %s does not exist" % username) if options["email"]: user.email = options["email"] # False is an allowed value, but not None. if options["active"] in [True, False]: user.is_active = options["active"] if options["staff"] in [True, False]: user.is_staff = options["staff"] if options["superuser"] in [True, False]: user.is_superuser = options["superuser"] user.save() def handle_details(self, username): """ Print user details """ try: user = User.objects.get(username=username) except User.DoesNotExist: raise CommandError("Unable to find user '%s'" % username) self.stdout.write("username : %s" % username) self.stdout.write("is_active : %s" % user.is_active) self.stdout.write("is_staff : %s" % user.is_staff) self.stdout.write("is_superuser: %s" % user.is_superuser) groups = [g.name for g in user.groups.all().order_by("name")] self.stdout.write("groups : [%s]" % ", ".join(groups)) def handle_list(self, show_all, format_as_csv): """ List users """ users = User.objects.all().order_by("username") if not show_all: users = users.exclude(is_active=False) if format_as_csv: fields = ["username", "fullname", "email", "staff", "superuser"] writer = csv.DictWriter(self.stdout, fieldnames=fields) writer.writeheader() for user in users: writer.writerow( { "username": user.username, "email": user.email, "staff": user.is_staff, "superuser": user.is_superuser, } ) else: self.stdout.write("List of users:") for user in users: out = "* %s" % user.username if user.get_full_name(): out = "%s (%s)" % (out, user.get_full_name()) if not user.is_active: out = "%s [inactive]" % out self.stdout.write(out)
class Command(BaseCommand): def add_arguments(self, parser): pass class SubParser(CommandParser): ''' Sub-parsers constructor that mimic Django constructor. See http://stackoverflow.com/a/37414551 ''' def __init__(self, **kwargs): pass def handle(self, *args, **options): ''' Forward to the right sub-handler ''' pass def handle_token(self, username, token): pass def handle_add(self, options): ''' Create a new user ''' pass def handle_update(self, options): ''' Update existing user''' pass def handle_details(self, username): ''' Print user details ''' pass def handle_list(self, show_all, format_as_csv): ''' List users ''' pass
10
6
30
3
25
2
4
0.09
1
3
1
0
7
1
7
7
236
27
195
34
185
17
112
34
102
7
1
3
31
145,697
Linaro/squad
Linaro_squad/squad/core/callback.py
squad.core.callback.callback_events
class callback_events: ON_BUILD_FINISHED = 'on_build_finished' @classmethod def all(cls): return [cls.ON_BUILD_FINISHED] @classmethod def validator(cls, value): return __generic_callback_validator__(value, 'event', cls.all())
class callback_events: @classmethod def all(cls): pass @classmethod def validator(cls, value): pass
5
0
2
0
2
0
1
0
0
0
0
0
0
0
2
2
10
2
8
6
3
0
6
4
3
1
0
0
2
145,698
Linaro/squad
Linaro_squad/squad/ci/migrations/0023_remove_testjob_build.py
squad.ci.migrations.0023_remove_testjob_build.Migration
class Migration(migrations.Migration): dependencies = [ ('ci', '0022_backend_poll_enabled'), ] operations = [ migrations.RemoveField( model_name='testjob', name='build', ), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
12
2
10
3
9
0
3
3
2
0
1
0
0
145,699
Linaro/squad
Linaro_squad/squad/core/callback.py
squad.core.callback.callback_methods
class callback_methods: GET = 'get' POST = 'post' @classmethod def all(cls): return [cls.GET, cls.POST] @classmethod def validator(cls, value): return __generic_callback_validator__(value, 'method', cls.all())
class callback_methods: @classmethod def all(cls): pass @classmethod def validator(cls, value): pass
5
0
2
0
2
0
1
0
0
0
0
0
0
0
2
2
11
2
9
7
4
0
7
5
4
1
0
0
2
145,700
Linaro/squad
Linaro_squad/squad/core/comparison.py
squad.core.comparison.MetricComparison
class MetricComparison(BaseComparison): __builds_dict__ = None def __init__(self, *builds, regressions_and_fixes_only=False): self.regressions_and_fixes_only = regressions_and_fixes_only self.__regressions__ = None self.__fixes__ = None BaseComparison.__init__(self, *builds) def __extract_regressions_and_fixes__(self): """ The target build should be the most recent once and the baseline an older build. If a metric in the target build has a match in the base line build and if their results are different it's considered to be a regression. +-----------------------------------------------------------+ | metric.result == target.result - baseline.result | | -> metric.result > 0 : target.result > baseline.result | | -> metric.result < 0 : target.result < baseline.result | | -> metric.result = 0 : won't be returned from the query | +-----------------------------------------------------------+ """ if self.builds[0] is None: # No baseline is present, then no comparison is needed return target = self.builds[1] query = self.base_sql.copy() query['select'].append('target.result - baseline.result AS result') query['from'].append('core_metric baseline') query['from'].append('core_metric target') sql = self.__render_sql__(query) metrics = [m for m in models.Metric.objects.raw(sql)] prefetch_related_objects(metrics, 'metadata', 'suite') env_ids = set() metrics_per_env = defaultdict(list) regressions = defaultdict(list) fixes = defaultdict(list) regs_and_fixes = { True: { True: fixes, False: regressions, }, False: { True: regressions, False: fixes, }, } for metric in metrics: env_id = metric.environment_id env_ids.add(env_id) metrics_per_env[env_id].append(metric) thresholds = models.MetricThreshold.objects.filter(project=target.project, value__isnull=True) for threshold in thresholds: threshold_envs = threshold.project.environments.all() if threshold.environment is None else [threshold.environment] for env in threshold_envs: if env.id not in metrics_per_env: continue for metric in metrics_per_env[env.id]: if not threshold.match(metric.full_name): continue regs_and_fixes[threshold.is_higher_better][metric.result > 0][env.slug].append(metric.full_name) self.__regressions__ = OrderedDict() for env in regressions.keys(): self.__regressions__[env] = regressions[env] self.__fixes__ = OrderedDict() for env in fixes.keys(): self.__fixes__[env] = fixes[env] @property def regressions(self): return self.__regressions__ @property def fixes(self): return self.__fixes__ def __get_build__(self, build_id): if self.__builds_dict__ is None: self.__builds_dict__ = {b.id: b for b in self.builds} return self.__builds_dict__[build_id] def __extract_stats__(self, query): stats = [] for environment_slug, builds in groupby(query, lambda x: x['environment__slug']): for build_id, suites in groupby(builds, lambda x: x['build_id']): for suite_slug, metrics in groupby(suites, lambda x: x['suite__slug']): for metric_name, measurements in groupby(metrics, lambda x: x['metadata__name']): values = [] for m in measurements: values += [float(v) for v in m['measurements'].split(',')] stat = { 'environment_slug': environment_slug, 'build_id': build_id, 'full_name': join_name(suite_slug, metric_name), 'mean': statistics.mean(values), 'stddev': statistics.pstdev(values), 'count': len(values) } stats.append(stat) return stats def __extract_results__(self): if self.regressions_and_fixes_only: self.__extract_regressions_and_fixes__() return metrics = models.Metric.objects.filter( build__in=self.builds, is_outlier=False ).values( 'environment__slug', 'build_id', 'suite__slug', 'metadata__name', 'measurements' ).order_by( 'environment__slug', 'build_id', 'suite__slug', 'metadata__name' ) results = self.__extract_stats__(metrics) for result in results: environment = result['environment_slug'] build = self.__get_build__(result['build_id']) full_name = result['full_name'] mean = result['mean'] stddev = result['stddev'] count = result['count'] self.all_environments.add(environment) self.environments[build].add(environment) key = (build, environment) if full_name not in self.results: self.results[full_name] = OrderedDict() self.results[full_name][key] = (mean, stddev, count) self.results = OrderedDict(sorted(self.results.items())) for build in self.builds: self.environments[build] = sorted(self.environments[build])
class MetricComparison(BaseComparison): def __init__(self, *builds, regressions_and_fixes_only=False): pass def __extract_regressions_and_fixes__(self): ''' The target build should be the most recent once and the baseline an older build. If a metric in the target build has a match in the base line build and if their results are different it's considered to be a regression. +-----------------------------------------------------------+ | metric.result == target.result - baseline.result | | -> metric.result > 0 : target.result > baseline.result | | -> metric.result < 0 : target.result < baseline.result | | -> metric.result = 0 : won't be returned from the query | +-----------------------------------------------------------+ ''' pass @property def regressions(self): pass @property def fixes(self): pass def __get_build__(self, build_id): pass def __extract_stats__(self, query): pass def __extract_results__(self): pass
10
1
20
2
16
2
4
0.11
1
7
2
0
7
5
7
17
155
25
117
49
107
13
85
46
77
11
2
5
27
145,701
Linaro/squad
Linaro_squad/squad/ci/migrations/0022_backend_poll_enabled.py
squad.ci.migrations.0022_backend_poll_enabled.Migration
class Migration(migrations.Migration): dependencies = [ ('ci', '0021_testjob_parent_job'), ] operations = [ migrations.AddField( model_name='backend', name='poll_enabled', field=models.BooleanField(default=True), ), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
13
2
11
3
10
0
3
3
2
0
1
0
0
145,702
Linaro/squad
Linaro_squad/squad/ci/migrations/0021_testjob_parent_job.py
squad.ci.migrations.0021_testjob_parent_job.Migration
class Migration(migrations.Migration): dependencies = [ ('ci', '0020_backend_settings_field'), ] operations = [ migrations.AddField( model_name='testjob', name='parent_job', field=models.ForeignKey(blank=True, default=None, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='resubmitted_jobs', to='ci.TestJob'), ), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
13
2
11
3
10
0
3
3
2
0
1
0
0
145,703
Linaro/squad
Linaro_squad/squad/ci/migrations/0020_backend_settings_field.py
squad.ci.migrations.0020_backend_settings_field.Migration
class Migration(migrations.Migration): dependencies = [ ('ci', '0019_add_fake_backend'), ] operations = [ migrations.AddField( model_name='backend', name='backend_settings', field=models.TextField(blank=True, null=True, validators=[squad.ci.models.yaml_validator]), ), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
13
2
11
3
10
0
3
3
2
0
1
0
0
145,704
Linaro/squad
Linaro_squad/squad/ci/migrations/0019_add_fake_backend.py
squad.ci.migrations.0019_add_fake_backend.Migration
class Migration(migrations.Migration): dependencies = [ ('ci', '0018_testjob_dates'), ] operations = [ migrations.AlterField( model_name='backend', name='implementation_type', field=models.CharField(choices=[('fake', 'fake'), ('lava', 'lava'), ('null', 'null')], default='null', max_length=64), ), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
13
2
11
3
10
0
3
3
2
0
1
0
0
145,705
Linaro/squad
Linaro_squad/squad/ci/migrations/0018_testjob_dates.py
squad.ci.migrations.0018_testjob_dates.Migration
class Migration(migrations.Migration): dependencies = [ ('ci', '0017_testjob_fetch_attempts'), ] operations = [ migrations.AddField( model_name='testjob', name='created_at', field=models.DateTimeField(auto_now_add=True, null=True), ), migrations.AddField( model_name='testjob', name='fetched_at', field=models.DateTimeField(null=True), ), migrations.AddField( model_name='testjob', name='submitted_at', field=models.DateTimeField(null=True), ), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
23
2
21
3
20
0
3
3
2
0
1
0
0
145,706
Linaro/squad
Linaro_squad/squad/ci/migrations/0017_testjob_fetch_attempts.py
squad.ci.migrations.0017_testjob_fetch_attempts.Migration
class Migration(migrations.Migration): dependencies = [ ('ci', '0016_backend_max_fetch_attempts'), ] operations = [ migrations.AddField( model_name='testjob', name='fetch_attempts', field=models.IntegerField(default=0), ), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
13
2
11
3
10
0
3
3
2
0
1
0
0
145,707
Linaro/squad
Linaro_squad/squad/core/apps.py
squad.core.apps.CoreConfig
class CoreConfig(AppConfig): default_auto_field = 'django.db.models.AutoField' name = 'squad.core'
class CoreConfig(AppConfig): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
3
0
3
3
2
0
3
3
2
0
1
0
0
145,708
Linaro/squad
Linaro_squad/squad/ci/migrations/0016_backend_max_fetch_attempts.py
squad.ci.migrations.0016_backend_max_fetch_attempts.Migration
class Migration(migrations.Migration): dependencies = [ ('ci', '0015_testjob_populate_target_build'), ] operations = [ migrations.AddField( model_name='backend', name='max_fetch_attempts', field=models.IntegerField(default=3), ), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
13
2
11
3
10
0
3
3
2
0
1
0
0
145,709
Linaro/squad
Linaro_squad/squad/ci/migrations/0014_testjob_target_build.py
squad.ci.migrations.0014_testjob_target_build.Migration
class Migration(migrations.Migration): dependencies = [ ('core', '0061_project_enabled_plugins_list'), ('ci', '0013_testjob_name'), ] operations = [ migrations.AddField( model_name='testjob', name='target_build', field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='test_jobs', to='core.Build'), ), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
14
2
12
3
11
0
3
3
2
0
1
0
0
145,710
Linaro/squad
Linaro_squad/squad/ci/migrations/0013_testjob_name.py
squad.ci.migrations.0013_testjob_name.Migration
class Migration(migrations.Migration): dependencies = [ ('ci', '0012_testjob_build'), ] operations = [ migrations.AddField( model_name='testjob', name='name', field=models.CharField(blank=True, max_length=256, null=True), ), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
13
2
11
3
10
0
3
3
2
0
1
0
0
145,711
Linaro/squad
Linaro_squad/squad/ci/migrations/0012_testjob_build.py
squad.ci.migrations.0012_testjob_build.Migration
class Migration(migrations.Migration): dependencies = [ ('ci', '0011_testjob_resubmitted_count'), ] operations = [ migrations.AlterField( model_name='testjob', name='build', field=models.CharField(max_length=100), ), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
13
2
11
3
10
0
3
3
2
0
1
0
0
145,712
Linaro/squad
Linaro_squad/squad/ci/migrations/0011_testjob_resubmitted_count.py
squad.ci.migrations.0011_testjob_resubmitted_count.Migration
class Migration(migrations.Migration): dependencies = [ ('ci', '0010_testjob_can_resubmit'), ] operations = [ migrations.AddField( model_name='testjob', name='resubmitted_count', field=models.IntegerField(default=0), ), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
13
2
11
3
10
0
3
3
2
0
1
0
0
145,713
Linaro/squad
Linaro_squad/squad/ci/migrations/0010_testjob_can_resubmit.py
squad.ci.migrations.0010_testjob_can_resubmit.Migration
class Migration(migrations.Migration): dependencies = [ ('ci', '0009_slug_pattern'), ] operations = [ migrations.AddField( model_name='testjob', name='can_resubmit', field=models.BooleanField(default=False), ), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
13
2
11
3
10
0
3
3
2
0
1
0
0
145,714
Linaro/squad
Linaro_squad/squad/ci/migrations/0009_slug_pattern.py
squad.ci.migrations.0009_slug_pattern.Migration
class Migration(migrations.Migration): dependencies = [ ('ci', '0008_testjob_testrun'), ] operations = [ migrations.AlterField( model_name='testjob', name='environment', field=models.CharField(max_length=100, validators=[django.core.validators.RegexValidator(regex='^[a-zA-Z0-9][a-zA-Z0-9_.-]*')]), ), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
13
2
11
3
10
0
3
3
2
0
1
0
0
145,715
Linaro/squad
Linaro_squad/squad/ci/migrations/0008_testjob_testrun.py
squad.ci.migrations.0008_testjob_testrun.Migration
class Migration(migrations.Migration): dependencies = [ ('core', '0025_unique_testrun_job_id'), ('ci', '0007_auto_20170517_1736'), ] operations = [ migrations.AddField( model_name='testjob', name='testrun', field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='test_jobs', to='core.TestRun'), ), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
14
2
12
3
11
0
3
3
2
0
1
0
0
145,716
Linaro/squad
Linaro_squad/squad/ci/migrations/0007_auto_20170517_1736.py
squad.ci.migrations.0007_auto_20170517_1736.Migration
class Migration(migrations.Migration): dependencies = [ ('ci', '0006_simplify_backend_loading'), ] operations = [ migrations.AlterField( model_name='testjob', name='definition', field=models.TextField(blank=True, null=True), ), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
13
2
11
3
10
0
3
3
2
0
1
0
0
145,717
Linaro/squad
Linaro_squad/squad/ci/migrations/0006_simplify_backend_loading.py
squad.ci.migrations.0006_simplify_backend_loading.Migration
class Migration(migrations.Migration): dependencies = [ ('ci', '0005_remove_listener_data'), ] operations = [ migrations.AlterField( model_name='backend', name='implementation_type', field=models.CharField(choices=[('lava', 'lava'), ('null', 'null')], default='null', max_length=64), ), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
13
2
11
3
10
0
3
3
2
0
1
0
0
145,718
Linaro/squad
Linaro_squad/squad/ci/migrations/0005_remove_listener_data.py
squad.ci.migrations.0005_remove_listener_data.Migration
class Migration(migrations.Migration): dependencies = [ ('ci', '0004_testjob_failure'), ] operations = [ migrations.RemoveField( model_name='backend', name='listener_filter', ), migrations.RemoveField( model_name='backend', name='listener_url', ), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
16
2
14
3
13
0
3
3
2
0
1
0
0
145,719
Linaro/squad
Linaro_squad/squad/ci/migrations/0015_testjob_populate_target_build.py
squad.ci.migrations.0015_testjob_populate_target_build.Migration
class Migration(migrations.Migration): dependencies = [ ('ci', '0014_testjob_target_build'), ] if POSTGRESQL: # Only PostgreSQL is supported. SQLite does not support "UPDATE FROM" # so a similar UPDATE query would take ages operations = [ migrations.RunSQL(SQL, reverse_sql=REVERSE_SQL), ] else: operations = []
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0.2
1
0
0
0
0
0
0
0
14
2
10
3
9
2
5
3
4
0
1
1
0
145,720
Linaro/squad
Linaro_squad/squad/core/admin.py
squad.core.admin.TestRunProjectFilter
class TestRunProjectFilter(admin.SimpleListFilter): title = "Project" parameter_name = "project" def lookups(self, request, model_admin): ret_list = () for project in models.Project.objects.all(): ret_list = ret_list + ((project.id, "%s/%s" % (project.group.slug, project.slug)),) return ret_list def queryset(self, request, queryset): if self.value(): return queryset.filter(build__project=self.value()) return queryset
class TestRunProjectFilter(admin.SimpleListFilter): def lookups(self, request, model_admin): pass def queryset(self, request, queryset): pass
3
0
5
0
5
0
2
0
1
1
1
0
2
0
2
2
14
2
12
7
9
0
12
7
9
2
1
1
4
145,721
Linaro/squad
Linaro_squad/squad/core/admin.py
squad.core.admin.TestRunAdmin
class TestRunAdmin(NoDeleteListingModelAdmin): models = models.TestRun list_filter = [TestRunProjectFilter] actions = [force_execute_plugins] def has_add_permission(self, request): return False
class TestRunAdmin(NoDeleteListingModelAdmin): def has_add_permission(self, request): pass
2
0
2
0
2
0
1
0
1
0
0
0
1
0
1
2
7
1
6
5
4
0
6
5
4
1
2
0
1
145,722
Linaro/squad
Linaro_squad/squad/core/admin.py
squad.core.admin.SuiteMetadataAdmin
class SuiteMetadataAdmin(admin.ModelAdmin): models = models.SuiteMetadata ordering = ['name'] list_display = ['__str__', 'kind', 'description'] list_filter = ['kind', 'suite'] readonly_fields = ['kind', 'suite', 'name']
class SuiteMetadataAdmin(admin.ModelAdmin): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
6
0
6
6
5
0
6
6
5
0
1
0
0
145,723
Linaro/squad
Linaro_squad/squad/ci/models.py
squad.ci.models.TestJobManager
class TestJobManager(models.Manager): def pending(self): return self.filter(Q(fetched=False) | Q(job_status='Fetching'))
class TestJobManager(models.Manager): def pending(self): pass
2
0
2
0
2
0
1
0
1
0
0
0
1
0
1
1
4
1
3
2
1
0
3
2
1
1
1
0
1
145,724
Linaro/squad
Linaro_squad/squad/ci/models.py
squad.ci.models.TestJob
class TestJob(models.Model): __test__ = False objects = TestJobManager() # input - internal backend = models.ForeignKey(Backend, related_name='test_jobs', on_delete=models.CASCADE) # TestRun object once it's created testrun = models.ForeignKey(TestRun, related_name='test_jobs', null=True, blank=True, on_delete=models.CASCADE) # definition can only be empty if the job already exists # in the executor. definition = models.TextField(null=True, blank=True) # name field is optional. In case of LAVA it's extrated from # test job definition name = models.CharField(max_length=256, null=True, blank=True) # input - for TestRun later target = models.ForeignKey(Project, on_delete=models.CASCADE) target_build = models.ForeignKey(Build, related_name='test_jobs', null=True, blank=True, on_delete=models.CASCADE) environment = models.CharField(max_length=100, validators=[slug_validator]) # dates created_at = models.DateTimeField(auto_now_add=True, null=True) submitted_at = models.DateTimeField(null=True) fetched_at = models.DateTimeField(null=True) started_at = models.DateTimeField(null=True) ended_at = models.DateTimeField(null=True) # control submitted = models.BooleanField(default=False) fetched = models.BooleanField(default=False) fetch_attempts = models.IntegerField(default=0) last_fetch_attempt = models.DateTimeField(null=True, default=None, blank=True) failure = models.TextField(null=True, blank=True) can_resubmit = models.BooleanField(default=False) # this field should be set to "previous job + 1" whenever # resubmitting resubmitted_count = models.IntegerField(default=0) # reference to the job that was used as base for resubmission parent_job = models.ForeignKey('self', default=None, blank=True, null=True, related_name="resubmitted_jobs", on_delete=models.CASCADE) # number of subtasks postprocessing this job subtasks_count = models.IntegerField(default=0) @property def show_definition(self): try: # we'll loose comments in web UI yaml_def = yaml.safe_load(self.definition) except (yaml.parser.ParserError, yaml.scanner.ScannerError): # in case yaml is not valid, return original string return self.definition if not isinstance(yaml_def, dict): return yaml_def if 'secrets' in yaml_def.keys(): # prevent displaying 'secrets' in the web UI for key, value in yaml_def['secrets'].items(): yaml_def['secrets'][key] = "****" stream = StringIO() yaml.dump(yaml_def, stream, default_flow_style=False, allow_unicode=True, encoding=None) return stream.getvalue() def success(self): return not self.failure success.boolean = True # output job_id = models.CharField(null=True, max_length=128, blank=True, db_index=True) job_status = models.CharField(null=True, max_length=128, blank=True) @property def url(self): if self.job_id is not None: return self.backend.get_implementation().job_url(self) return None @property def input(self): try: return self.results_input.text except ResultsInput.DoesNotExist: return None @input.setter def input(self, value): if value: self.results_input = ResultsInput(text=value) self.results_input.save() else: self.results_input.delete() def resubmit(self): ret_value = False if self.can_resubmit: ret_value = self.force_resubmit() if self.can_resubmit: # in case the backend doesn't set the can_resubmit=False # or the resubmit call comes from api self.can_resubmit = False self.save() return ret_value def reset_build_events(self): # Retrigger build-finished events if self.target_build is not None \ and self.target_build.status is not None \ and self.target_build.status.finished \ and self.target.get_setting('CI_RESET_BUILD_EVENTS_ON_JOB_RESUBMISSION', False): self.target_build.reset_events() def force_resubmit(self): if self.job_id is None: # Seems like something went wrong while submitting job in the first place # so just try submitting once more self.backend.submit(self) return True self.reset_build_events() # Delete old data if any if self.target.get_setting('CI_DELETE_RESULTS_RESUBMITTED_JOBS', False) and self.testrun: testrun = self.testrun self.testrun = None testrun.delete() success = False try: # Resubmit test job not respecting any restrictions self.backend.get_implementation().resubmit(self) self.resubmitted_count += 1 success = True self.failure = None except SubmissionIssue as issue: self.failure = str(issue) self.save() return success def cancel(self): if self.job_status == "Canceled": return False if self.job_id is not None and self.backend.get_implementation().has_cancel(): return self.backend.get_implementation().cancel(self) self.fetched = True self.submitted = True self.job_status = "Canceled" self.failure = "Canceled before submission" self.save() return True def needs_postprocessing(self): return self.testrun and self.target.enabled_plugins and any(self.target.enabled_plugins) def update_statuses(self, status): # Update this testjob's status and the build/project status assocated self.job_status = status self.save() if self.testrun: UpdateProjectStatus()(self.testrun) def __str__(self): return "%s/%s" % (self.backend.name, self.job_id) class Meta: # This index speeds up Backend.poll(), where it queries submitted and fetched together indexes = [ models.Index(fields=['submitted', 'fetched']), ] @staticmethod def set_subtasks_count(job_id, subtasks_count): if subtasks_count <= 0: return with transaction.atomic(): try: test_job = TestJob.objects.select_for_update(nowait=True).get(pk=job_id) test_job.subtasks_count = subtasks_count test_job.save() except DatabaseError: return @staticmethod def sub_subtasks_count(job_id): with transaction.atomic(): try: test_job = TestJob.objects.select_for_update(nowait=True).get(pk=job_id) subtasks_count = test_job.subtasks_count if subtasks_count == 0: return True test_job.subtasks_count -= 1 test_job.save() return test_job.subtasks_count == 0 except DatabaseError: return False
class TestJob(models.Model): @property def show_definition(self): pass def success(self): pass @property def url(self): pass @property def input(self): pass @input.setter def input(self): pass def resubmit(self): pass def reset_build_events(self): pass def force_resubmit(self): pass def cancel(self): pass def needs_postprocessing(self): pass def update_statuses(self, status): pass def __str__(self): pass class Meta: @staticmethod def set_subtasks_count(job_id, subtasks_count): pass @staticmethod def sub_subtasks_count(job_id): pass
22
0
9
1
8
1
2
0.18
1
5
3
0
12
1
14
14
201
33
142
59
120
26
130
52
114
5
1
3
34
145,725
Linaro/squad
Linaro_squad/squad/ci/models.py
squad.ci.models.ResultsInput
class ResultsInput(models.Model): test_job = models.OneToOneField(TestJob, related_name='results_input', on_delete=models.CASCADE, null=True) text = models.TextField(null=True, blank=True)
class ResultsInput(models.Model): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
3
0
3
3
2
0
3
3
2
0
1
0
0
145,726
Linaro/squad
Linaro_squad/squad/ci/models.py
squad.ci.models.Backend
class Backend(models.Model): name = models.CharField(max_length=128, unique=True) url = models.URLField() username = models.CharField(max_length=128) token = models.CharField(max_length=1024) implementation_type = models.CharField( max_length=64, choices=list_backends(), default='null', ) backend_settings = models.TextField( null=True, blank=True, validators=[yaml_validator] ) poll_interval = models.IntegerField(default=60) # minutes max_fetch_attempts = models.IntegerField(default=3) poll_enabled = models.BooleanField(default=True) listen_enabled = models.BooleanField(default=True) def poll(self): if not self.poll_enabled: return test_jobs = self.test_jobs.filter( submitted=True, fetched=False, fetch_attempts__lt=self.max_fetch_attempts ) for test_job in test_jobs: last = test_job.last_fetch_attempt if last: now = timezone.now() next_poll = last + relativedelta(minutes=self.poll_interval) if now > next_poll: yield test_job else: yield test_job def fetch(self, job_id): # Job statuses can be one of: # * None # * Submitted # * Scheduling # * Scheduled # * Running # * Complete # * Incomplete # * Canceled # * Fetching # Only jobs in 'Complete', 'Canceled' and 'Incomplete' are eligible for fetching with transaction.atomic(): try: test_job = TestJob.objects.select_for_update(nowait=True).get(pk=job_id) if test_job.fetched or test_job.fetch_attempts >= test_job.backend.max_fetch_attempts: return except DatabaseError: # another thread is working on this testjob return try: test_job.last_fetch_attempt = timezone.now() results = self.get_implementation().fetch(test_job) if results is None: # empty results mean the job is still in progress # or in the queue test_job.save() return except FetchIssue as issue: logger.warning("error fetching job %s: %s" % (test_job.id, str(issue))) test_job.failure = str(issue) test_job.fetched = not issue.retry test_job.fetch_attempts += 1 test_job.save() return test_job.job_status = 'Fetching' test_job.fetched = True test_job.fetched_at = timezone.now() test_job.save() status, completed, metadata, tests, metrics, logs = results if not completed: tests = {} metrics = {} test_job.can_resubmit = True if completed and not tests and not metrics: # test job produced no results # mark it incomplete completed = False test_job.can_resubmit = True metadata['job_id'] = test_job.job_id metadata['job_status'] = status if test_job.url is not None: metadata['job_url'] = test_job.url try: receive = ReceiveTestRun(test_job.target, update_project_status=False) testrun, _ = receive( version=test_job.target_build.version, environment_slug=test_job.environment, metadata_file=json.dumps(metadata), tests_file=json.dumps(tests), metrics_file=json.dumps(metrics), log_file=logs, completed=completed, ) test_job.testrun = testrun except InvalidMetadata as exception: test_job.failure = str(exception) except DuplicatedTestJob as exception: logger.error('Failed to fetch test_job(%d): "%s"' % (test_job.id, str(exception))) if test_job.needs_postprocessing(): # Offload postprocessing plugins to a new task test_job.save() # Avoids cyclic import errors from squad.ci.tasks import postprocess_testjob postprocess_testjob.delay(test_job.id, status) else: # Remove the 'Fetching' job_status only after all work is done test_job.update_statuses(status) def __postprocess_testjob__(self, test_job, job_status): """ The problem postprocess plugin 1 plugin 2 trigger subtasks plugin 3 One ore more plugins may have subtasks, meaning that their main thread comes to an end before all results are in place, causing inconsistencies. The solution is to detect the count of plugins with subtasks there are so they can update the testjob status only at the very end """ # Avoids cyclic import errors from squad.ci.tasks import postprocess_testjob_subtasks plugins = {p: get_plugin_instance(p) for p in test_job.target.enabled_plugins} plugins_with_subtasks = [p for p in plugins.values() if p.has_subtasks()] has_subtasks = len(plugins_with_subtasks) > 0 if has_subtasks: # Plugins with subtasks should call squad.ci.tasks.update_testjob_status TestJob.set_subtasks_count(test_job.id, len(plugins_with_subtasks)) for plugin_name, plugin in plugins.items(): try: if plugin.has_subtasks(): postprocess_testjob_subtasks.delay(plugin_name, test_job.id, job_status) else: plugin.postprocess_testjob(test_job) except Exception as e: logger.error("Plugin postprocessing error: " + str(e) + "\n" + traceback.format_exc()) if not has_subtasks: # Remove the 'Fetching' job_status only after all work is done test_job.update_statuses(job_status) def submit(self, test_job): test_job.reset_build_events() job_id_list = self.get_implementation().submit(test_job) test_job.job_id = job_id_list[0] test_job.submitted = True test_job.submitted_at = timezone.now() test_job.save() if job_id_list is not None and len(job_id_list) > 1: # clone test job in case of multinode for job_id in job_id_list[1:]: test_job.pk = None # according to django docs this will create new object test_job.job_id = job_id test_job.save() def get_implementation(self): return get_backend_implementation(self) def check_job_definition(self, definition): return self.get_implementation().check_job_definition(definition) def get_job_definition(self, job_id): return self.get_implementation().get_job_definition(job_id) def supports_callbacks(self): return self.get_implementation().supports_callbacks() def validate_callback(self, request, project): self.get_implementation().validate_callback(request, project) def process_callback(self, payload, build, environment): return self.get_implementation().process_callback(payload, build, environment, self) def __str__(self): return '%s (%s)' % (self.name, self.implementation_type)
class Backend(models.Model): def poll(self): pass def fetch(self, job_id): pass def __postprocess_testjob__(self, test_job, job_status): ''' The problem postprocess plugin 1 plugin 2 trigger subtasks plugin 3 One ore more plugins may have subtasks, meaning that their main thread comes to an end before all results are in place, causing inconsistencies. The solution is to detect the count of plugins with subtasks there are so they can update the testjob status only at the very end ''' pass def submit(self, test_job): pass def get_implementation(self): pass def check_job_definition(self, definition): pass def get_job_definition(self, job_id): pass def supports_callbacks(self): pass def validate_callback(self, request, project): pass def process_callback(self, payload, build, environment): pass def __str__(self): pass
12
1
16
2
11
3
3
0.28
1
8
5
0
11
0
11
11
202
28
138
43
124
38
115
40
101
11
1
3
32
145,727
Linaro/squad
Linaro_squad/squad/ci/migrations/0030_testjob_subtasks_count.py
squad.ci.migrations.0030_testjob_subtasks_count.Migration
class Migration(migrations.Migration): dependencies = [ ("ci", "0029_create_testjob_results_input"), ] operations = [ migrations.AddField( model_name="testjob", name="subtasks_count", field=models.IntegerField(default=0), ), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
12
1
11
3
10
0
3
3
2
0
1
0
0
145,728
Linaro/squad
Linaro_squad/squad/ci/migrations/0029_create_testjob_results_input.py
squad.ci.migrations.0029_create_testjob_results_input.Migration
class Migration(migrations.Migration): dependencies = [ ('ci', '0028_create_testjob_indexes'), ] operations = [ migrations.CreateModel( name='ResultsInput', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('text', models.TextField(blank=True, null=True)), ('test_job', models.OneToOneField(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='results_input', to='ci.testjob')), ], ), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
16
2
14
3
13
0
3
3
2
0
1
0
0
145,729
Linaro/squad
Linaro_squad/squad/ci/migrations/0028_create_testjob_indexes.py
squad.ci.migrations.0028_create_testjob_indexes.Migration
class Migration(migrations.Migration): dependencies = [ ('ci', '0027_add_tuxsuite_implementation_type'), ] operations = [ migrations.AlterField( model_name='testjob', name='job_id', field=models.CharField(blank=True, db_index=True, max_length=128, null=True), ), migrations.AddIndex( model_name='testjob', index=models.Index(fields=['submitted', 'fetched'], name='ci_testjob_submitt_e51225_idx'), ), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
17
2
15
3
14
0
3
3
2
0
1
0
0
145,730
Linaro/squad
Linaro_squad/squad/core/admin.py
squad.core.admin.EnvironmentInline
class EnvironmentInline(admin.StackedInline): """ Handles environments when editing a project. """ model = models.Environment fields = ['slug', 'name', 'description', 'expected_test_runs'] extra = 0
class EnvironmentInline(admin.StackedInline): ''' Handles environments when editing a project. ''' pass
1
1
0
0
0
0
0
0.75
1
0
0
0
0
0
0
0
7
0
4
4
3
3
4
4
3
0
1
0
0
145,731
Linaro/squad
Linaro_squad/squad/core/admin.py
squad.core.admin.GroupAdmin
class GroupAdmin(NoDeleteListingModelAdmin): """ Handles groups """ model = models.Group inlines = [GroupMemberAdmin]
class GroupAdmin(NoDeleteListingModelAdmin): ''' Handles groups ''' pass
1
1
0
0
0
0
0
1
1
0
0
0
0
0
0
1
6
0
3
3
2
3
3
3
2
0
2
0
0
145,732
Linaro/squad
Linaro_squad/squad/core/admin.py
squad.core.admin.GroupMemberAdmin
class GroupMemberAdmin(admin.TabularInline): """ Handles group members """ model = models.GroupMember readonly_fields = ['member_since']
class GroupMemberAdmin(admin.TabularInline): ''' Handles group members ''' pass
1
1
0
0
0
0
0
1
1
0
0
0
0
0
0
0
7
1
3
3
2
3
3
3
2
0
1
0
0
145,733
Linaro/squad
Linaro_squad/squad/core/admin.py
squad.core.admin.KnownIssueAdmin
class KnownIssueAdmin(admin.ModelAdmin): models = models.KnownIssue list_display = ['title', 'url', 'active', 'intermittent'] list_filter = [KnownIssueGroupFilter] form = KnownIssueAdminForm
class KnownIssueAdmin(admin.ModelAdmin): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
5
0
5
5
4
0
5
5
4
0
1
0
0
145,734
Linaro/squad
Linaro_squad/squad/core/admin.py
squad.core.admin.KnownIssueGroupFilter
class KnownIssueGroupFilter(admin.SimpleListFilter): title = 'group' parameter_name = 'group' def lookups(self, request, model_admin): return ((g.id, g.slug) for g in models.Group.objects.order_by('slug').all()) def queryset(self, request, queryset): group = request.GET.get('group') if group: return queryset.filter(environments__project__group__id=group).distinct() else: return queryset
class KnownIssueGroupFilter(admin.SimpleListFilter): def lookups(self, request, model_admin): pass def queryset(self, request, queryset): pass
3
0
4
0
4
0
2
0
1
0
0
0
2
0
2
2
14
3
11
6
8
0
10
6
7
2
1
1
3
145,735
Linaro/squad
Linaro_squad/squad/core/admin.py
squad.core.admin.LogEntryAdmin
class LogEntryAdmin(admin.ModelAdmin): date_hierarchy = 'action_time' list_filter = [ 'user', 'content_type', 'action_flag' ] search_fields = [ 'object_repr', 'change_message' ] list_display = [ 'action_time', 'user', 'content_type', 'object_link', 'action_flag', ] def has_add_permission(self, request): return False def has_change_permission(self, request, obj=None): return False def has_delete_permission(self, request, obj=None): return False def has_view_permission(self, request, obj=None): return request.user.is_superuser def object_link(self, obj): if obj.action_flag == DELETION: link = escape(obj.object_repr) else: ct = obj.content_type link = '<a href="%s">%s</a>' % ( reverse('admin:%s_%s_change' % (ct.app_label, ct.model), args=[obj.object_id]), escape(obj.object_repr), ) return mark_safe(link) object_link.admin_order_field = "object_repr" object_link.short_description = "object"
class LogEntryAdmin(admin.ModelAdmin): def has_add_permission(self, request): pass def has_change_permission(self, request, obj=None): pass def has_delete_permission(self, request, obj=None): pass def has_view_permission(self, request, obj=None): pass def object_link(self, obj): pass
6
0
4
0
4
0
1
0
1
0
0
0
5
0
5
5
46
8
38
12
32
0
21
12
15
2
1
1
6
145,736
Linaro/squad
Linaro_squad/squad/core/admin.py
squad.core.admin.PatchSourceAdmin
class PatchSourceAdmin(admin.ModelAdmin): form = PatchSourceForm def save_model(self, request, obj, form, change): if 'password' in form.changed_data: obj.password = form.cleaned_data['password'] super(PatchSourceAdmin, self).save_model(request, obj, form, change)
class PatchSourceAdmin(admin.ModelAdmin): def save_model(self, request, obj, form, change): pass
2
0
4
0
4
0
2
0
1
1
0
0
1
0
1
1
7
1
6
3
4
0
6
3
4
2
1
1
2
145,737
Linaro/squad
Linaro_squad/squad/core/admin.py
squad.core.admin.PatchSourceForm
class PatchSourceForm(ModelForm): password = forms.CharField(max_length=128, required=False) def __init__(self, *args, **kwargs): super(PatchSourceForm, self).__init__(*args, **kwargs) self.initial['password'] = self.instance.password class Meta: model = models.PatchSource fields = ['name', 'url', 'username', 'password', 'token', 'implementation']
class PatchSourceForm(ModelForm): def __init__(self, *args, **kwargs): pass class Meta:
3
0
3
0
3
0
1
0
1
1
0
0
1
0
1
1
10
2
8
6
5
0
8
6
5
1
1
0
1
145,738
Linaro/squad
Linaro_squad/squad/core/admin.py
squad.core.admin.ProjectAdmin
class ProjectAdmin(NoDeleteListingModelAdmin): list_display = ['__str__', 'is_public', 'moderate_notifications', 'custom_email_template'] list_filter = ['group', 'is_public', 'moderate_notifications', 'custom_email_template'] inlines = [EnvironmentInline, SubscriptionInline, AdminSubscriptionInline] save_as = True
class ProjectAdmin(NoDeleteListingModelAdmin): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
1
5
0
5
5
4
0
5
5
4
0
2
0
0
145,739
Linaro/squad
Linaro_squad/squad/core/admin.py
squad.core.admin.ProjectStatusAdmin
class ProjectStatusAdmin(admin.ModelAdmin): model = models.ProjectStatus ordering = ['-build__datetime'] list_display = ['__str__', 'finished', 'approved', 'notified', 'tests_total', 'tests_pass', 'tests_fail', 'tests_skip', 'tests_xfail'] list_filter = ['build__project', 'finished', 'approved', 'notified'] actions = [approve_project_status, resend_notification] def get_queryset(self, request): return super(ProjectStatusAdmin, self).get_queryset(request).prefetch_related( 'build', 'build__project', 'build__project__group', ) def has_add_permission(self, request): return False
class ProjectStatusAdmin(admin.ModelAdmin): def get_queryset(self, request): pass def has_add_permission(self, request): pass
3
0
4
0
4
0
1
0
1
1
0
0
2
0
2
2
16
2
14
8
11
0
10
8
7
1
1
0
2
145,740
Linaro/squad
Linaro_squad/squad/ci/migrations/0027_add_tuxsuite_implementation_type.py
squad.ci.migrations.0027_add_tuxsuite_implementation_type.Migration
class Migration(migrations.Migration): dependencies = [ ('ci', '0026_job_start_end_time'), ] operations = [ migrations.AlterField( model_name='backend', name='implementation_type', field=models.CharField(choices=[('fake', 'fake'), ('lava', 'lava'), ('null', 'null'), ('tuxsuite', 'tuxsuite')], default='null', max_length=64), ), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
13
2
11
3
10
0
3
3
2
0
1
0
0
145,741
Linaro/squad
Linaro_squad/squad/ci/migrations/0026_job_start_end_time.py
squad.ci.migrations.0026_job_start_end_time.Migration
class Migration(migrations.Migration): dependencies = [ ('ci', '0025_backend_listen_enabled'), ] operations = [ migrations.AddField( model_name='testjob', name='ended_at', field=models.DateTimeField(null=True), ), migrations.AddField( model_name='testjob', name='started_at', field=models.DateTimeField(null=True), ), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
18
2
16
3
15
0
3
3
2
0
1
0
0
145,742
Linaro/squad
Linaro_squad/squad/ci/migrations/0025_backend_listen_enabled.py
squad.ci.migrations.0025_backend_listen_enabled.Migration
class Migration(migrations.Migration): dependencies = [ ('ci', '0024_fix_testjob_environment_validation'), ] operations = [ migrations.AddField( model_name='backend', name='listen_enabled', field=models.BooleanField(default=True), ), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
13
2
11
3
10
0
3
3
2
0
1
0
0
145,743
Linaro/squad
Linaro_squad/squad/ci/migrations/0024_fix_testjob_environment_validation.py
squad.ci.migrations.0024_fix_testjob_environment_validation.Migration
class Migration(migrations.Migration): dependencies = [ ('ci', '0023_remove_testjob_build'), ] operations = [ migrations.AlterField( model_name='testjob', name='environment', field=models.CharField(max_length=100, validators=[django.core.validators.RegexValidator(regex='^[a-zA-Z0-9][a-zA-Z0-9_.-]*$')]), ), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
13
2
11
3
10
0
3
3
2
0
1
0
0
145,744
Linaro/squad
Linaro_squad/squad/core/admin.py
squad.core.admin.SelectEnvironment
class SelectEnvironment(ModelMultipleChoiceField): def label_from_instance(self, e): return e.project.full_name + ' - ' + e.slug
class SelectEnvironment(ModelMultipleChoiceField): def label_from_instance(self, e): pass
2
0
2
0
2
0
1
0
1
0
0
0
1
0
1
1
4
1
3
2
1
0
3
2
1
1
1
0
1
145,745
Linaro/squad
Linaro_squad/squad/core/admin.py
squad.core.admin.SubscriptionInline
class SubscriptionInline(admin.StackedInline): model = models.Subscription fields = ['email', 'user', 'notification_strategy'] extra = 0
class SubscriptionInline(admin.StackedInline): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
4
0
4
4
3
0
4
4
3
0
1
0
0
145,746
Linaro/squad
Linaro_squad/squad/ci/migrations/0004_testjob_failure.py
squad.ci.migrations.0004_testjob_failure.Migration
class Migration(migrations.Migration): dependencies = [ ('ci', '0003_backend_name'), ] operations = [ migrations.AddField( model_name='testjob', name='failure', field=models.TextField(blank=True, null=True), ), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
13
2
11
3
10
0
3
3
2
0
1
0
0
145,747
Linaro/squad
Linaro_squad/squad/core/migrations/0089_test_has_known_issues.py
squad.core.migrations.0089_test_has_known_issues.Migration
class Migration(migrations.Migration): dependencies = [ ('core', '0088_user_subscriptions'), ] operations = [ migrations.AddField( model_name='test', name='has_known_issues', field=models.NullBooleanField(), ), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
13
2
11
3
10
0
3
3
2
0
1
0
0