[copr] master: [backend] update createrepo tests (9e10d7c)
by vgologuz@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit 9e10d7c9ca6eec3dcab1440176c1031bd15d9ddd
Author: Valentin Gologuzov <vgologuz(a)redhat.com>
Date: Mon Jun 22 18:47:01 2015 +0200
[backend] update createrepo tests
>---------------------------------------------------------------
backend/tests/test_createrepo.py | 197 ++++++++++++++++++++++----------------
1 files changed, 113 insertions(+), 84 deletions(-)
diff --git a/backend/tests/test_createrepo.py b/backend/tests/test_createrepo.py
index 5959a8b..7484729 100644
--- a/backend/tests/test_createrepo.py
+++ b/backend/tests/test_createrepo.py
@@ -4,9 +4,11 @@ import tarfile
import tempfile
import shutil
import time
+import pytest
import six
+
if six.PY3:
from unittest import mock
from unittest.mock import MagicMock
@@ -15,8 +17,8 @@ else:
from mock import MagicMock
-from backend.createrepo import createrepo, createrepo_unsafe, add_appdata
-
+from backend.createrepo import createrepo, createrepo_unsafe, add_appdata, run_cmd_unsafe
+from backend.exceptions import CreateRepoError
@mock.patch('backend.createrepo.createrepo_unsafe')
@mock.patch('backend.createrepo.add_appdata')
@@ -51,7 +53,18 @@ def test_createrepo_conditional_false(mc_client, mc_create_unsafe):
assert mc_create_unsafe.call_args == mock.call('/tmp/', None, dest_dir='devel', base_url=base_url)
-(a)mock.patch('backend.createrepo.Popen')
+(a)pytest.yield_fixture
+def mc_popen():
+ with mock.patch('backend.createrepo.Popen') as handle:
+ yield handle
+
+
+(a)pytest.yield_fixture
+def mc_run_cmd_unsafe():
+ with mock.patch('backend.createrepo.run_cmd_unsafe') as handle:
+ yield handle
+
+
class TestCreaterepo(object):
def setup_method(self, method):
self.tmp_dir_name = self.make_temp_dir()
@@ -83,44 +96,71 @@ class TestCreaterepo(object):
root_tmp_dir = tempfile.gettempdir()
subdir = "test_createrepo_{}".format(time.time())
self.tmp_dir_name = os.path.join(root_tmp_dir, subdir)
-
os.mkdir(self.tmp_dir_name)
-
return self.tmp_dir_name
- def test_run_cmd_unsafe(self, mc_popen):
- # todo: implement & simplify createrepo_unsafe tests
- pass
+ #def test_add_appdata(self, mc_run_cmd_unsafe):
+ # todo: implement, need to test behaviour with/withou produced appstream files
+ # for lock in [None, MagicMock()]:
+ # add_appdata(self.tmp_dir_name, self.username, self.projectname, lock=lock)
+ # print mc_run_cmd_unsafe.call_args_list
+ # mc_run_cmd_unsafe.reset()
- def disabled_test_add_appdata(self, mc_popen):
- # todo: re-enable
+ def test_run_cmd_unsafe_ok(self, mc_popen):
+ cmd = "foo --bar"
+ mc_popen.return_value.communicate.return_value = ("stdout", "stderr")
mc_popen.return_value.returncode = 0
- mc_popen.return_value.communicate.return_value = "stdout", ""
- add_appdata(self.tmp_dir_name, self.username, self.projectname)
- expected = [
- mock.call([
- '/usr/bin/appstream-builder',
- '--api-version=0.8',
- '--verbose',
- '--add-cache-id',
- # '--min-icon-size=48',
- # '--enable-hidpi',
- # '--include-failed',
- '--max-threads=4',
- '--temp-dir={}/tmp'.format(self.tmp_dir_name),
- '--cache-dir={}/cache'.format(self.tmp_dir_name),
- '--packages-dir={}'.format(self.tmp_dir_name),
- '--output-dir={}/appdata'.format(self.tmp_dir_name),
- '--basename=appstream',
- '--origin={}/{}'.format(self.username, self.projectname)], stderr=-1, stdout=-1),
- mock.call([
- '/usr/bin/modifyrepo_c',
- '--no-compress',
- '{}/appdata/appstream.xml.gz'.format(self.tmp_dir_name),
- '{}/repodata'.format(self.tmp_dir_name)], stderr=-1, stdout=-1)]
- assert expected == mc_popen.call_args_list
-
- def test_createrepo_unsafe_lock_usage(self, mc_popen):
+
+ for lock in [None, MagicMock()]:
+ assert run_cmd_unsafe(cmd, lock) == "stdout"
+ assert mc_popen.call_args[0][0] == ["foo", "--bar"]
+ mc_popen.reset()
+
+ def test_run_cmd_unsafe_err_popen(self, mc_popen):
+ cmd = "foo --bar"
+ mc_popen.side_effect = IOError()
+
+ for lock in [None, MagicMock()]:
+ with pytest.raises(CreateRepoError) as err:
+ run_cmd_unsafe(cmd, lock) == "stdout"
+
+ assert err.value.cmd == cmd
+ assert mc_popen.call_args[0][0] == ["foo", "--bar"]
+ mc_popen.reset()
+
+ def test_run_cmd_unsafe_err_return_code(self, mc_popen):
+ cmd = "foo --bar"
+ mc_popen.return_value.communicate.return_value = ("stdout", "stderr")
+ mc_popen.return_value.returncode = 1
+
+ for lock in [None, MagicMock()]:
+ with pytest.raises(CreateRepoError) as err:
+ run_cmd_unsafe(cmd, lock) == "stdout"
+
+ assert err.value.cmd == cmd
+ assert err.value.stdout == "stdout"
+ assert err.value.stderr == "stderr"
+ assert err.value.exit_code == 1
+ assert mc_popen.call_args[0][0] == ["foo", "--bar"]
+ mc_popen.reset()
+
+ def test_run_cmd_unsafe_err_communicate(self, mc_popen):
+ cmd = "foo --bar"
+ mc_handle = MagicMock()
+ mc_popen.return_value = MagicMock()
+ mc_handle.returncode = 0
+ mc_handle.side_effect = RuntimeError()
+
+ for lock in [None, MagicMock()]:
+ with pytest.raises(CreateRepoError) as err:
+ run_cmd_unsafe(cmd, lock) == "stdout"
+
+ assert err.value.cmd == cmd
+ assert mc_popen.call_args[0][0] == ["foo", "--bar"]
+ mc_popen.reset()
+
+ def test_run_cmd_unsafe_lock_usage(self, mc_popen):
+ cmd = "foo --bar"
mocked_lock = MagicMock()
self.shared_state = dict(in_lock=False, lock_status=None)
@@ -141,23 +181,20 @@ class TestCreaterepo(object):
mc_popen.return_value.communicate.return_value = ("", "")
mc_popen.return_value.returncode = 0
- createrepo_unsafe(self.tmp_dir_name, lock=mocked_lock)
+ run_cmd_unsafe(cmd, lock=mocked_lock)
assert self.shared_state["lock_status"]
self.shared_state["lock_status"] = None
- createrepo_unsafe(self.tmp_dir_name, lock=None)
+ run_cmd_unsafe(cmd, lock=None)
assert not self.shared_state["lock_status"]
- def disabled_test_createrepo_generated_commands_existing_repodata(self, mc_popen):
- # todo: re-enable
- mc_popen.return_value.communicate.return_value = ("", "")
- mc_popen.return_value.returncode = 0
+ def test_createrepo_generated_commands_existing_repodata(self, mc_run_cmd_unsafe):
path_epel_5 = os.path.join(self.tmp_dir_name, "epel-5")
- expected_epel_5 = ['/usr/bin/createrepo_c', '--database',
- '--ignore-lock', '--update', '-s', 'sha', '--checksum', 'md5', path_epel_5]
+ expected_epel_5 = ('/usr/bin/createrepo_c --database '
+ '--ignore-lock --update -s sha --checksum md5 ' + path_epel_5)
path_fedora = os.path.join(self.tmp_dir_name, "fedora-21")
- expected_fedora = ['/usr/bin/createrepo_c', '--database',
- '--ignore-lock', '--update', path_fedora]
+ expected_fedora = ('/usr/bin/createrepo_c --database '
+ '--ignore-lock --update ' + path_fedora)
for path, expected in [(path_epel_5, expected_epel_5), (path_fedora, expected_fedora)]:
os.makedirs(path)
@@ -167,21 +204,18 @@ class TestCreaterepo(object):
handle.write("1")
createrepo_unsafe(path, None)
- assert mc_popen.call_args == mock.call(expected, stderr=-1, stdout=-1)
+ assert mc_run_cmd_unsafe.call_args[0][0] == expected
- def disabled_test_createrepo_devel_generated_commands_existing_repodata(self, mc_popen):
- # todo: re-enable
- mc_popen.return_value.communicate.return_value = ("", "")
- mc_popen.return_value.returncode = 0
+ def test_createrepo_devel_generated_commands_existing_repodata(self, mc_run_cmd_unsafe):
path_epel_5 = os.path.join(self.tmp_dir_name, "epel-5")
- expected_epel_5 = ['/usr/bin/createrepo_c', '--database', '--ignore-lock',
- '-s', 'sha', '--checksum', 'md5',
- '--outputdir', os.path.join(path_epel_5, "devel"),
- '--baseurl', self.base_url, path_epel_5]
+ expected_epel_5 = ("/usr/bin/createrepo_c --database --ignore-lock "
+ "-s sha --checksum md5 "
+ "--outputdir " + os.path.join(path_epel_5, "devel") + " "
+ "--baseurl " + self.base_url + " " + path_epel_5)
path_fedora = os.path.join(self.tmp_dir_name, "fedora-21")
- expected_fedora = ['/usr/bin/createrepo_c', '--database', '--ignore-lock',
- '--outputdir', os.path.join(path_fedora, "devel"),
- '--baseurl', self.base_url, path_fedora]
+ expected_fedora = ("/usr/bin/createrepo_c --database --ignore-lock "
+ "--outputdir " + os.path.join(path_fedora, "devel") + " "
+ "--baseurl " + self.base_url + " " + path_fedora)
for path, expected in [(path_epel_5, expected_epel_5), (path_fedora, expected_fedora)]:
os.makedirs(path)
@@ -191,37 +225,32 @@ class TestCreaterepo(object):
handle.write("1")
createrepo_unsafe(path, lock=None, base_url=self.base_url, dest_dir="devel")
- assert mc_popen.call_args == mock.call(expected, stderr=-1, stdout=-1)
-
- def disabled_test_createrepo_devel_generated_commands(self, mc_popen):
- # todo: re-enable
+ assert mc_run_cmd_unsafe.call_args[0][0] == expected
- mc_popen.return_value.communicate.return_value = ("", "")
- mc_popen.return_value.returncode = 0
+ def test_createrepo_devel_generated_commands(self, mc_run_cmd_unsafe):
path_epel_5 = os.path.join(self.tmp_dir_name, "epel-5")
- expected_epel_5 = ['/usr/bin/createrepo_c', '--database', '--ignore-lock',
- '-s', 'sha', '--checksum', 'md5',
- '--outputdir', os.path.join(path_epel_5, "devel"),
- '--baseurl', self.base_url, path_epel_5]
+ expected_epel_5 = ("/usr/bin/createrepo_c --database --ignore-lock "
+ "-s sha --checksum md5 "
+ "--outputdir " + os.path.join(path_epel_5, "devel") + " "
+ "--baseurl " + self.base_url + " " + path_epel_5)
path_fedora = os.path.join(self.tmp_dir_name, "fedora-21")
- expected_fedora = ['/usr/bin/createrepo_c', '--database', '--ignore-lock',
- '--outputdir', os.path.join(path_fedora, "devel"),
- '--baseurl', self.base_url, path_fedora]
+ expected_fedora = ("/usr/bin/createrepo_c --database --ignore-lock "
+ "--outputdir " + os.path.join(path_fedora, "devel") + " "
+ "--baseurl " + self.base_url + " " + path_fedora)
for path, expected in [(path_epel_5, expected_epel_5), (path_fedora, expected_fedora)]:
os.makedirs(path)
createrepo_unsafe(path, lock=None, base_url=self.base_url, dest_dir="devel")
assert os.path.exists(os.path.join(path, "devel"))
- assert mc_popen.call_args == mock.call(expected, stderr=-1, stdout=-1)
- #
- # def test_createrepo_devel_creates_folder(self, mc_popen):
- #
- # mc_popen.return_value.communicate.return_value = ("", "")
- # path_epel_5 = os.path.join(self.tmp_dir_name, "epel-5")
- # path_fedora = os.path.join(self.tmp_dir_name, "fedora-21")
- #
- # for path in [path_epel_5, path_fedora]:
- # os.makedirs(path)
- #
- # createrepo_unsafe(path, lock=None, base_url=self.base_url, dest_dir="devel")
- # assert os.path.exists(os.path.join(path, "devel"))
+ assert mc_run_cmd_unsafe.call_args[0][0] == expected
+ # assert mc_popen.call_args == mock.call(expected, stderr=-1, stdout=-1)
+
+ def test_createrepo_devel_creates_folder(self, mc_run_cmd_unsafe):
+ path_epel_5 = os.path.join(self.tmp_dir_name, "epel-5")
+ path_fedora = os.path.join(self.tmp_dir_name, "fedora-21")
+
+ for path in [path_epel_5, path_fedora]:
+ os.makedirs(path)
+
+ createrepo_unsafe(path, lock=None, base_url=self.base_url, dest_dir="devel")
+ assert os.path.exists(os.path.join(path, "devel"))
8 years, 10 months
[copr] dist-git: fix branch_to_os_version for el6 (8e069b8)
by asamalik@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : dist-git
>---------------------------------------------------------------
commit 8e069b8e19a8337320b205ff9f916a008856d75b
Author: Adam Samalik <asamalik(a)redhat.com>
Date: Tue Jun 30 14:29:56 2015 +0200
fix branch_to_os_version for el6
>---------------------------------------------------------------
frontend/coprs_frontend/coprs/helpers.py | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/frontend/coprs_frontend/coprs/helpers.py b/frontend/coprs_frontend/coprs/helpers.py
index b9fb8e4..9a0e880 100644
--- a/frontend/coprs_frontend/coprs/helpers.py
+++ b/frontend/coprs_frontend/coprs/helpers.py
@@ -156,7 +156,7 @@ def branch_to_os_version(branch):
if branch[0] == "f":
os = "fedora"
version = branch[1:]
- elif branch[:4] == "epel":
+ elif branch[:4] == "epel" or branch[:2] == "el":
os = "epel"
version = branch[4:]
return os, version
8 years, 10 months
[copr] dist-git: [backend] building from dist git (d2a2a66)
by asamalik@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : dist-git
>---------------------------------------------------------------
commit d2a2a668c392c18be3334a0d6361eef5793e69d5
Author: Adam Samalik <asamalik(a)redhat.com>
Date: Tue Jun 30 14:29:35 2015 +0200
[backend] building from dist git
>---------------------------------------------------------------
backend/backend/helpers.py | 10 ++++++++++
backend/backend/mockremote/builder.py | 28 ++++++++++++++++++++++++----
backend/conf/copr-be.conf.example | 2 ++
backend/conf/copr-be.local.conf | 2 ++
4 files changed, 38 insertions(+), 4 deletions(-)
diff --git a/backend/backend/helpers.py b/backend/backend/helpers.py
index 3755113..573ed8c 100644
--- a/backend/backend/helpers.py
+++ b/backend/backend/helpers.py
@@ -72,6 +72,16 @@ def _get_conf(cp, section, option, default, mode=None):
return path
return default
+def chroot_to_branch(chroot):
+ """
+ Get a git branch name from chroot. Follow the fedora naming standard.
+ """
+ os, version, arch = chroot.split("-")
+ if os == "fedora":
+ os = "f"
+ elif os == "epel" and int(version) <= 6:
+ os = "el"
+ return "{}{}".format(os, version)
class BackendConfigReader(object):
def __init__(self, config_file=None, ext_opts=None):
diff --git a/backend/backend/mockremote/builder.py b/backend/backend/mockremote/builder.py
index 9457156..459c970 100644
--- a/backend/backend/mockremote/builder.py
+++ b/backend/backend/mockremote/builder.py
@@ -8,6 +8,7 @@ from urlparse import urlparse
from ansible.runner import Runner
from backend.vm_manage import PUBSUB_INTERRUPT_BUILDER
from ..helpers import get_redis_connection
+from ..helpers import chroot_to_branch
from ..exceptions import BuilderError, BuilderTimeOutError, AnsibleCallError, AnsibleResponseError, VmError
@@ -183,6 +184,22 @@ class Builder(object):
ansible_test_results = self._run_ansible("/usr/bin/test -f {0}".format(successfile))
check_for_ans_error(ansible_test_results, self.hostname)
+ def download_job_pkg(self, pkg):
+ branch = chroot_to_branch(self.job.chroot)
+ repo_name = pkg.split("dist-git://")[1]
+ pkg_name = repo_name.split("/")[2]
+ repo_url = "{}/{}".format(self.opts.dist_git_url, repo_name)
+ self.log.info("Cloning Dist Git repo {}, branch {}".format(repo_url, branch))
+ results = self._run_ansible("cd /tmp && "
+ "git clone -b {branch} {repo}.git && "
+ "cd {pkg} && "
+ "fedpkg-copr srpm".format(
+ branch=branch, repo=repo_url, pkg=pkg_name))
+
+ local_pkg = list(results["contacted"].values())[0][u"stdout"].split("Wrote: ")[1]
+ self.log.info("Done: {}".format(local_pkg))
+ return local_pkg
+
def update_job_pkg_version(self, pkg):
self.log.info("Getting package information: version")
results = self._run_ansible("rpm -qp --qf \"%{{EPOCH}}\$\$%{{VERSION}}\$\$%{{RELEASE}}\" {}".format(pkg))
@@ -302,22 +319,25 @@ class Builder(object):
def build(self, pkg):
self.modify_mock_chroot_config()
+ # download the package to the builder
+ local_pkg = self.download_job_pkg(pkg)
+
# srpm version
- self.update_job_pkg_version(pkg)
+ self.update_job_pkg_version(local_pkg)
# construct the mockchain command
- buildcmd = self.gen_mockchain_command(pkg)
+ buildcmd = self.gen_mockchain_command(local_pkg)
# run the mockchain command async
ansible_build_results = self.run_build_and_wait(buildcmd) # now raises BuildTimeoutError
check_for_ans_error(ansible_build_results, self.hostname) # on error raises AnsibleResponseError
# we know the command ended successfully but not if the pkg built
# successfully
- self.check_build_success(pkg)
+ self.check_build_success(local_pkg)
build_out = get_ans_results(ansible_build_results, self.hostname).get("stdout", "")
build_details = {"pkg_version": self.job.pkg_version}
- self.collect_built_packages(build_details, pkg)
+ self.collect_built_packages(build_details, local_pkg)
return build_details, build_out
def download(self, pkg, destdir):
diff --git a/backend/conf/copr-be.conf.example b/backend/conf/copr-be.conf.example
index 1f9f768..ba3fe7a 100644
--- a/backend/conf/copr-be.conf.example
+++ b/backend/conf/copr-be.conf.example
@@ -11,6 +11,8 @@ frontend_base_url=http://copr-fe-dev.cloud.fedoraproject.org
# default is PASSWORDHERE but you really should change it. really.
frontend_auth=backend_password_from_fe_config
+dist_git_url=distgitvm.example.com
+
# comma-separated architectures
# default is i386,x86_64
#architectures=i386,x86_64
diff --git a/backend/conf/copr-be.local.conf b/backend/conf/copr-be.local.conf
index 7897e1c..854b31e 100644
--- a/backend/conf/copr-be.local.conf
+++ b/backend/conf/copr-be.local.conf
@@ -11,6 +11,8 @@ frontend_base_url=http://copr-fe-dev.cloud.fedoraproject.org
# default is PASSWORDHERE but you really should change it. really.
frontend_auth=backend_password_from_fe_config
+dist_git_url=distgitvm.example.com
+
# comma-separated architectures
# default is i386,x86_64
#architectures=i386,x86_64
8 years, 10 months
[copr] master: add small script to print queues (76836c4)
by Miroslav Suchý
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit 76836c4176c0e9a72a2e3be297009344c88c8f21
Author: Miroslav Suchý <msuchy(a)redhat.com>
Date: Thu Jun 25 16:08:35 2015 +0200
add small script to print queues
>---------------------------------------------------------------
backend/run/print_queues.py | 23 +++++++++++++++++++++++
1 files changed, 23 insertions(+), 0 deletions(-)
diff --git a/backend/run/print_queues.py b/backend/run/print_queues.py
new file mode 100755
index 0000000..0f93c63
--- /dev/null
+++ b/backend/run/print_queues.py
@@ -0,0 +1,23 @@
+#!/usr/bin/python
+# coding: utf-8
+
+NUM_QUEUES = 2
+
+import sys
+sys.path.append("/usr/share/copr/")
+
+from retask.task import Task
+from retask.queue import Queue
+
+for i in range(0, NUM_QUEUES):
+ print("## Queue {}".format(i))
+ q = Queue("copr-be-{}".format(i))
+ q.connect()
+ save_q = []
+ while q.length != 0:
+ task = q.dequeue()
+ print task.data
+ save_q.append(task)
+ for t in save_q:
+ q.enqueue(t)
+
8 years, 10 months
[copr] dist-git: [dist-git] basic rpm package (bfa97ca)
by asamalik@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : dist-git
>---------------------------------------------------------------
commit bfa97caeb735674f5d2c8b70669247f03c2f93b4
Author: Adam Samalik <asamalik(a)redhat.com>
Date: Thu Jun 25 15:08:43 2015 +0200
[dist-git] basic rpm package
>---------------------------------------------------------------
{backend => dist-git}/LICENSE | 0
dist-git/conf/copr-dist-git.conf.example | 8 +
.../__init__.py => dist-git/copr-dist-git.service | 0
dist-git/copr-dist-git.spec | 57 +++++++
dist-git/dist-git/__init__.py | 1 +
dist-git/dist-git/dist_git_importer.py | 162 ++++++++++++++++++++
dist-git/dist-git/helpers.py | 61 ++++++++
dist-git/dit_git_import.py | 91 -----------
8 files changed, 289 insertions(+), 91 deletions(-)
diff --git a/backend/LICENSE b/dist-git/LICENSE
similarity index 100%
copy from backend/LICENSE
copy to dist-git/LICENSE
diff --git a/dist-git/conf/copr-dist-git.conf.example b/dist-git/conf/copr-dist-git.conf.example
new file mode 100644
index 0000000..fec0824
--- /dev/null
+++ b/dist-git/conf/copr-dist-git.conf.example
@@ -0,0 +1,8 @@
+[dist-git]
+
+# default is http://coprs/rest/api
+frontend_base_url=http://copr-fe-dev.cloud.fedoraproject.org
+
+# must have same value as BACKEND_PASSWORD from have frontend in /etc/copr/copr.conf
+# default is PASSWORDHERE but you really should change it. really.
+frontend_auth=backend_password_from_fe_config
diff --git a/frontend/coprs_frontend/coprs/logic/__init__.py b/dist-git/copr-dist-git.service
similarity index 100%
copy from frontend/coprs_frontend/coprs/logic/__init__.py
copy to dist-git/copr-dist-git.service
diff --git a/dist-git/copr-dist-git.spec b/dist-git/copr-dist-git.spec
new file mode 100644
index 0000000..1930eb4
--- /dev/null
+++ b/dist-git/copr-dist-git.spec
@@ -0,0 +1,57 @@
+Name: copr-dist-git
+Version: 0.1
+Release: 1%{?dist}
+Summary: Copr services for Dist Git server
+
+Group: Applications/Productivity
+License: GPLv2+
+URL: https://fedorahosted.org/copr/
+# Source is created by
+# git clone https://git.fedorahosted.org/git/copr.git
+# cd copr/dist-git
+# tito build --tgz
+Source0: %{name}-%{version}.tar.gz
+
+BuildArch: noarch
+
+Requires: dist-git
+Requires: python-bunch
+Requires: python-requests
+
+%description
+COPR is lightweight build system. It allows you to create new project in WebUI
+and submit new builds and COPR will create yum repository from latest builds.
+
+This package contains Copr services for Dist Git server
+
+
+%prep
+%setup -q
+
+
+%build
+
+
+%install
+
+install -d %{buildroot}%{_datadir}/copr/dist-git
+install -d %{buildroot}%{_sysconfdir}/copr
+
+cp -a dist-git/* %{buildroot}%{_datadir}/copr/dist-git
+cp -a conf/copr-dist-git.conf.example %{buildroot}%{_sysconfdir}/copr/copr-dist-git.conf
+
+
+%check
+
+
+%files
+%license LICENSE
+
+%{_datadir}/copr/*
+%dir %{_sysconfdir}/copr
+%config(noreplace) %attr(0640, root, copr) %{_sysconfdir}/copr/copr-dist-git.conf
+
+
+%changelog
+* Thu Jun 25 2015 Adam Samalik <asamalik(a)redhat.com> 0.1
+- basic package
diff --git a/dist-git/dist-git/__init__.py b/dist-git/dist-git/__init__.py
new file mode 100644
index 0000000..f7f1a59
--- /dev/null
+++ b/dist-git/dist-git/__init__.py
@@ -0,0 +1 @@
+# Copr Dist Git
diff --git a/dist-git/dist-git/dist_git_importer.py b/dist-git/dist-git/dist_git_importer.py
new file mode 100644
index 0000000..060d126
--- /dev/null
+++ b/dist-git/dist-git/dist_git_importer.py
@@ -0,0 +1,162 @@
+import os
+import json
+import time
+import types
+import urllib
+import shutil
+import tempfile
+from requests import get
+from requests import post
+from pyrpkg import Commands
+from subprocess import call
+from pyrpkg.errors import rpkgError
+
+from helpers import DistGitConfigReader
+
+# Example usage:
+#
+# user = "asamalik"
+# project = "project-for-dist-git"
+# pkg_name = "devtoolset-3"
+# branch = "f20"
+# filepath = "/tmp/rh-php56-php-5.6.5-5.el7.src.rpm"
+#
+# git_hash = import_srpm(user, project, pkg_name, branch, filepath)
+
+
+def _my_upload(repo_dir, reponame, filename, filehash):
+ """
+ This is a replacement function for uploading sources.
+ Rpkg uses upload.cgi for uploading which doesn't make sense
+ on the local machine.
+ """
+ lookaside = "/var/lib/dist-git/cache/lookaside/pkgs/"
+ source = os.path.join(repo_dir, filename)
+ destination = os.path.join(lookaside, reponame, filename, filehash, filename)
+ if not os.path.exists(destination):
+ os.makedirs(os.path.dirname(destination))
+ shutil.copyfile(source, destination)
+
+def import_srpm(user, project, pkg, branch, filepath):
+ """
+ Imports a source rpm file into local dist git.
+ Repository name is in the Copr Style: user/project/package
+ filepath is a srpm file locally downloaded somewhere
+ """
+ # I need to use git via SSH because of gitolite as it manages
+ # permissions with it's hook that relies on gitolite console
+ # which is a default shell on SSH
+ gitbaseurl = "ssh://copr-dist-git@localhost/%(module)s"
+ tmp = tempfile.mkdtemp()
+ try:
+ repo_dir = os.path.join(tmp, pkg)
+
+ # use rpkg for importing the source rpm
+ commands = Commands(path =repo_dir,
+ lookaside ="",
+ lookasidehash ="md5",
+ lookaside_cgi ="",
+ gitbaseurl =gitbaseurl,
+ anongiturl ="",
+ branchre ="",
+ kojiconfig ="",
+ build_client ="")
+
+ # rpkg gets module_name as a basename of git url
+ # we use module_name as "username/projectname/packagename"
+ # basename is not working here - so I'm setting it manually
+ module = "{}/{}/{}".format(user, project, pkg)
+ commands.module_name = module
+ # rpkg calls upload.cgi script on the dist git server
+ # here, I just copy the source files manually with custom function
+ # I also add one parameter "repo_dir" to that function with this hack
+ commands.lookasidecache.upload = types.MethodType(_my_upload, repo_dir)
+
+ # clone the pkg repository into tmp directory
+ #module = "{}/{}/{}.git".format(user, project, pkg)
+ #giturl = gitbaseurl % {'module': module}
+ #cmd = ['git', 'clone', "-b", "f20", giturl]
+ #call(cmd, cwd=tmp)
+ commands.clone(module, tmp, branch)
+
+ # import the source rpm into git and save filenames of sources
+ uploadfiles = commands.import_srpm(filepath)
+
+ # save the source files into lookaside cache
+ commands.upload(uploadfiles, replace=True)
+
+ # git push
+ message = "Import of {}".format(os.path.basename(filepath))
+ #call(["git", "commit", "-m", message], cwd=repo_dir)
+ #call(["git", "push"], cwd=repo_dir)
+ try:
+ commands.commit(message)
+ commands.push()
+ except rpkgError:
+ pass
+ git_hash = commands.commithash
+ finally:
+ shutil.rmtree(tmp)
+ return git_hash
+
+
+class DistGitImporter():
+ def __init__(self):
+ self.config_reader = DistGitConfigReader()
+ self.opts = self.config_reader.read()
+
+ def run(self):
+ get_url = "{}/backend/uploading/".format(self.opts.frontend_base_url)
+ upload_url = "{}/backend/upload-completed/".format(self.opts.frontend_base_url)
+ auth = ("user",self.opts.frontend_auth)
+ headers = {"content-type": "application/json"}
+
+ tmp = tempfile.mkdtemp()
+ try:
+ while(True):
+ # get the data
+ r = get(get_url)
+ try:
+ task = r.json()["builds"][0]
+
+ task_id = task["task_id"]
+ user = task["user"]
+ project = task["project"]
+ package = task["package"]
+ branch = task["branch"]
+ package_url = task["package_url"]
+ except:
+ time.sleep(10)
+ continue
+
+ # make sure repos exist
+ reponame = "{}/{}/{}".format(user, project, package)
+ call(["/usr/share/dist-git/git_package.sh", reponame])
+ call(["/usr/share/dist-git/git_branch.sh", branch, reponame])
+
+ # download the package
+ filepath = os.path.join(tmp, os.path.basename(package_url))
+ urllib.urlretrieve(package_url, filepath)
+
+ # import it and delete the srpm
+ git_hash = import_srpm(user, project, package, branch, filepath)
+ os.remove(filepath)
+
+ # send a response
+ data = {"task_id": task_id,
+ "repo_name": reponame,
+ "git_hash": git_hash}
+ post(upload_url, auth=auth, data=json.dumps(data), headers=headers)
+ finally:
+ shutil.rmtree(tmp)
+
+def main():
+ importer = DistGitImporter()
+ try:
+ importer.run()
+ except KeyboardInterrupt:
+ return
+
+if __name__ == "__main__":
+ main()
+
diff --git a/dist-git/dist-git/helpers.py b/dist-git/dist-git/helpers.py
new file mode 100644
index 0000000..91fbb89
--- /dev/null
+++ b/dist-git/dist-git/helpers.py
@@ -0,0 +1,61 @@
+from bunch import Bunch
+import os
+import ConfigParser
+
+def _get_conf(cp, section, option, default, mode=None):
+ """
+ To make returning items from config parser less irritating
+
+ :param mode: convert obtained value, possible modes:
+ - None (default): do nothing
+ - "bool" or "boolean"
+ - "int"
+ - "float"
+ """
+
+ if cp.has_section(section) and cp.has_option(section, option):
+ if mode is None:
+ return cp.get(section, option)
+ elif mode in ["bool", "boolean"]:
+ return cp.getboolean(section, option)
+ elif mode == "int":
+ return cp.getint(section, option)
+ elif mode == "float":
+ return cp.getfloat(section, option)
+ elif mode == "path":
+ path = cp.get(section, option)
+ if path.startswith("~"):
+ path = os.path.expanduser(path)
+ path = os.path.abspath(path)
+ path = os.path.normpath(path)
+
+ return path
+ return default
+
+
+class DistGitConfigReader(object):
+ def __init__(self, config_file=None):
+ self.config_file = config_file or "/etc/copr/copr-dist-git.conf"
+
+ def read(self):
+ try:
+ opts = self._read_unsafe()
+ return opts
+
+ except ConfigParser.Error as e:
+ raise CoprBackendError(
+ "Error parsing config file: {0}: {1}".format(
+ self.config_file, e))
+
+ def _read_unsafe(self):
+ cp = ConfigParser.ConfigParser()
+ cp.read(self.config_file)
+
+ opts = Bunch()
+
+ opts.frontend_base_url = _get_conf(
+ cp, "dist-git", "frontend_base_url", "http://copr-fe")
+
+ opts.frontend_auth = _get_conf(
+ cp, "dist-git", "frontend_auth", "PASSWORDHERE")
+ return opts
diff --git a/dist-git/dit_git_import.py b/dist-git/dit_git_import.py
deleted file mode 100644
index 01731b9..0000000
--- a/dist-git/dit_git_import.py
+++ /dev/null
@@ -1,91 +0,0 @@
-import os
-import types
-import shutil
-import tempfile
-from pyrpkg import Commands
-from pyrpkg.errors import rpkgError
-
-# Example usage:
-#
-# user = "asamalik"
-# project = "project-for-dist-git"
-# pkg_name = "devtoolset-3"
-# branch = "f20"
-# filepath = "/tmp/rh-php56-php-5.6.5-5.el7.src.rpm"
-#
-# git_hash = import_srpm(user, project, pkg_name, branch, filepath)
-
-
-def _my_upload(repo_dir, reponame, filename, filehash):
- """
- This is a replacement function for uploading sources.
- Rpkg uses upload.cgi for uploading which doesn't make sense
- on the local machine.
- """
- lookaside = "/var/lib/dist-git/cache/lookaside/pkgs/"
- source = os.path.join(repo_dir, filename)
- destination = os.path.join(lookaside, reponame, filename, filehash, filename)
- if not os.path.exists(destination):
- os.makedirs(os.path.dirname(destination))
- shutil.copyfile(source, destination)
-
-def import_srpm(user, project, pkg, branch, filepath):
- """
- Imports a source rpm file into local dist git.
- Repository name is in the Copr Style: user/project/package
- filepath is a srpm file locally downloaded somewhere
- """
- # I need to use git via SSH because of gitolite as it manages
- # permissions with it's hook that relies on gitolite console
- # which is a default shell on SSH
- gitbaseurl = "ssh://frank@localhost/%(module)s"
- tmp = tempfile.mkdtemp()
- try:
- repo_dir = os.path.join(tmp, pkg)
-
- # use rpkg for importing the source rpm
- commands = Commands(path =repo_dir,
- lookaside ="",
- lookasidehash ="md5",
- lookaside_cgi ="",
- gitbaseurl =gitbaseurl,
- anongiturl ="",
- branchre ="",
- kojiconfig ="",
- build_client ="")
-
- # rpkg gets module_name as a basename of git url
- # we use module_name as "username/projectname/packagename"
- # basename is not working here - so I'm setting it manually
- module = "{}/{}/{}".format(user, project, pkg)
- commands.module_name = module
- # rpkg calls upload.cgi script on the dist git server
- # here, I just copy the source files manually with custom function
- # I also add one parameter "repo_dir" to that function with this hack
- commands.lookasidecache.upload = types.MethodType(_my_upload, repo_dir)
-
- # clone the pkg repository into tmp directory
- #module = "{}/{}/{}.git".format(user, project, pkg)
- #giturl = gitbaseurl % {'module': module}
- #cmd = ['git', 'clone', "-b", "f20", giturl]
- #call(cmd, cwd=tmp)
- commands.clone(module, tmp, branch)
-
- # import the source rpm into git and save filenames of sources
- uploadfiles = commands.import_srpm(filepath)
-
- # save the source files into lookaside cache
- commands.upload(uploadfiles, replace=True)
-
- # git push
- message = "Import of {}".format(os.path.basename(filepath))
- #call(["git", "commit", "-m", message], cwd=repo_dir)
- #call(["git", "push"], cwd=repo_dir)
- try:
- commands.commit(message)
- commands.push()
- except rpkgError:
- pass
- finally:
- shutil.rmtree(tmp)
- return commands.commithash
8 years, 10 months
[copr] dist-git: set dist-git:// url (d0c4906)
by asamalik@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : dist-git
>---------------------------------------------------------------
commit d0c4906258277c3fb9cf8fb4d65e03636907a965
Author: Adam Samalik <asamalik(a)redhat.com>
Date: Thu Jun 25 10:28:45 2015 +0200
set dist-git:// url
>---------------------------------------------------------------
.../coprs/templates/coprs/detail/build.html | 6 +++++-
.../coprs/views/backend_ns/backend_general.py | 10 ++++++++--
2 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/frontend/coprs_frontend/coprs/templates/coprs/detail/build.html b/frontend/coprs_frontend/coprs/templates/coprs/detail/build.html
index 9c2f8f3..f9cc5d1 100644
--- a/frontend/coprs_frontend/coprs/templates/coprs/detail/build.html
+++ b/frontend/coprs_frontend/coprs/templates/coprs/detail/build.html
@@ -100,7 +100,11 @@
<dt> Source: </dt>
<dd>
{% if build.pkgs is not none %}
- <dd> <a href="{{ build.pkgs }}">{{ build.pkgs }}</a></dd>
+ {% if build.pkgs[:11] == "dist-git://" %}
+ <dd> {{ build.pkgs }} </dd>
+ {% else %}
+ <dd> <a href="{{ build.pkgs }}">{{ build.pkgs }}</a></dd>
+ {% endif %}
{% endif %}
</dd>
</div>
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 5e1086e..d9ded77 100644
--- a/frontend/coprs_frontend/coprs/views/backend_ns/backend_general.py
+++ b/frontend/coprs_frontend/coprs/views/backend_ns/backend_general.py
@@ -48,23 +48,29 @@ def dist_git_upload_completed():
Mark BuildChroot in a Build as uploaded, which means:
- set it to pending state
- set BuildChroot.git_hash
- - if it's the last BuildChroot in a Build, delete local srpm
+ - if it's the last BuildChroot in a Build:
+ - delete local srpm
+ - set the url to dist-git://user/project/package
BuildChroot is identified with task_id which is build id + git branch name
- For example: 56-f22 -> build 55, chroots fedora-22-*
"""
result = {"updated": False}
- if "task_id" in flask.request.json and "git_hash" in flask.request.json:
+ if "task_id" in flask.request.json and "git_hash" in flask.request.json and \
+ "repo_name" in flask.request.json:
task_id = flask.request.json["task_id"]
git_hash = flask.request.json["git_hash"]
+ repo_name = flask.request.json["repo_name"]
build_chroots = BuildsLogic.get_chroots_from_dist_git_task_id(task_id)
for ch in build_chroots:
ch.status = helpers.StatusEnum("pending")
ch.git_hash = git_hash
build = build_chroots[0].build
+ # is it the last chroot?
if not build.has_uploading_chroot:
BuildsLogic.delete_local_srpm(build)
+ build.pkgs = "dist-git://{}".format(repo_name)
db.session.commit()
8 years, 10 months
[copr] dist-git: new build logic functions + helper (6fc09d6)
by asamalik@fedoraproject.org
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
8 years, 10 months
[copr] dist-git: dist git update view in backend_ns (c717eb5)
by asamalik@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : dist-git
>---------------------------------------------------------------
commit c717eb50f16d0ebdabf36e4dfbe3018e06f85bad
Author: Adam Samalik <asamalik(a)redhat.com>
Date: Wed Jun 24 17:46:00 2015 +0200
dist git update view in backend_ns
>---------------------------------------------------------------
frontend/coprs_frontend/coprs/models.py | 4 +++
.../coprs/views/backend_ns/backend_general.py | 29 ++++++++++++++++++++
2 files changed, 33 insertions(+), 0 deletions(-)
diff --git a/frontend/coprs_frontend/coprs/models.py b/frontend/coprs_frontend/coprs/models.py
index 16e4800..53a3270 100644
--- a/frontend/coprs_frontend/coprs/models.py
+++ b/frontend/coprs_frontend/coprs/models.py
@@ -338,6 +338,10 @@ class Build(db.Model, helpers.Serializer):
helpers.StatusEnum("running") in self.chroot_states
@property
+ def has_uploading_chroot(self):
+ return helpers.StatusEnum("uploading") in self.chroot_states
+
+ @property
def status(self):
"""
Return build status according to build status of its chroots
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 26800bf..420cd90 100644
--- a/frontend/coprs_frontend/coprs/views/backend_ns/backend_general.py
+++ b/frontend/coprs_frontend/coprs/views/backend_ns/backend_general.py
@@ -41,6 +41,35 @@ def dist_git_uploading_queue():
return flask.jsonify(response_dict)
+(a)backend_ns.route("/upload-completed/", methods=["POST", "PUT"])
+(a)misc.backend_authenticated
+def dist_git_upload_completed():
+ """
+ Mark BuildChroot in a Build as uploaded, which means:
+ - set it to pending state
+ - set BuildChroot.git_hash
+ - if it's the last BuildChroot in a Build, delete local srpm
+ BuildChroot is identified with task_id which is build id + git branch name
+ - For example: 56-f22 -> build 55, chroots fedora-22-*
+ """
+ result = {"updated": False}
+
+ if "task_id" in flask.request.json and "git_hash" in flask.request.json:
+ task_id = flask.request.json["task_id"]
+ git_hash = flask.request.json["git_hash"]
+ build_chroots = BuildsLogic.get_chroots_from_dist_git_task_id(task_id)
+ for ch in build_chroots:
+ ch.status = helpers.StatusEnum("pending")
+ ch.git_hash = git_hash
+
+ build = build_chroots[0].build
+ if not build.has_uploading_chroot():
+ BuildsLogic.delete_local_srpm(build)
+
+ result["updated"] = True
+
+ return result
+
@backend_ns.route("/waiting/")
@misc.backend_authenticated
def waiting():
8 years, 10 months
[copr] dist-git: import script for dist git (caa027a)
by asamalik@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : dist-git
>---------------------------------------------------------------
commit caa027a9bea6127502e50fdbfa9835a8916c3caf
Author: Adam Samalik <asamalik(a)redhat.com>
Date: Wed Jun 24 13:57:24 2015 +0200
import script for dist git
>---------------------------------------------------------------
dist-git/dit_git_import.py | 91 ++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 91 insertions(+), 0 deletions(-)
diff --git a/dist-git/dit_git_import.py b/dist-git/dit_git_import.py
new file mode 100644
index 0000000..01731b9
--- /dev/null
+++ b/dist-git/dit_git_import.py
@@ -0,0 +1,91 @@
+import os
+import types
+import shutil
+import tempfile
+from pyrpkg import Commands
+from pyrpkg.errors import rpkgError
+
+# Example usage:
+#
+# user = "asamalik"
+# project = "project-for-dist-git"
+# pkg_name = "devtoolset-3"
+# branch = "f20"
+# filepath = "/tmp/rh-php56-php-5.6.5-5.el7.src.rpm"
+#
+# git_hash = import_srpm(user, project, pkg_name, branch, filepath)
+
+
+def _my_upload(repo_dir, reponame, filename, filehash):
+ """
+ This is a replacement function for uploading sources.
+ Rpkg uses upload.cgi for uploading which doesn't make sense
+ on the local machine.
+ """
+ lookaside = "/var/lib/dist-git/cache/lookaside/pkgs/"
+ source = os.path.join(repo_dir, filename)
+ destination = os.path.join(lookaside, reponame, filename, filehash, filename)
+ if not os.path.exists(destination):
+ os.makedirs(os.path.dirname(destination))
+ shutil.copyfile(source, destination)
+
+def import_srpm(user, project, pkg, branch, filepath):
+ """
+ Imports a source rpm file into local dist git.
+ Repository name is in the Copr Style: user/project/package
+ filepath is a srpm file locally downloaded somewhere
+ """
+ # I need to use git via SSH because of gitolite as it manages
+ # permissions with it's hook that relies on gitolite console
+ # which is a default shell on SSH
+ gitbaseurl = "ssh://frank@localhost/%(module)s"
+ tmp = tempfile.mkdtemp()
+ try:
+ repo_dir = os.path.join(tmp, pkg)
+
+ # use rpkg for importing the source rpm
+ commands = Commands(path =repo_dir,
+ lookaside ="",
+ lookasidehash ="md5",
+ lookaside_cgi ="",
+ gitbaseurl =gitbaseurl,
+ anongiturl ="",
+ branchre ="",
+ kojiconfig ="",
+ build_client ="")
+
+ # rpkg gets module_name as a basename of git url
+ # we use module_name as "username/projectname/packagename"
+ # basename is not working here - so I'm setting it manually
+ module = "{}/{}/{}".format(user, project, pkg)
+ commands.module_name = module
+ # rpkg calls upload.cgi script on the dist git server
+ # here, I just copy the source files manually with custom function
+ # I also add one parameter "repo_dir" to that function with this hack
+ commands.lookasidecache.upload = types.MethodType(_my_upload, repo_dir)
+
+ # clone the pkg repository into tmp directory
+ #module = "{}/{}/{}.git".format(user, project, pkg)
+ #giturl = gitbaseurl % {'module': module}
+ #cmd = ['git', 'clone', "-b", "f20", giturl]
+ #call(cmd, cwd=tmp)
+ commands.clone(module, tmp, branch)
+
+ # import the source rpm into git and save filenames of sources
+ uploadfiles = commands.import_srpm(filepath)
+
+ # save the source files into lookaside cache
+ commands.upload(uploadfiles, replace=True)
+
+ # git push
+ message = "Import of {}".format(os.path.basename(filepath))
+ #call(["git", "commit", "-m", message], cwd=repo_dir)
+ #call(["git", "push"], cwd=repo_dir)
+ try:
+ commands.commit(message)
+ commands.push()
+ except rpkgError:
+ pass
+ finally:
+ shutil.rmtree(tmp)
+ return commands.commithash
8 years, 10 months
[copr] dist-git: get_build_uploading_queue (5c84a31)
by asamalik@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : dist-git
>---------------------------------------------------------------
commit 5c84a31101a4113dc106c89b8302e5c7e04f6997
Author: Adam Samalik <asamalik(a)redhat.com>
Date: Wed Jun 24 12:42:00 2015 +0200
get_build_uploading_queue
>---------------------------------------------------------------
.../coprs_frontend/coprs/logic/builds_logic.py | 11 +++++++++++
1 files changed, 11 insertions(+), 0 deletions(-)
diff --git a/frontend/coprs_frontend/coprs/logic/builds_logic.py b/frontend/coprs_frontend/coprs/logic/builds_logic.py
index e22a1d6..dfa88d4 100644
--- a/frontend/coprs_frontend/coprs/logic/builds_logic.py
+++ b/frontend/coprs_frontend/coprs/logic/builds_logic.py
@@ -51,6 +51,17 @@ class BuildsLogic(object):
return query
@classmethod
+ def get_build_uploading_queue(cls):
+ """
+ Returns BuildChroots which are waiting to be uploaded to dist git
+ """
+ query = (models.BuildChroot.query.join(models.Build)
+ .filter(models.Build.canceled == false())
+ .filter(models.BuildChroot.status == helpers.StatusEnum("uploading")))
+ query = query.order_by(models.BuildChroot.build_id.asc())
+ return query
+
+ @classmethod
def get_build_task_queue(cls):
"""
Returns BuildChroots which are - waiting to be built or
8 years, 10 months