summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYongqin Liu <yongqin.liu@linaro.org>2020-02-25 14:41:58 +0800
committerYongqin Liu <yongqin.liu@linaro.org>2020-02-25 14:41:58 +0800
commit75c6d82a9446c506be5e6d4ab996c0c05c7ced21 (patch)
tree3f36d178278c4b738cb6b50962c299b3cf1ab503
parent0b34e6ac0d43e308ac488c2171a1fdbfcd601402 (diff)
lkft: add some workaround to suppport python3 too
Signed-off-by: Yongqin Liu <yongqin.liu@linaro.org>
-rw-r--r--lcr/templatetags/escapesharp.py2
-rw-r--r--lcr/templatetags/startswith.py2
-rw-r--r--lcr/utils.py6
-rw-r--r--lkft/lkft_config.py22
-rw-r--r--lkft/management/commands/lkftreport.py62
5 files changed, 53 insertions, 41 deletions
diff --git a/lcr/templatetags/escapesharp.py b/lcr/templatetags/escapesharp.py
index c45c8ea..ce07b0a 100644
--- a/lcr/templatetags/escapesharp.py
+++ b/lcr/templatetags/escapesharp.py
@@ -5,6 +5,6 @@ register = template.Library()
@register.filter('escapesharp')
def escapesharp(text):
- if isinstance(text, basestring):
+ if isinstance(text, str):
return text.replace('#', '%23')
return None
diff --git a/lcr/templatetags/startswith.py b/lcr/templatetags/startswith.py
index 48c4ef2..ad08d6b 100644
--- a/lcr/templatetags/startswith.py
+++ b/lcr/templatetags/startswith.py
@@ -5,6 +5,6 @@ register = template.Library()
@register.filter('startswith')
def startswith(text, starts):
- if isinstance(text, basestring):
+ if isinstance(text, str):
return text.startswith(starts)
return False
diff --git a/lcr/utils.py b/lcr/utils.py
index 131cdb3..060e4c1 100644
--- a/lcr/utils.py
+++ b/lcr/utils.py
@@ -30,7 +30,11 @@ def download_urllib(url, path):
else:
sys.stdout.write("\r %.2f%%" % per)
sys.stdout.flush()
- urllib.urlretrieve(url, path, Schedule)
+ try:
+ urllib.urlretrieve(url, path, Schedule)
+ except AttributeError:
+ urllib.request.urlretrieve(url, path, Schedule)
+
if not check_dict['file_not_exist']:
logger.info("File is saved to %s" % path)
return check_dict['file_not_exist']
diff --git a/lkft/lkft_config.py b/lkft/lkft_config.py
index d105ac5..34eefd2 100644
--- a/lkft/lkft_config.py
+++ b/lkft/lkft_config.py
@@ -104,13 +104,15 @@ citrigger_lkft_rcs = {
def find_expect_cibuilds(trigger_name=None):
if not trigger_name:
- return None
+ return set([])
lkft_builds = citrigger_lkft.get(trigger_name)
lkft_rc_builds = citrigger_lkft_rcs.get(trigger_name)
if lkft_builds is not None:
return set(lkft_builds.values())
- else:
+ elif lkft_rc_builds is not None:
return set(lkft_rc_builds.values())
+ else:
+ return set([])
def get_ci_trigger_info(project=None):
if not project.get('full_name'):
@@ -180,11 +182,19 @@ def get_kver_with_pname_env(prj_name='', env=''):
def get_url_content(url=None):
- import urllib2
try:
- response = urllib2.urlopen(url)
- return response.read()
- except urllib2.HTTPError:
+ # For Python 3.0 and later
+ from urllib.request import urlopen
+ from urllib.error import HTTPError
+ except ImportError:
+ # Fall back to Python 2's urllib2
+ from urllib2 import urlopen
+ from urllib2 import HTTPError
+
+ try:
+ response = urlopen(url)
+ return response.read().decode('utf-8')
+ except HTTPError:
pass
return None
diff --git a/lkft/management/commands/lkftreport.py b/lkft/management/commands/lkftreport.py
index 6ebeb9e..ef72c6a 100644
--- a/lkft/management/commands/lkftreport.py
+++ b/lkft/management/commands/lkftreport.py
@@ -10,7 +10,6 @@ import datetime
import json
import os
import re
-import urllib2
import yaml
from django.core.management.base import BaseCommand, CommandError
@@ -371,7 +370,7 @@ class Command(BaseCommand):
# print out the reports
- print "########## REPORTS FOR KERNEL CHANGES#################"
+ print("########## REPORTS FOR KERNEL CHANGES#################")
for kernel_change_report in total_reports:
kernel_change = kernel_change_report.get('kernel_change')
trigger_build = kernel_change_report.get('trigger_build')
@@ -381,60 +380,60 @@ class Command(BaseCommand):
trigger_starttimestamp = trigger_build['start_timestamp']
finished_timestamp = kernel_change_report.get('finished_timestamp')
if status == "ALL_COMPLETED":
- print "%s started at %s, %s ago, took %s" % (kernel_change, trigger_starttimestamp, timesince(trigger_starttimestamp), finished_timestamp - trigger_starttimestamp)
+ print("%s started at %s, %s ago, took %s" % (kernel_change, trigger_starttimestamp, timesince(trigger_starttimestamp), finished_timestamp - trigger_starttimestamp))
else:
- print "%s started at %s, %s ago, %s" % (kernel_change, trigger_starttimestamp, timesince(trigger_starttimestamp), status)
+ print("%s started at %s, %s ago, %s" % (kernel_change, trigger_starttimestamp, timesince(trigger_starttimestamp), status))
- print "\t Reports for CI Builds:"
+ print("\t Reports for CI Builds:")
for build in jenkins_ci_builds:
dbci_build = build.get('dbci_build')
if build.get('status') == 'INPROGRESS':
- print "\t\t %s#%s %s, started at %s, %s ago" % (dbci_build.name, dbci_build.number,
+ print("\t\t %s#%s %s, started at %s, %s ago" % (dbci_build.name, dbci_build.number,
build.get('status'),
build.get('start_timestamp'),
- timesince(build.get('start_timestamp')))
+ timesince(build.get('start_timestamp'))))
else:
- print "\t\t %s#%s %s, started at %s, %s ago, took %s" % (dbci_build.name, dbci_build.number,
+ print("\t\t %s#%s %s, started at %s, %s ago, took %s" % (dbci_build.name, dbci_build.number,
build.get('status'),
build.get('start_timestamp'),
timesince(build.get('start_timestamp')),
- build.get('duration'))
+ build.get('duration')))
queued_ci_builds = kernel_change_report.get('queued_ci_builds')
for build in queued_ci_builds:
- inqueuesince = qa_report_api.get_aware_datetime_from_timestamp(int(build.get('inQueueSince')/1000))
+ inqueuesince = datetime.datetime.fromtimestamp(int(build.get('inQueueSince')/1000), tz=timezone.utc)
#duration = datetime_now - inqueuesince
- print "\t\t %s: still in queue since %s ago" % (build.get('build_name'), timesince(inqueuesince))
+ print("\t\t %s: still in queue since %s ago" % (build.get('build_name'), timesince(inqueuesince)))
not_reported_ci_builds = kernel_change_report.get('not_reported_ci_builds')
for build in not_reported_ci_builds:
- print "\t\t %s: not reported" % (str(build))
+ print("\t\t %s: not reported" % (str(build)))
diabled_ci_builds = kernel_change_report.get('diabled_ci_builds')
for build in diabled_ci_builds:
- print "\t\t %s: disabled" % (str(build))
+ print("\t\t %s: disabled" % (str(build)))
- print "\t Summary of Projects Status:"
+ print("\t Summary of Projects Status:")
for build in qa_report_builds:
qa_report_project = build.get('qa_report_project')
if build.get('build_status') == "JOBSCOMPLETED":
- print "\t\t %s %s, created at %s, %s ago, took %s" % (qa_report_project.get('full_name'),
+ print("\t\t %s %s, created at %s, %s ago, took %s" % (qa_report_project.get('full_name'),
build.get('build_status'),
build.get('created_at'),
timesince(build.get('created_at')),
- build.get('duration'))
+ build.get('duration')))
else:
- print "\t\t %s %s, created at %s, %s ago" % (qa_report_project.get('full_name'),
+ print("\t\t %s %s, created at %s, %s ago" % (qa_report_project.get('full_name'),
build.get('build_status'),
build.get('created_at'),
- timesince(build.get('created_at')))
+ timesince(build.get('created_at'))))
numbers_of_result = build.get('numbers_of_result')
str_numbers = "\t\t\t Summary: modules_total=%s, modules_done=%s, number_total=%s, number_failed=%s"
- print str_numbers % (numbers_of_result.get('modules_total'),
+ print(str_numbers % (numbers_of_result.get('modules_total'),
numbers_of_result.get('modules_done'),
numbers_of_result.get('number_total'),
- numbers_of_result.get('number_failed'))
+ numbers_of_result.get('number_failed')))
str_numbers = "\t\t\t %s: modules_total=%s, modules_done=%s, number_total=%s, number_failed=%s"
final_jobs = build.get('final_jobs')
def get_job_name(item):
@@ -445,33 +444,32 @@ class Command(BaseCommand):
job_name = job.get('name')
numbers_of_result = job.get('numbers')
if numbers_of_result is not None:
- print str_numbers % ("%s#%s %s" % (job_name, job.get('job_id'), job.get('job_status')),
+ print(str_numbers % ("%s#%s %s" % (job_name, job.get('job_id'), job.get('job_status')),
numbers_of_result.get('modules_total'),
numbers_of_result.get('modules_done'),
numbers_of_result.get('number_total'),
- numbers_of_result.get('number_failed'))
+ numbers_of_result.get('number_failed')))
-
- print "\t Failures and Bugs:"
+ print("\t Failures and Bugs:")
for build in qa_report_builds:
qa_report_project = build.get('qa_report_project')
- print "\t\t %s %s %s" % (qa_report_project.get('full_name'),
+ print("\t\t %s %s %s" % (qa_report_project.get('full_name'),
build.get('build_status'),
- build.get('created_at'))
+ build.get('created_at')))
classification = build.get('classification')
bugs_reproduced = classification.get('bugs_reproduced')
bugs_not_reproduced = classification.get('bugs_not_reproduced')
new_failures = classification.get('new_failures')
- print "\t\t\t Bugs Reproduced: %s" % (len(bugs_reproduced))
+ print("\t\t\t Bugs Reproduced: %s" % (len(bugs_reproduced)))
for bug in bugs_reproduced:
- print "\t\t\t\t %s %s %s" % (bug.id, bug.summary, bug.status)
+ print("\t\t\t\t %s %s %s" % (bug.id, bug.summary, bug.status))
- print "\t\t\t Bugs Not Reproduced: %s" % (len(bugs_not_reproduced))
+ print("\t\t\t Bugs Not Reproduced: %s" % (len(bugs_not_reproduced)))
for bug in bugs_not_reproduced:
- print "\t\t\t\t %s %s %s" % (bug.id, bug.summary, bug.status)
+ print("\t\t\t\t %s %s %s" % (bug.id, bug.summary, bug.status))
- print "\t\t\t Failures Not Reported: %s" % (len(new_failures))
+ print("\t\t\t Failures Not Reported: %s" % (len(new_failures)))
for failure in new_failures:
- print "\t\t\t\t %s %s: %s" % (failure.get('module_name'), failure.get('test_name'), failure.get('message'))
+ print("\t\t\t\t %s %s: %s" % (failure.get('module_name'), failure.get('test_name'), failure.get('message')))