summaryrefslogtreecommitdiff
blob: c272c505ae24245c2f9425f07fd5b84d62c73d08 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
# Copyright 1998-2017 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

from django.shortcuts import render, get_object_or_404, HttpResponseRedirect, redirect
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.conf import settings
from django.urls import reverse
from tbc_www.forms import BugForm, BugzillaUser
from tbc_www.utils.bugzillasubmit import addnewbug
from gentoo_www.models import SiteSettings, Layout, Pages, SubPages, Sponsors, Posts, Bugzilla
from tbc_www.models import EbuildsMetadata, BuildLogs, BuildJobs, BuildLogsQa, \
	BuildJobsUse, Categories, CategoriesMetadata, Packages, PackagesMetadata, Ebuilds, \
	Repos, EbuildsKeywords, BuildLogsErrors, EbuildsRestrictions, EbuildsIuse, PackagesRepoman, \
	BuildLogsConfig, BuildLogsUse, BuildLogsRepoman, PackagesEmails, Jobs
import re
import gzip
import os

def default_TmpDict(pagerequest):
	site = get_object_or_404(SiteSettings)
	page = get_object_or_404(Pages, nav1 = pagerequest)
	jobs = get_object_or_404(Jobs, JobType = 'esync')
	pages = Pages.objects.all()
	if page.SubMenu:
		subpages = SubPages.objects.filter(PageId = page.PageId)
	else:
		subpages = False
	TmpDict = {'site' : site}
	TmpDict['page'] = page
	TmpDict['pages'] = pages
	TmpDict['subpages'] = subpages
	TmpDict['smappages'] = SubPages.objects.all()
	TmpDict['jobs'] = jobs
	return TmpDict

def fail_status(buildlog_id):
	BU_tmp = BuildLogsUse.objects.filter(BuildLogId = buildlog_id)
	Test = False
	if BU_tmp != []:
		for BU in BU_tmp:
			if BU.Status:
				if BU.UseId.Flag == 'test':
					Test = True
	adict = {}
	adict['repoman'] = False
	adict['qa'] = False
	adict['others'] = False
	adict['build'] = False
	adict['TestRun'] = Test
	BE_tmp = BuildLogsErrors.objects.filter(BuildLogId__BuildLogId = buildlog_id)
	for BE in BE_tmp:
		if BE.ErrorId.ErrorId == 1:
			adict['repoman'] = True
		if BE.ErrorId.ErrorId == 2:
			adict['qa'] = True
		if BE.ErrorId.ErrorId == 3:
			adict['others'] = True
		if BE.ErrorId.ErrorId == 4:
			adict['test'] = True
		if BE.ErrorId.ErrorId >= 5:
			adict['build'] = True
			adict['builderror'] = BE.ErrorId.ErrorName
			if BE.ErrorId.ErrorName != 'install':
				adict['TestRun'] = False
	return adict

