Repository :
http://git.fedorahosted.org/cgit/copr.git
On branch : dist-git
---------------------------------------------------------------
commit 6fc09d6fe163a88e167af96704eba3d2dd4c798e
Author: Adam Samalik <asamalik(a)redhat.com>
Date: Wed Jun 24 19:17:58 2015 +0200
new build logic functions + helper
---------------------------------------------------------------
frontend/coprs_frontend/coprs/helpers.py | 11 +++++++
.../coprs_frontend/coprs/logic/builds_logic.py | 32 ++++++++++++++++++++
.../coprs/views/backend_ns/backend_general.py | 8 +++--
3 files changed, 48 insertions(+), 3 deletions(-)
diff --git a/frontend/coprs_frontend/coprs/helpers.py
b/frontend/coprs_frontend/coprs/helpers.py
index c962f71..b9fb8e4 100644
--- a/frontend/coprs_frontend/coprs/helpers.py
+++ b/frontend/coprs_frontend/coprs/helpers.py
@@ -150,6 +150,17 @@ def chroot_to_branch(chroot):
os = "el"
return "{}{}".format(os, version)
+def branch_to_os_version(branch):
+ os = None
+ version = None
+ if branch[0] == "f":
+ os = "fedora"
+ version = branch[1:]
+ elif branch[:4] == "epel":
+ os = "epel"
+ version = branch[4:]
+ return os, version
+
def parse_package_name(pkg):
"""
diff --git a/frontend/coprs_frontend/coprs/logic/builds_logic.py
b/frontend/coprs_frontend/coprs/logic/builds_logic.py
index dfa88d4..1426a8a 100644
--- a/frontend/coprs_frontend/coprs/logic/builds_logic.py
+++ b/frontend/coprs_frontend/coprs/logic/builds_logic.py
@@ -1,4 +1,6 @@
from collections import defaultdict
+import urlparse
+import shutil
import json
import os
import pprint
@@ -215,6 +217,36 @@ class BuildsLogic(object):
return build
@classmethod
+ def get_chroots_from_dist_git_task_id(cls, task_id):
+ """
+ Returns a list of BuildChroots identified with task_id
+ task_id consists of a name of git branch + build id
+ Example: 42-f22 -> build id 42, chroots fedora-22-*
+ """
+ build_id, branch = task_id.split("-")
+ build = cls.get_by_id(build_id)
+ build_chroots = build.build_chroots
+ os, version = helpers.branch_to_os_version(branch)
+ chroot_halfname = "{}-{}".format(os, version)
+ matching = [ch for ch in build_chroots if chroot_halfname in ch.name]
+ return matching
+
+
+ @classmethod
+ def delete_local_srpm(cls, build):
+ """
+ Deletes the source rpm locally stored for upload (if exists)
+ """
+ data = urlparse.urlparse(build.pkgs)
+ service = data.netloc
+
+ # is it hosted on the copr frontend?
+ if service == app.config["PUBLIC_COPR_HOSTNAME"]:
+ tmp = data.path.split("/")[-2]
+ storage_path = app.config["SRPM_STORAGE_DIR"]
+ shutil.rmtree(os.path.join(storage_path, tmp))
+
+ @classmethod
def update_state_from_dict(cls, build, upd_dict):
log.info("Updating build: {} by: {}".format(build.id, upd_dict))
if "chroot" in upd_dict:
diff --git a/frontend/coprs_frontend/coprs/views/backend_ns/backend_general.py
b/frontend/coprs_frontend/coprs/views/backend_ns/backend_general.py
index 420cd90..5e1086e 100644
--- a/frontend/coprs_frontend/coprs/views/backend_ns/backend_general.py
+++ b/frontend/coprs_frontend/coprs/views/backend_ns/backend_general.py
@@ -63,12 +63,14 @@ def dist_git_upload_completed():
ch.git_hash = git_hash
build = build_chroots[0].build
- if not build.has_uploading_chroot():
+ if not build.has_uploading_chroot:
BuildsLogic.delete_local_srpm(build)
- result["updated"] = True
+ db.session.commit()
+
+ result.update({"updated": True})
- return result
+ return flask.jsonify(result)
@backend_ns.route("/waiting/")
@misc.backend_authenticated