copr cli tool
by Seth Vidal
I was thinking about the cli tool we want, now that we have the api in
place to make it possible to submit from a cli.
to start with I was thinking of a simple tool that did a small number of
basic commands:
create coprname -r distro -r distro -r distro -a arch -a arch
--repo=somerepo --repo=somerepo -p pkgurl1 -p pkgurl2
-p pkgurl3
edit coprname (not sure what this would do yet)
info coprname (dumps out info like the returned urls of builds, number of
builds, etc)
build coprname pkgurl1 pkgurl2 pkgurl3
delete coprname
What do you think? Too broad? not broad enough?
-sv
10 years, 9 months
Priorities for production
by Seth Vidal
We're still in a testing-mode for coprs right now and I'd like to think
about what our highest priorities are for production.
Right now things I care about/ I have been told I should care about - no
particular order:
- copr-cli
- fixing up the cases where a backend builder will hang/become
abandoned
- figure out how we manage sizing of the prodcution cloud instance(s)
- way for user to specify that they need a larger builder for their
software
- deletable coprs
- private coprs
what else is on other folks' lists?
-sv
10 years, 10 months
[copr] master: This setting shouldn't have been commited... (db0c8e6)
by bkabrda@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit db0c8e65e26fd40438357a04c1ba8c6a8087e26c
Author: Bohuslav Kabrda <bkabrda(a)redhat.com>
Date: Thu Jan 31 13:12:24 2013 +0100
This setting shouldn't have been commited...
>---------------------------------------------------------------
coprs_frontend/coprs/config.py | 1 -
1 files changed, 0 insertions(+), 1 deletions(-)
diff --git a/coprs_frontend/coprs/config.py b/coprs_frontend/coprs/config.py
index 3ab0410..6218ea9 100644
--- a/coprs_frontend/coprs/config.py
+++ b/coprs_frontend/coprs/config.py
@@ -24,7 +24,6 @@ class Config(object):
class ProductionConfig(Config):
DEBUG = False
- SQLALCHEMY_DATABASE_URI = 'postgresql+psycopg2://bkabrda:pass@/copr'
class DevelopmentConfig(Config):
DEBUG = True
10 years, 10 months
[copr] master: Have the mock chroots properly sorted in copr overview (01a84ac)
by bkabrda@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit 01a84acf3f8ee8972ff431a8a78cf96070ef27ed
Author: Bohuslav Kabrda <bkabrda(a)redhat.com>
Date: Thu Jan 31 13:05:08 2013 +0100
Have the mock chroots properly sorted in copr overview
>---------------------------------------------------------------
coprs_frontend/coprs/logic/coprs_logic.py | 4 ++++
.../coprs/views/coprs_ns/coprs_general.py | 9 ++++++---
2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/coprs_frontend/coprs/logic/coprs_logic.py b/coprs_frontend/coprs/logic/coprs_logic.py
index f8a6f24..1fd32e8 100644
--- a/coprs_frontend/coprs/logic/coprs_logic.py
+++ b/coprs_frontend/coprs/logic/coprs_logic.py
@@ -10,6 +10,7 @@ class CoprsLogic(object):
@classmethod
def get(cls, user, username, coprname, **kwargs):
with_builds = kwargs.get('with_builds', False)
+ with_mock_chroots = kwargs.get('with_mock_chroots', False)
query = db.session.query(models.Copr).\
join(models.Copr.owner).\
@@ -21,6 +22,9 @@ class CoprsLogic(object):
query = query.outerjoin(models.Copr.builds).\
options(db.contains_eager(models.Copr.builds)).\
order_by(models.Build.submitted_on.desc())
+ if with_mock_chroots:
+ query = query.outerjoin(*models.Copr.mock_chroots.attr).\
+ options(db.contains_eager(*models.Copr.mock_chroots.attr))
return query
diff --git a/coprs_frontend/coprs/views/coprs_ns/coprs_general.py b/coprs_frontend/coprs/views/coprs_ns/coprs_general.py
index 79467dd..2f32925 100644
--- a/coprs_frontend/coprs/views/coprs_ns/coprs_general.py
+++ b/coprs_frontend/coprs/views/coprs_ns/coprs_general.py
@@ -1,6 +1,7 @@
import time
import flask
+import sqlalchemy
from coprs import db
from coprs import exceptions
@@ -90,9 +91,11 @@ def copr_new():
@coprs_ns.route('/detail/<username>/<coprname>/')
def copr_detail(username, coprname):
- query = coprs_logic.CoprsLogic.get(flask.g.user, username, coprname)
- copr = query.first()
- if not copr:
+ query = coprs_logic.CoprsLogic.get(flask.g.user, username, coprname, with_mock_chroots=True)
+ try:
+ print dir(db)
+ copr = query.one()
+ except sqlalchemy.orm.exc.NoResultFound:
return page_not_found('Copr with name {0} does not exist.'.format(coprname))
return flask.render_template('coprs/detail/overview.html',
10 years, 10 months
[copr] master: Fix removing multiple mock chroots (5722893)
by bkabrda@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit 5722893d0eced4b7f5f31958f72c3b6f08e68a85
Author: Bohuslav Kabrda <bkabrda(a)redhat.com>
Date: Thu Jan 31 13:04:08 2013 +0100
Fix removing multiple mock chroots
>---------------------------------------------------------------
coprs_frontend/coprs/logic/coprs_logic.py | 8 ++++++-
.../tests/test_views/test_coprs_ns/test_general.py | 21 ++++++++++++++++++++
2 files changed, 28 insertions(+), 1 deletions(-)
diff --git a/coprs_frontend/coprs/logic/coprs_logic.py b/coprs_frontend/coprs/logic/coprs_logic.py
index 54ae9fe..f8a6f24 100644
--- a/coprs_frontend/coprs/logic/coprs_logic.py
+++ b/coprs_frontend/coprs/logic/coprs_logic.py
@@ -156,10 +156,16 @@ class CoprChrootsLogic(object):
for mock_chroot in new_chroots:
if mock_chroot not in current_chroots:
db.session.add(models.CoprChroot(copr=copr, mock_chroot=mock_chroot))
+
# delete no more present
+ to_remove = []
for mock_chroot in current_chroots:
if mock_chroot not in new_chroots:
- copr.mock_chroots.remove(mock_chroot)
+ # can't delete here, it would change current_chroots and break iteration
+ to_remove.append(mock_chroot)
+
+ for mc in to_remove:
+ copr.mock_chroots.remove(mc)
class MockChrootsLogic(object):
@classmethod
diff --git a/coprs_frontend/tests/test_views/test_coprs_ns/test_general.py b/coprs_frontend/tests/test_views/test_coprs_ns/test_general.py
index 2d96e84..9f3fad6 100644
--- a/coprs_frontend/tests/test_views/test_coprs_ns/test_general.py
+++ b/coprs_frontend/tests/test_views/test_coprs_ns/test_general.py
@@ -255,6 +255,27 @@ class TestCoprUpdate(CoprsTestCase):
assert self.mc3.chroot_name in mock_chroots_names
assert self.mc1.chroot_name not in mock_chroots_names
+ def test_update_deletes_multiple_chroots(self, f_users, f_coprs, f_copr_permissions, f_mock_chroots):
+ # https://fedorahosted.org/copr/ticket/42
+ with self.tc as c:
+ with c.session_transaction() as s:
+ s['openid'] = self.u2.openid_name
+
+ self.db.session.add_all([self.u2, self.c2, self.mc1])
+ # add one more mock_chroot, so that we can remove two
+ cc = self.models.CoprChroot()
+ cc.mock_chroot = self.mc1
+ self.c2.copr_chroots.append(cc)
+
+ r = c.post('/coprs/detail/{0}/{1}/update/'.format(self.u2.name, self.c2.name),
+ data = {'name': self.c2.name, self.mc1.chroot_name: 'y', 'id': self.c2.id},
+ follow_redirects = True)
+ assert 'Copr was updated successfully' in r.data
+ self.db.session.add_all([self.c2, self.mc1])
+ mock_chroots = self.models.MockChroot.query.join(self.models.CoprChroot).\
+ filter(self.models.CoprChroot.copr_id==\
+ self.c2.id).all()
+ assert len(mock_chroots) == 1
class TestCoprApplyForPermissions(CoprsTestCase):
def test_apply(self, f_users, f_coprs):
10 years, 10 months
[copr] master: Properly split mock chroot name (86eaef3)
by bkabrda@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit 86eaef312d1b5528d6c04fe15edbcf2eb0ddef38
Author: Bohuslav Kabrda <bkabrda(a)redhat.com>
Date: Thu Jan 31 11:55:02 2013 +0100
Properly split mock chroot name
>---------------------------------------------------------------
coprs_frontend/coprs/logic/coprs_logic.py | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/coprs_frontend/coprs/logic/coprs_logic.py b/coprs_frontend/coprs/logic/coprs_logic.py
index 21b2b00..54ae9fe 100644
--- a/coprs_frontend/coprs/logic/coprs_logic.py
+++ b/coprs_frontend/coprs/logic/coprs_logic.py
@@ -221,7 +221,7 @@ class MockChrootsLogic(object):
@classmethod
def tuple_from_name(cls, user, name):
- split_name = name.rsplit('-')
+ split_name = name.rsplit('-', 1)
if len(split_name) < 2:
raise exceptions.MalformedArgumentException(
'Chroot Name doesn\'t contain dash, can\'t determine chroot architecure.')
10 years, 10 months
[copr] master: Fix listing coprs by manage.py (426f227)
by bkabrda@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit 426f22711d4653e145c0dfff4f37c01935f77501
Author: Bohuslav Kabrda <bkabrda(a)redhat.com>
Date: Thu Jan 31 11:49:54 2013 +0100
Fix listing coprs by manage.py
>---------------------------------------------------------------
coprs_frontend/coprs/filters.py | 14 ++++++++------
coprs_frontend/coprs/logic/coprs_logic.py | 1 +
coprs_frontend/coprs/models.py | 8 +++++++-
coprs_frontend/manage.py | 2 +-
4 files changed, 17 insertions(+), 8 deletions(-)
diff --git a/coprs_frontend/coprs/filters.py b/coprs_frontend/coprs/filters.py
index 98d97dc..5cbdb75 100644
--- a/coprs_frontend/coprs/filters.py
+++ b/coprs_frontend/coprs/filters.py
@@ -14,10 +14,12 @@ def perm_type_from_num(num):
# this should probably be stored in DB with the whole mock_chroot...
@app.template_filter('os_name_short')
def os_name_short(os_name, os_version):
- if os_version == 'rawhide':
- return os_version
- if os_name == 'fedora':
- return 'fc.{0}'.format(os_version)
- elif os_name == 'epel':
- return 'el{0}'.format(os_version)
+ # TODO: make it models.MockChroot method or not?
+ if os_version:
+ if os_version == 'rawhide':
+ return os_version
+ if os_name == 'fedora':
+ return 'fc.{0}'.format(os_version)
+ elif os_name == 'epel':
+ return 'el{0}'.format(os_version)
return os_name
diff --git a/coprs_frontend/coprs/logic/coprs_logic.py b/coprs_frontend/coprs/logic/coprs_logic.py
index 3403c04..21b2b00 100644
--- a/coprs_frontend/coprs/logic/coprs_logic.py
+++ b/coprs_frontend/coprs/logic/coprs_logic.py
@@ -173,6 +173,7 @@ class MockChrootsLogic(object):
query = models.MockChroot.query
if active_only:
query = query.filter(models.MockChroot.is_active==True)
+ return query
@classmethod
def add(cls, user, name):
diff --git a/coprs_frontend/coprs/models.py b/coprs_frontend/coprs/models.py
index b59e7fa..cfa6857 100644
--- a/coprs_frontend/coprs/models.py
+++ b/coprs_frontend/coprs/models.py
@@ -191,7 +191,13 @@ class MockChroot(db.Model, Serializer):
@property
def chroot_name(self):
- return '{0}-{1}-{2}'.format(self.os_release, self.os_version, self.arch)
+ if self.os_version:
+ format_string = '{rel}-{ver}-{arch}'
+ else:
+ format_string = '{rel}-{arch}'
+ return format_string.format(rel=self.os_release,
+ ver=self.os_version,
+ arch=self.arch)
class CoprChroot(db.Model, Serializer):
mock_chroot_id = db.Column(db.Integer, db.ForeignKey('mock_chroot.id'), primary_key = True)
diff --git a/coprs_frontend/manage.py b/coprs_frontend/manage.py
index 5c505be..e191d52 100755
--- a/coprs_frontend/manage.py
+++ b/coprs_frontend/manage.py
@@ -112,7 +112,7 @@ class DropChrootCommand(ChrootCommand):
class DisplayChrootsCommand(Command):
'Displays current mock chroots'
def run(self, active_only):
- for ch in coprs_logic.MockChrootsLogic.get_multiple(active_only=active_only):
+ for ch in coprs_logic.MockChrootsLogic.get_multiple(None, active_only=active_only).all():
print ch.chroot_name
option_list = (
10 years, 10 months
[copr] master: Introduce MockChrootLogic - relax the mock chroot name requirements (c89f919)
by bkabrda@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit c89f91968423be3765afaf73c59db0ceef5a8239
Author: Bohuslav Kabrda <bkabrda(a)redhat.com>
Date: Mon Jan 28 14:23:32 2013 +0100
Introduce MockChrootLogic
- relax the mock chroot name requirements
>---------------------------------------------------------------
coprs_frontend/coprs/exceptions.py | 3 +
coprs_frontend/coprs/logic/coprs_logic.py | 71 +++++++++++++++++++++++++++++
coprs_frontend/coprs/models.py | 6 ---
coprs_frontend/manage.py | 56 +++++++++--------------
4 files changed, 96 insertions(+), 40 deletions(-)
diff --git a/coprs_frontend/coprs/exceptions.py b/coprs_frontend/coprs/exceptions.py
index 8635520..09888e2 100644
--- a/coprs_frontend/coprs/exceptions.py
+++ b/coprs_frontend/coprs/exceptions.py
@@ -4,6 +4,9 @@ class ArgumentMissingException(BaseException):
class MalformedArgumentException(ValueError):
pass
+class NotFoundException(BaseException):
+ pass
+
class DuplicateException(BaseException):
pass
diff --git a/coprs_frontend/coprs/logic/coprs_logic.py b/coprs_frontend/coprs/logic/coprs_logic.py
index fc0293d..3403c04 100644
--- a/coprs_frontend/coprs/logic/coprs_logic.py
+++ b/coprs_frontend/coprs/logic/coprs_logic.py
@@ -160,3 +160,74 @@ class CoprChrootsLogic(object):
for mock_chroot in current_chroots:
if mock_chroot not in new_chroots:
copr.mock_chroots.remove(mock_chroot)
+
+class MockChrootsLogic(object):
+ @classmethod
+ def get(cls, user, os_release, os_version, arch, active_only = False):
+ return models.MockChroot.query.filter(models.MockChroot.os_release==os_release,
+ models.MockChroot.os_version==os_version,
+ models.MockChroot.arch==arch)
+
+ @classmethod
+ def get_multiple(cls, user, active_only=False):
+ query = models.MockChroot.query
+ if active_only:
+ query = query.filter(models.MockChroot.is_active==True)
+
+ @classmethod
+ def add(cls, user, name):
+ name_tuple = cls.tuple_from_name(user, name)
+ if cls.get(user, *name_tuple).first():
+ raise exceptions.DuplicateException('Mock chroot with this name already exists.')
+ new_chroot = models.MockChroot(os_release=name_tuple[0],
+ os_version=name_tuple[1],
+ arch=name_tuple[2])
+ cls.new(user, new_chroot)
+ return new_chroot
+
+ @classmethod
+ def new(cls, user, mock_chroot):
+ db.session.add(mock_chroot)
+
+ @classmethod
+ def edit_by_name(cls, user, name, is_active):
+ name_tuple = cls.tuple_from_name(user, name)
+ mock_chroot = cls.get(user, *name_tuple).first()
+ if not mock_chroot:
+ raise exceptions.NotFoundException('Mock chroot with this name doesn\'t exist.')
+
+ mock_chroot.is_active = is_active
+ cls.update(user, mock_chroot)
+ return mock_chroot
+
+ @classmethod
+ def update(cls, user, mock_chroot):
+ db.session.add(mock_chroot)
+
+
+ @classmethod
+ def delete_by_name(cls, user, name):
+ name_tuple = cls.tuple_from_name(user, name)
+ mock_chroot = cls.get(user, *name_tuple).first()
+ if not mock_chroot:
+ raise exceptions.NotFoundException('Mock chroot with this name doesn\'t exist.')
+
+ cls.delete(user, mock_chroot)
+
+ @classmethod
+ def delete(cls, user, mock_chroot):
+ db.session.delete(mock_chroot)
+
+ @classmethod
+ def tuple_from_name(cls, user, name):
+ split_name = name.rsplit('-')
+ if len(split_name) < 2:
+ raise exceptions.MalformedArgumentException(
+ 'Chroot Name doesn\'t contain dash, can\'t determine chroot architecure.')
+ if '-' in split_name[0]:
+ os_release, os_version = split_name[0].rsplit('-')
+ else:
+ os_release, os_version = split_name[0], ''
+
+ arch = split_name[1]
+ return (os_release, os_version, arch)
diff --git a/coprs_frontend/coprs/models.py b/coprs_frontend/coprs/models.py
index f75586f..b59e7fa 100644
--- a/coprs_frontend/coprs/models.py
+++ b/coprs_frontend/coprs/models.py
@@ -193,12 +193,6 @@ class MockChroot(db.Model, Serializer):
def chroot_name(self):
return '{0}-{1}-{2}'.format(self.os_release, self.os_version, self.arch)
- @classmethod
- def get(cls, os_release, os_version, arch, active_only = False):
- return cls.query.filter(cls.os_release==os_release,
- cls.os_version==os_version,
- cls.arch==arch).first()
-
class CoprChroot(db.Model, Serializer):
mock_chroot_id = db.Column(db.Integer, db.ForeignKey('mock_chroot.id'), primary_key = True)
mock_chroot = db.relationship('MockChroot', backref = db.backref('copr_chroots'))
diff --git a/coprs_frontend/manage.py b/coprs_frontend/manage.py
index 766ca46..5c505be 100755
--- a/coprs_frontend/manage.py
+++ b/coprs_frontend/manage.py
@@ -5,7 +5,11 @@ import os
import flask
from flask.ext.script import Manager, Command, Option
-from coprs import app, db, models
+from coprs import app
+from coprs import db
+from coprs import exceptions
+from coprs import models
+from coprs.logic import coprs_logic
class CreateSqliteFileCommand(Command):
'Create the sqlite DB file (not the tables). Used for alembic, "create_db" does this automatically.'
@@ -63,37 +67,26 @@ class CreateChrootCommand(ChrootCommand):
'Creates a mock chroot in DB'
def run(self, chroot_names):
for chroot_name in chroot_names:
- split_chroot = chroot_name.split('-')
- if len(split_chroot) < 3:
+ try:
+ coprs_logic.MockChrootsLogic.add(None, chroot_name)
+ db.session.commit()
+ except exceptions.MalformedArgumentException:
self.print_invalid_format(chroot_name)
- elif models.MockChroot.get(*split_chroot):
+ except exceptions.DuplicateException:
self.print_already_exists(chroot_name)
- else:
- new_chroot = models.MockChroot(os_release=split_chroot[0],
- os_version=split_chroot[1],
- arch=split_chroot[2],
- is_active=True)
- db.session.add(new_chroot)
- db.session.commit()
class AlterChrootCommand(ChrootCommand):
'Activates or deactivates a chroot'
def run(self, chroot_names, action):
+ activate = (action == 'activate')
for chroot_name in chroot_names:
- split_chroot = chroot_name.split('-')
- if len(split_chroot) < 3:
+ try:
+ coprs_logic.MockChrootsLogic.edit_by_name(None, chroot_name, activate)
+ db.session.commit()
+ except exceptions.MalformedArgumentException:
self.print_invalid_format(chroot_name)
- chroot = models.MockChroot.get(*split_chroot)
- if not chroot:
+ except exceptions.NotFoundException:
self.print_doesnt_exist(chroot_name)
- else:
- if action == 'activate':
- chroot.is_active = True
- else:
- chroot.is_active = False
-
- db.session.add(chroot)
- db.session.commit()
option_list = ChrootCommand.option_list + (
Option('--action',
@@ -108,23 +101,18 @@ class DropChrootCommand(ChrootCommand):
'Activates or deactivates a chroot'
def run(self, chroot_names):
for chroot_name in chroot_names:
- split_chroot = chroot_name.split('-')
- if len(split_chroot) < 3:
+ try:
+ coprs_logic.MockChrootsLogic.delete_by_name(None, chroot_name)
+ db.session.commit()
+ except exceptions.MalformedArgumentException:
self.print_invalid_format(chroot_name)
- chroot = models.MockChroot.get(*split_chroot)
- if not chroot:
+ except exceptions.NotFoundException:
self.print_doesnt_exist(chroot_name)
- else:
- db.session.delete(chroot)
- db.session.commit()
class DisplayChrootsCommand(Command):
'Displays current mock chroots'
def run(self, active_only):
- chroots = models.MockChroot.query
- if active_only:
- chroots = chroots.filter(models.MockChroot.is_active==True)
- for ch in chroots:
+ for ch in coprs_logic.MockChrootsLogic.get_multiple(active_only=active_only):
print ch.chroot_name
option_list = (
10 years, 10 months
[copr] master: Make exception names more general - Introduce MalformedArgumentException (e2ee7b4)
by bkabrda@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit e2ee7b4aaca9f2dc7e96d0e040dfdb1dc72674db
Author: Bohuslav Kabrda <bkabrda(a)redhat.com>
Date: Mon Jan 28 12:38:16 2013 +0100
Make exception names more general
- Introduce MalformedArgumentException
>---------------------------------------------------------------
coprs_frontend/coprs/exceptions.py | 5 ++++-
coprs_frontend/coprs/logic/coprs_logic.py | 4 ++--
coprs_frontend/coprs/views/api_ns/api_general.py | 2 +-
3 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/coprs_frontend/coprs/exceptions.py b/coprs_frontend/coprs/exceptions.py
index 7b7fd5c..8635520 100644
--- a/coprs_frontend/coprs/exceptions.py
+++ b/coprs_frontend/coprs/exceptions.py
@@ -1,7 +1,10 @@
class ArgumentMissingException(BaseException):
pass
-class DuplicateCoprNameException(BaseException):
+class MalformedArgumentException(ValueError):
+ pass
+
+class DuplicateException(BaseException):
pass
class InsufficientRightsException(BaseException):
diff --git a/coprs_frontend/coprs/logic/coprs_logic.py b/coprs_frontend/coprs/logic/coprs_logic.py
index a27668e..fc0293d 100644
--- a/coprs_frontend/coprs/logic/coprs_logic.py
+++ b/coprs_frontend/coprs/logic/coprs_logic.py
@@ -64,14 +64,14 @@ class CoprsLogic(object):
@classmethod
def new(cls, user, copr, check_for_duplicates = True):
if check_for_duplicates and cls.exists_for_current_user(user, copr.name).all():
- raise exceptions.DuplicateCoprNameException(
+ raise exceptions.DuplicateException(
'Copr: "{0}" already exists'.format(copr.name))
db.session.add(copr)
@classmethod
def update(cls, user, copr, check_for_duplicates = True):
if check_for_duplicates and cls.exists_for_current_user(user, copr.name).all():
- raise exceptions.DuplicateCoprNameException(
+ raise exceptions.DuplicateException(
'Copr: "{0}" already exists'.format(copr.name))
db.session.add(copr)
diff --git a/coprs_frontend/coprs/views/api_ns/api_general.py b/coprs_frontend/coprs/views/api_ns/api_general.py
index f2d270d..735da98 100644
--- a/coprs_frontend/coprs/views/api_ns/api_general.py
+++ b/coprs_frontend/coprs/views/api_ns/api_general.py
@@ -77,7 +77,7 @@ def api_new_copr():
output = {'output': 'ok', 'message' : '\n'.join(infos)}
db.session.commit()
- except exceptions.DuplicateCoprNameException, err:
+ except exceptions.DuplicateException, err:
output = {'output': 'notok', 'error': err}
db.session.rollback()
10 years, 10 months
[copr] master: Make the list function use better serializing, too (a994260)
by bkabrda@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit a9942603b2a550d31dfc68b7c93785700ba97e88
Author: Bohuslav Kabrda <bkabrda(a)redhat.com>
Date: Mon Jan 28 10:28:20 2013 +0100
Make the list function use better serializing, too
- Also try to take username from URL if not present in GET params
>---------------------------------------------------------------
coprs_frontend/coprs/views/api_ns/api_general.py | 33 ++++++++++------------
1 files changed, 15 insertions(+), 18 deletions(-)
diff --git a/coprs_frontend/coprs/views/api_ns/api_general.py b/coprs_frontend/coprs/views/api_ns/api_general.py
index 4cba67b..f2d270d 100644
--- a/coprs_frontend/coprs/views/api_ns/api_general.py
+++ b/coprs_frontend/coprs/views/api_ns/api_general.py
@@ -90,31 +90,28 @@ def api_new_copr():
@api_ns.route('/owned/')
-def api_list_copr():
+(a)api_ns.route('/owned/<username>/')
+def api_coprs_by_owner(username=None):
""" Return the list of coprs owned by the given user.
+ username is taken either from GET params or from the URL itself
+ (in this order).
:arg username: the username of the person one would like to the
coprs of.
"""
- if 'username' in flask.request.args:
- username = flask.request.args['username']
+ username = flask.request.args.get('username', None) or username
+ if 'username':
query = coprs_logic.CoprsLogic.get_multiple(flask.g.user,
- user_relation = 'owned', username = username)
+ user_relation='owned', username=username)
repos = query.all()
- output = '{"output": "ok",\n"repos":[\n'
- for cnt, repo in enumerate(repos):
- output += '{'\
- '"name" : "%s", '\
- '"repos" : "%s", '\
- '"description": "%s", '\
- '"instructions": "%s" '\
- '}\n' % (repo.name, repo.repos, repo.description,
- repo.instructions)
- if cnt < len(repos):
- output += ','
- output += "]}\n"
+ output = {'output': 'ok', 'repos': []}
+ for repo in repos:
+ output['repos'].append({'name': repo.name,
+ 'repos': repo.repos,
+ 'description': repo.description,
+ 'instructions': repo.instructions})
else:
- output = '{"output": "notok", "error": "Invalid request"}'
+ output = {'output': 'notok', 'error': 'Invalid request'}
- return flask.Response(output, mimetype='application/json')
+ return flask.jsonify(output)
10 years, 10 months