def home(request):
	pagerequest = 'home'
	Lines = 10
	TmpDict = default_TmpDict(pagerequest)
	TmpDict['PM'] = PackagesMetadata.objects.filter(New = True)
	alist = []
	for EM in EbuildsMetadata.objects.filter(Updated = True):
		adict = {}
		adict['EbuildId'] = EM.EbuildId.EbuildId
		adict['C'] = EM.EbuildId.PackageId.CategoryId.Category
		adict['P'] = EM.EbuildId.PackageId.Package
		adict['CId'] = EM.EbuildId.PackageId.CategoryId.CategoryId
		adict['PId'] = EM.EbuildId.PackageId.PackageId
		adict['V'] = EM.EbuildId.Version
		adict['R'] = EM.EbuildId.PackageId.RepoId.Repo
		adict['TimeStamp'] = EM.EbuildId.TimeStamp
		adict['CommitId'] = EM.Commit
		adict['CommitMsg'] = EM.CommitMsg
		adict['Descriptions'] = EM.Descriptions
		adict['EK_tmp'] = EbuildsKeywords.objects.filter(EbuildId__EbuildId = EM.EbuildId.EbuildId)
		alist.append(adict)
	TmpDict['EM_list'] = alist
	alist = []
	for BL in BuildLogs.objects.filter(New = True):
		adict2 = {}
		adict2['BuildLogId'] = BL.BuildLogId
		adict2['C'] = BL.EbuildId.PackageId.CategoryId.Category
		adict2['P'] = BL.EbuildId.PackageId.Package
		adict2['V'] = BL.EbuildId.Version
		adict2['R'] = BL.EbuildId.PackageId.RepoId.Repo
		adict2['SummeryText'] = BL.SummeryText
		adict2['Fail'] = BL.Fail
		if BL.Fail:
			adict2['BE_tmp'] = BuildLogsErrors.objects.filter(BuildLogId = BL.BuildLogId)
		alist.append(adict2)
	TmpDict['BL_tmp'] = alist
	adict = {}
	BJ_Tmp = BuildJobs.objects.filter(New = True)
	for BJ in BJ_Tmp:
		adict2 = {}
		adict2['EbuildId'] = BJ.EbuildId.EbuildId
		adict2['C'] = BJ.EbuildId.PackageId.CategoryId.Category
		adict2['P'] = BJ.EbuildId.PackageId.Package
		adict2['V'] = BJ.EbuildId.Version
		adict2['R'] = BJ.EbuildId.PackageId.RepoId.Repo
		adict2['Status'] = BJ.Status
		adict2['title'] = "Setup: " + BJ.SetupId.Setup + "\n" + "Profile: " + BJ.SetupId.Profile + "\n"
		BJU = BuildJobsUse.objects.filter(BuildJobId = BJ.BuildJobId)
		if not BJU == []:
			use_enable = []
			use_disable = []
			for BU in BJU:
				if BU.Status:
					use_enable.append(BU.UseId.Flag)
				else:
					use_disable.append(BU.UseId.Flag)
		if not use_enable == []:
			adict2['title'] = adict2['title'] + "Enable: "
			for use in use_enable:
				adict2['title'] = adict2['title'] + use + " "
			adict2['title'] = adict2['title'] + "\n"
		if not use_disable == []:
			adict2['title'] = adict2['title'] + "Disable: "
			for use in use_disable:
				adict2['title'] = adict2['title'] + use + " "
			adict2['title'] = adict2['title'] + "\n"
		adict[BJ.BuildJobId] = adict2
	TmpDict['BJ'] = adict
	TmpDict['PR_tmp'] = PackagesRepoman.objects.order_by('-Id')[:Lines]
	return render(request, 'pages/' + pagerequest + '/index.html', TmpDict)

def categories(request):
	pagerequest = 'packages'
	TmpDict = default_TmpDict(pagerequest)
	alphabet_list = map(chr, range(97, 123))
	CM_tmp = CategoriesMetadata.objects.filter(CategoryId__Active = True).order_by('CategoryId__Category')
	list2 = []
	for a in alphabet_list:
		alist = []
		for CM in CM_tmp:
			if a == CM.CategoryId.Category[:1]:
				adict = {}
				adict['CategoryId'] = CM.CategoryId.CategoryId
				adict['Category'] = CM.CategoryId.Category
				adict['Descriptions'] = CM.Descriptions
				alist.append(adict)
		adict2 = {}
		adict2['letter'] = a
		adict2['CM_list'] = alist
		if alist != []:
			list2.append(adict2)
	TmpDict['CM_tmp'] = list2
	return render(request, 'pages/categories/index.html', TmpDict)

def packages(request, category_id):
	pagerequest = 'packages'
	TmpDict = default_TmpDict(pagerequest)
	alist = []
	TmpDict['PM_tmp'] = PackagesMetadata.objects.filter(PackageId__CategoryId_id = category_id).filter(PackageId__Active = True)
	TmpDict['C'] = get_object_or_404(CategoriesMetadata,  CategoryId__CategoryId = category_id)
	return render(request, 'pages/categories/packages/index.html', TmpDict)

