Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
commit 83a2c9ca4028ad4e23029dad81aae77e262c55c0 Author: Bohuslav Kabrda bkabrda@redhat.com Date: Mon Jan 14 11:45:13 2013 +0100
Refactor getting mock chroots by its attributest
coprs_frontend/coprs/models.py | 6 ++++++ coprs_frontend/manage.py | 12 ++++++------ 2 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/coprs_frontend/coprs/models.py b/coprs_frontend/coprs/models.py index f3f1ca0..120cf15 100644 --- a/coprs_frontend/coprs/models.py +++ b/coprs_frontend/coprs/models.py @@ -193,6 +193,12 @@ 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('coprs')) diff --git a/coprs_frontend/manage.py b/coprs_frontend/manage.py index 322cd61..e2461d8 100755 --- a/coprs_frontend/manage.py +++ b/coprs_frontend/manage.py @@ -54,6 +54,10 @@ class CreateChrootCommand(ChrootCommand): split_chroot = chroot_name.split('-') if len(split_chroot) < 3: print 'Invalid chroot format, must be "{release}-{version}-{arch}".' + return + if models.MockChroot.get(*split_chroot): + print 'Already exists.' + return new_chroot = models.MockChroot(os_release=split_chroot[0], os_version=split_chroot[1], arch=split_chroot[2], @@ -67,9 +71,7 @@ class AlterChrootCommand(ChrootCommand): split_chroot = chroot_name.split('-') if len(split_chroot) < 3: print 'Invalid chroot format, must be "{release}-{version}-{arch}".' - chroot = models.MockChroot.query.filter(models.MockChroot.os_release==split_chroot[0], - models.MockChroot.os_version==split_chroot[1], - models.MockChroot.arch==split_chroot[2]).first() + chroot = models.MockChroot.get(*split_chroot) if action == 'activate': chroot.is_active = True else: @@ -93,9 +95,7 @@ class DropChrootCommand(ChrootCommand): split_chroot = chroot_name.split('-') if len(split_chroot) < 3: print 'Invalid chroot format, must be "{release}-{version}-{arch}".' - chroot = models.MockChroot.query.filter(models.MockChroot.os_release==split_chroot[0], - models.MockChroot.os_version==split_chroot[1], - models.MockChroot.arch==split_chroot[2]).first() + chroot = models.MockChroot.get(*split_chroot) if chroot: db.session.delete(chroot) db.session.commit()
copr-devel@lists.fedorahosted.org