diff --git a/repoapi/conf.py b/repoapi/conf.py
new file mode 100644
index 0000000..2ff6406
--- /dev/null
+++ b/repoapi/conf.py
@@ -0,0 +1,21 @@
+# Copyright (C) 2020 The Sipwise Team - http://sipwise.com
+#
+# This program is free software: you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program. If not, see .
+from django.conf import settings # noqa
+from appconf import AppConf
+
+
+class RepoAPIConf(AppConf):
+ class Meta:
+ prefix = "repoapi"
diff --git a/repoapi/settings/common.py b/repoapi/settings/common.py
index 9523902..82be4cf 100644
--- a/repoapi/settings/common.py
+++ b/repoapi/settings/common.py
@@ -43,7 +43,7 @@ INSTALLED_APPS = [
"build.apps.ReleaseConfig",
]
-MIDDLEWARE_CLASSES = (
+MIDDLEWARE = (
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
diff --git a/repoapi/tasks.py b/repoapi/tasks.py
index 2c2e519..878e9b8 100644
--- a/repoapi/tasks.py
+++ b/repoapi/tasks.py
@@ -1,28 +1,31 @@
-# Copyright (C) 2016 The Sipwise Team - http://sipwise.com
-
+# Copyright (C) 2016-2020 The Sipwise Team - http://sipwise.com
+#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
-
+#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
-
+#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see .
-from __future__ import absolute_import
-from datetime import timedelta
import json
import logging
+from datetime import timedelta
from os.path import basename
+
from celery import shared_task
-from django.conf import settings
from django.apps import apps
+
from .celery import jbi_parse_hotfix
-from .utils import jenkins_get_console, jenkins_get_artifact
-from .utils import jenkins_get_build, jenkins_get_env
+from .conf import settings
+from .utils import jenkins_get_artifact
+from .utils import jenkins_get_build
+from .utils import jenkins_get_console
+from .utils import jenkins_get_env
logger = logging.getLogger(__name__)
@@ -43,7 +46,7 @@ def get_jbi_files(jbi_id, jobname, buildnumber):
with open(path_build) as data_file:
data = json.load(data_file)
logger.debug("job_info:%s", data)
- for artifact in data['artifacts']:
+ for artifact in data["artifacts"]:
jbi_get_artifact.delay(jbi_id, jobname, buildnumber, artifact)
else:
logger.debug("skip artifacts download for jobname: %s", jobname)
@@ -52,7 +55,5 @@ def get_jbi_files(jbi_id, jobname, buildnumber):
@shared_task(ignore_result=True)
def jbi_purge(release, weeks):
JenkinsBuildInfo = apps.get_model("repoapi", "JenkinsBuildInfo")
- JenkinsBuildInfo.objects.purge_release(
- release,
- timedelta(weeks=weeks))
+ JenkinsBuildInfo.objects.purge_release(release, timedelta(weeks=weeks))
logger.info("purged release %s jbi older than %s weeks" % (release, weeks))
diff --git a/repoapi/utils.py b/repoapi/utils.py
index 1afaec0..4e0e83f 100644
--- a/repoapi/utils.py
+++ b/repoapi/utils.py
@@ -1,27 +1,25 @@
-# Copyright (C) 2015 The Sipwise Team - http://sipwise.com
-
+# Copyright (C) 2015-2020 The Sipwise Team - http://sipwise.com
+#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
-
+#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
-
+#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see .
-from __future__ import absolute_import
-
-from distutils.dir_util import mkpath
import logging
import os
import shutil
import subprocess
import urllib.request
-from urllib.error import HTTPError
-from django.conf import settings
+from distutils.dir_util import mkpath
+
+from .conf import settings
logger = logging.getLogger(__name__)
@@ -32,8 +30,9 @@ JBI_ENVVARS_URL = "{}/job/{}/{}/injectedEnvVars/api/json"
def executeAndReturnOutput(command, env=None):
- proc = subprocess.Popen(command, stdout=subprocess.PIPE,
- stderr=subprocess.PIPE, env=env)
+ proc = subprocess.Popen(
+ command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env
+ )
stdoutdata, stderrdata = proc.communicate()
logger.debug("%s", stdoutdata)
logger.debug("%s", stderrdata)
@@ -59,7 +58,7 @@ def openurl(url):
logger.debug("OK[%d] URL[%s]", response.getcode(), url)
return True
except urllib.error.HTTPError as e:
- logger.error('Error[%d] retrieving URL[%s]', e.getcode(), url)
+ logger.error("Error[%d] retrieving URL[%s]", e.getcode(), url)
except Exception:
logger.error("Fatal error retrieving URL[%s]", url)
@@ -67,9 +66,11 @@ def openurl(url):
def jenkins_remove_ppa(repo):
- url = "%s/job/remove-reprepro-codename/buildWithParameters?"\
- "token=%s&repository=%s" % \
- (settings.JENKINS_URL, settings.JENKINS_TOKEN, repo)
+ url = (
+ "%s/job/remove-reprepro-codename/buildWithParameters?"
+ "token=%s&repository=%s"
+ % (settings.JENKINS_URL, settings.JENKINS_TOKEN, repo)
+ )
if settings.DEBUG:
logger.debug("I would call %s", url)
else:
@@ -85,36 +86,21 @@ def _jenkins_get(url, base_path, filename):
def jenkins_get_console(jobname, buildnumber):
- url = JBI_CONSOLE_URL.format(
- settings.JENKINS_URL,
- jobname,
- buildnumber
- )
- base_path = os.path.join(settings.JBI_BASEDIR,
- jobname, str(buildnumber))
- return _jenkins_get(url, base_path, 'console.txt')
+ url = JBI_CONSOLE_URL.format(settings.JENKINS_URL, jobname, buildnumber)
+ base_path = os.path.join(settings.JBI_BASEDIR, jobname, str(buildnumber))
+ return _jenkins_get(url, base_path, "console.txt")
def jenkins_get_build(jobname, buildnumber):
- url = JBI_BUILD_URL.format(
- settings.JENKINS_URL,
- jobname,
- buildnumber
- )
- base_path = os.path.join(settings.JBI_BASEDIR,
- jobname, str(buildnumber))
- return _jenkins_get(url, base_path, 'build.json')
+ url = JBI_BUILD_URL.format(settings.JENKINS_URL, jobname, buildnumber)
+ base_path = os.path.join(settings.JBI_BASEDIR, jobname, str(buildnumber))
+ return _jenkins_get(url, base_path, "build.json")
def jenkins_get_env(jobname, buildnumber):
- url = JBI_ENVVARS_URL.format(
- settings.JENKINS_URL,
- jobname,
- buildnumber
- )
- base_path = os.path.join(settings.JBI_BASEDIR,
- jobname, str(buildnumber))
- return _jenkins_get(url, base_path, 'envVars.json')
+ url = JBI_ENVVARS_URL.format(settings.JENKINS_URL, jobname, buildnumber)
+ base_path = os.path.join(settings.JBI_BASEDIR, jobname, str(buildnumber))
+ return _jenkins_get(url, base_path, "envVars.json")
def jenkins_get_artifact(jobname, buildnumber, artifact_info):
@@ -122,10 +108,11 @@ def jenkins_get_artifact(jobname, buildnumber, artifact_info):
settings.JENKINS_URL,
jobname,
buildnumber,
- artifact_info["relativePath"]
+ artifact_info["relativePath"],
+ )
+ base_path = os.path.join(
+ settings.JBI_BASEDIR, jobname, str(buildnumber), "artifact"
)
- base_path = os.path.join(settings.JBI_BASEDIR,
- jobname, str(buildnumber), 'artifact')
return _jenkins_get(url, base_path, artifact_info["fileName"])
@@ -134,7 +121,7 @@ def workfront_note_send(_id, message):
"/usr/bin/workfront-jenkins-update",
"--credfile=%s" % settings.WORKFRONT_CREDENTIALS,
"--taskid=%s" % _id,
- '--message="%s"' % message
+ '--message="%s"' % message,
]
logger.debug("workfront-jenkins-update command: %s", command)
res = executeAndReturnOutput(command)
@@ -145,16 +132,13 @@ def workfront_note_send(_id, message):
def get_next_release(branch):
- command = [
- "/usr/bin/meta-release-helper",
- "--next-release",
- branch
- ]
+ command = ["/usr/bin/meta-release-helper", "--next-release", branch]
logger.debug("meta-release-helper command: %s", command)
res = executeAndReturnOutput(command)
if res[0] != 0:
logger.error(
- "can't find out next release version. %s. %s", res[1], res[2])
+ "can't find out next release version. %s. %s", res[1], res[2]
+ )
return None
val = res[1].rstrip()
if len(val) > 0:
@@ -175,7 +159,7 @@ def workfront_set_release_target(_id, release):
"/usr/bin/workfront-target-task",
"--credfile=%s" % settings.WORKFRONT_CREDENTIALS,
"--taskid=%s" % _id,
- '--release=%s' % release
+ "--release=%s" % release,
]
logger.debug("workfront-target-task command: %s", command)
res = executeAndReturnOutput(command)
diff --git a/tox.ini b/tox.ini
index b01c722..7bec2ae 100644
--- a/tox.ini
+++ b/tox.ini
@@ -11,3 +11,4 @@ filterwarnings =
[coverage:run]
data_file = ${RESULTS}/.coverage
+omit = repoapi/settings/*