def versions(request, package_id):
	pagerequest = 'packages'
	TmpDict = default_TmpDict(pagerequest)
	P = get_object_or_404(PackagesMetadata, PackageId__PackageId = package_id)
	TmpDict['P'] = P
	alist =[]
	EM_tmp = EbuildsMetadata.objects.filter(EbuildId__Active = True).filter(EbuildId__PackageId__PackageId = P.PackageId.PackageId)
	for EM in EM_tmp:
		adict = {}
		ebuild_id = EM.EbuildId.EbuildId
		adict['EbuildId'] = ebuild_id
		adict['Slot'] = EM.Slot
		adict['Version'] = EM.EbuildId.Version
		adict['TimeStamp'] = EM.EbuildId.TimeStamp
		adict['EK_tmp'] = EbuildsKeywords.objects.filter(EbuildId__EbuildId = ebuild_id)
		adict['EU_tmp'] = EbuildsIuse.objects.filter(EbuildId__EbuildId = ebuild_id)
		adict['ER_tmp'] = EbuildsRestrictions.objects.filter(EbuildId__EbuildId = ebuild_id)
		BL_tmp = BuildLogs.objects.filter(EbuildId__EbuildId = ebuild_id)
		adict['BL_tmp'] = BL_tmp
		alist2 = []
		for BL in BL_tmp:
			adict2 = {}
			adict2['BuildLogId'] = BL.BuildLogId
			adict2['repoman'] = False
			adict2['qa'] = False
			adict2['Blo'] = False
			adict2['Blb'] = False
			if BL.Fail:
				adict2['fail'] = True
			BE_tmp = BuildLogsErrors.objects.filter(BuildLogId__BuildLogId = BL.BuildLogId)
			for BE in BE_tmp:
				if BE.ErrorId.ErrorId == 1:
					adict2['repoman'] = True
				if BE.ErrorId.ErrorId == 2:
					adict2['qa'] = True
				if BE.ErrorId.ErrorId == 3:
					adict2['Blo'] = True
				if BE.ErrorId.ErrorId >= 4:
					adict2['Blb'] = True
					adict2['Ble'] = BE.ErrorId.ErrorName
			alist2.append(adict2)
		adict['fi_tmp'] = alist2
		alist.append(adict)
	TmpDict['EM_info'] = alist
	return render(request, 'pages/categories/packages/versions/index.html', TmpDict)

def new_build_req(request):
	pagerequest = 'build_req'
	TmpDict = default_TmpDict(pagerequest)
	adict = {}
	BJ_Tmp = BuildJobs.objects.order_by('-TimeStamp')
	for BJ in BJ_Tmp:
		adict2 = {}
		adict2['EbuildId'] = BJ.EbuildId.EbuildId
		adict2['C'] = BJ.EbuildId.PackageId.CategoryId.Category
		adict2['P'] = BJ.EbuildId.PackageId.Package
		adict2['V'] = BJ.EbuildId.Version
		adict2['R'] = BJ.EbuildId.PackageId.RepoId.Repo
		adict2['Status'] = BJ.Status
		adict2['title'] = "Setup: " + BJ.SetupId.Setup + "\n" + "Profile: " + BJ.SetupId.Profile + "\n"
		BJU = BuildJobsUse.objects.filter(BuildJobId = BJ.BuildJobId)
		if not BJU == []:
			use_enable = []
			use_disable = []
			for BU in BJU:
				if BU.Status:
					use_enable.append(BU.UseId.Flag)
				else:
					use_disable.append(BU.UseId.Flag)
		if not use_enable == []:
			adict2['title'] = adict2['title'] + "Enable: "
			for use in use_enable:
				adict2['title'] = adict2['title'] + use + " "
			adict2['title'] = adict2['title'] + "\n"
		if not use_disable == []:
			adict2['title'] = adict2['title'] + "Disable: "
			for use in use_disable:
				adict2['title'] = adict2['title'] + use + " "
			adict2['title'] = adict2['title'] + "\n"
		adict[BJ.BuildJobId] = adict2
	TmpDict['BJ'] = adict 
	return render(request, 'pages/build_req/index.html', TmpDict)

def new_repoman(request):
	pagerequest = 'new'
	Lines = 30
	TmpDict = default_TmpDict(pagerequest)
	TmpDict['PR_tmp'] = PackagesRepoman.objects.order_by('-Id')[:Lines]
	return render(request, 'pages/' + pagerequest + '/repoman/index.html', TmpDict)

def new_logs(request):
	pagerequest = 'logs'
	TmpDict = default_TmpDict(pagerequest)
	alist = []
	for BL in BuildLogs.objects.order_by('-TimeStamp').filter(New = True):
		adict2 = {}
		adict2['BuildLogId'] = BL.BuildLogId
		adict2['C'] = BL.EbuildId.PackageId.CategoryId.Category
		adict2['P'] = BL.EbuildId.PackageId.Package
		adict2['V'] = BL.EbuildId.Version
		adict2['R'] = BL.EbuildId.PackageId.RepoId.Repo
		adict2['Fail'] = BL.Fail
		adict2['SummeryText'] = BL.SummeryText
		if BL.Fail:
			adict2['FI'] = fail_status(BL.BuildLogId)
		alist.append(adict2)
	TmpDict['BL_tmp'] = alist
	TmpDict['QA_tmp'] = BuildLogsQa.objects.filter(BuildLogId__New = True)
	TmpDict['RM_tmp'] = BuildLogsRepoman.objects.filter(BuildLogId__New = True)
	return render(request, 'pages/logs/index.html', TmpDict)

