Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
commit 30b3980485418b73b355d45f75a1d47c2dd3a6aa Author: Bohuslav Kabrda bkabrda@redhat.com Date: Mon Jan 14 10:35:39 2013 +0100
Basic mock chroot commands for manage.py
coprs_frontend/manage.py | 83 +++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 82 insertions(+), 1 deletions(-)
diff --git a/coprs_frontend/manage.py b/coprs_frontend/manage.py index cd53522..7c9cddf 100755 --- a/coprs_frontend/manage.py +++ b/coprs_frontend/manage.py @@ -5,7 +5,7 @@ import os import flask from flask.ext.script import Manager, Command, Option
-from coprs import app, db +from coprs import app, db, models
class CreateSqliteFileCommand(Command): 'Create the sqlite DB file (not the tables). Used for alembic, "create_db" does this automatically.' @@ -42,10 +42,91 @@ class DropDBCommand(Command): def run(self): db.drop_all()
+class ChrootCommand(Command): + option_list = ( + Option('chroot_name', + help='Chroot name, e.g. fedora-18-x86_64.'), + ) + +class CreateChrootCommand(ChrootCommand): + 'Creates a mock chroot in DB' + def run(self, chroot_name): + split_chroot = chroot_name.split('-') + if len(split_chroot) < 3: + print 'Invalid chroot format, must be "{release}-{version}-{arch}".' + 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_name, action): + 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() + 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', + '-a', + dest='action', + help='Action to take - currently activate or deactivate', + choices=['activate', 'deactivate'], + required=True), + ) + +class DropChrootCommand(ChrootCommand): + 'Activates or deactivates a chroot' + def run(self, chroot_name): + 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() + if chroot: + 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: + print '{0}-{1}-{2}'.format(ch.os_release, ch.os_version, ch.arch) + + option_list = ( + Option('--active-only', + '-a', + dest='active_only', + help='Display only active chroots', + required=False, + action='store_true', + default=False), + ) + manager = Manager(app) manager.add_command('create_sqlite_file', CreateSqliteFileCommand()) manager.add_command('create_db', CreateDBCommand()) manager.add_command('drop_db', DropDBCommand()) +manager.add_command('create_chroot', CreateChrootCommand()) +manager.add_command('alter_chroot', AlterChrootCommand()) +manager.add_command('display_chroots', DisplayChrootsCommand()) +manager.add_command('drop_chroot', DropChrootCommand())
if __name__ == '__main__': manager.run()
copr-devel@lists.fedorahosted.org