def new_build_logs_all(request):
	pagerequest = 'logs'
	object_on_page = 50
	TmpDict = default_TmpDict(pagerequest)
	BL_tmp = BuildLogs.objects.order_by('-TimeStamp').filter(Fail = True)
	alist = []
	for BL in BL_tmp:
		adict = {}
		adict['BuildLogId'] = BL.BuildLogId
		adict['C'] = BL.EbuildId.PackageId.CategoryId.Category
		adict['P'] = BL.EbuildId.PackageId.Package
		adict['V'] = BL.EbuildId.Version
		adict['R'] = BL.EbuildId.PackageId.RepoId.Repo
		adict['Fail'] = BL.Fail
		adict['SummeryText'] = BL.SummeryText
		if BL.Fail:
			adict['FI'] = fail_status(BL.BuildLogId)
		alist.append(adict)
	paginator = Paginator(alist, object_on_page)
	page = request.GET.get('page')
	try:
		BL_tmp = paginator.page(page)
	except PageNotAnInteger:
		# If page is not an integer, deliver first page.
		BL_tmp = paginator.page(1)
	except EmptyPage:
		# If page is out of range (e.g. 9999), deliver last page of results.
		BL_tmp = paginator.page(paginator.num_pages)
	TmpDict['BL_tmp'] = BL_tmp
	return render(request, 'pages/logs/all/build/index.html', TmpDict)

def new_logs_build(request, buildlog_id):
	pagerequest = 'logs'
	TmpDict = default_TmpDict(pagerequest)
	TmpDict['Bugzillalogin'] = False
	B = BuildLogs.objects.get(BuildLogId = buildlog_id)
	EM = EbuildsMetadata.objects.get(EbuildId = B.EbuildId.EbuildId)
	PM = PackagesMetadata.objects.get(PackageId__PackageId = B.EbuildId.PackageId.PackageId)
	BLI = {}
	BLI['BuildLogId'] = buildlog_id
	BLI['EbuildId'] = B.EbuildId.EbuildId
	BLI['C'] = B.EbuildId.PackageId.CategoryId.Category
	BLI['P'] = B.EbuildId.PackageId.Package
	BLI['V'] = B.EbuildId.Version
	BLI['R'] = B.EbuildId.PackageId.RepoId.Repo
	BLI['EC'] = EM.Commit
	BLI['PD'] = EM.Descriptions
	BLI['PC'] = PM.Gitlog
	BLI['Fail'] = B.Fail
	BLI['Summery_text'] = B.SummeryText
	if B.BugId == "0":
		BLI['BugId'] = False
	else:
		BLI['BugId'] = B.BugId
	BC = BuildLogsConfig.objects.get(BuildLogId = buildlog_id)
	#CEO_tmp = ConfigsEmergeOptions.objects.filter(ConfigId = BC.ConfigId.ConfigId)
	BU_tmp = BuildLogsUse.objects.filter(BuildLogId = buildlog_id)
	config_eoption = []
	BLI['configid'] = BC.ConfigId.ConfigId
	BLI['hostname'] = BC.ConfigId.HostName
	BLI['config'] = BC.ConfigId.SetupId.Setup
	BLI['profile'] = BC.ConfigId.SetupId.Profile
	BLI['logid'] = BC.LogId
	BLI['logname'] = BC.LogName[1:]
	BLI['emerge_info_text'] = BC.EInfoId.EmergeInfoText
	#for CEO in CEO_tmp:
	#	config_eoption.append(CEO.EmergeOptionId.EOption)
	#BLI['emerge_option'] = config_eoption
	if not BU_tmp == []:
		use_enable = []
		use_disable = []
		for BU in BU_tmp:
			if BU.Status:
				use_enable.append(BU.UseId.Flag)
			else:
				use_disable.append(BU.UseId.Flag)
		if not use_enable == []:
			BLI['use_enable'] = use_enable
		if not use_disable == []:
			BLI['use_disable'] = use_disable
	TmpDict['FI'] = fail_status(buildlog_id)
	try: 
		BRQ = BuildLogsQa.objects.get(BuildLogId = B.BuildLogId)
		BLI['QA'] = BRQ.SummeryText
	except BuildLogsQa.DoesNotExist as e:
			BLI['QA'] = False
	try: 
		BRR = BuildLogsRepoman.objects.get(BuildLogId = B.BuildLogId)
		BLI['Repoman'] = BRR.SummeryText
	except BuildLogsRepoman.DoesNotExist as e:
			BLI['Repoman'] = False
	TmpDict['BLI'] = BLI
	return render(request, 'pages/logs/build/index.html', TmpDict)

def submit_to_bugzilla(request, form, buildlog_id):
	BC = BuildLogsConfig.objects.get(BuildLogId = buildlog_id)
	b = Bugzilla.objects.get(Username=request.user.username)
	args = {}
	args['product'] = form.cleaned_data['Product']
	args['component'] = form.cleaned_data['Component']
	args['version'] = form.cleaned_data['Version']
	args['summary'] = form.cleaned_data['Summary']
	args['description'] = form.cleaned_data['Description']
	args['comment'] = form.cleaned_data['EmergeInfo']
	args['assigned_to'] = form.cleaned_data['AssigendTo']
	args['password'] = request.session['bugzillapassword']
	args['username'] = b.Bugzillaname
	LogFile = BC.ConfigId.HostName + '/' + BC.ConfigId.SetupId.Setup + BC.LogName
	LogDir = settings.STATIC_ROOT + '/logs/'
	Filesize = os.path.getsize(LogDir + LogFile)/1024
	if Filesize > 900:
		#FIXME UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8b in position 1: invalid start byte
		with open(LogDir + LogFile, 'rb') as orig_file:
			with gzip.open('/tmp' + BC.LogName + '.gz', 'wb') as zipped_file:
				zipped_file.writelines(orig_file)
		args['filename'] = '/tmp' + BC.LogName + '.gz'
		args['content_type'] = 'application/gzip'
	else:
		args['filename'] = LogDir + LogFile
		args['content_type'] = 'text/plain'
	args['comment_attach'] = 'Build log'
	newbug = addnewbug(args)
	return newbug

def buildinfo_bugzilla(request, buildlog_id):
	pagerequest = 'logs'
	TmpDict = default_TmpDict(pagerequest)
	B = get_object_or_404(BuildLogs, BuildLogId = buildlog_id)
	C = B.EbuildId.PackageId.CategoryId.Category
	P = B.EbuildId.PackageId.Package
	V = B.EbuildId.Version
	R = B.EbuildId.PackageId.RepoId.Repo
	if request.method == 'POST':
		form = BugForm(request.POST)
		if form.is_valid():
			newbug = submit_to_bugzilla(request, form, buildlog_id)
			B.BugId = newbug.id
			B.save()
			return redirect('new_logs_build', buildlog_id=buildlog_id)
	else:
		if B.Fail == 'True':
			F = get_object_or_404(BuildLogsErrors, BuildLogId = buildlog_id)
			FailText = " : " + F.ErrorId.ErrorName
		else:
			FailText = ""
		E = get_object_or_404(BuildLogsConfig, BuildLogId = buildlog_id)
		PE = get_object_or_404(PackagesEmails, PackageId__PackageId = B.EbuildId.PackageId.PackageId)
		form = BugForm()
		form.fields['Product'].initial = 'Gentoo Linux'
		form.fields['Version'].initial = 'unspecified'
		form.fields['Summary'].initial = '[TEST][Tinderbox-cluster]=' + C + '/' + P + '-' + V + '::' + R + FailText
		form.fields['Description'].initial = B.SummeryText
		form.fields['EmergeInfo'].initial = E.EInfoId.EmergeInfoText
		form.fields['AssigendTo'].initial = PE.EmailId.Email

	TmpDict['form'] = form
	TmpDict['B'] = B
	return render(request, 'pages/logs/build/submitbug/index.html', TmpDict)

def set_bugzilla_user(request):
	pagerequest = 'home'
	TmpDict = default_TmpDict(pagerequest)
	if request.method == 'POST':
		form = BugzillaUser(request.POST)
		if form.is_valid():
			b = Bugzilla.objects.get(Username=request.user.username)
			if b == []:
				b = Bugzilla(Bugzillaname = form.cleaned_data['BugzillaName'], Username = request.user.username)
				b.save()
			else:
				if b.Bugzillaname != form.cleaned_data['BugzillaName']:
					b.Bugzillaname = form.cleaned_data['BugzillaName']
					b.save()
			request.session['bugzillapassword'] = form.cleaned_data['BugzillaPassword']
			return HttpResponseRedirect('/home/')

	else:
		form = BugzillaUser()
		TmpDict['form'] = form
	return render(request, 'registration/bugzillauser.html', TmpDict)