diff --git a/frontend/coprs_frontend/commands/change_storage.py b/frontend/coprs_frontend/commands/change_storage.py new file mode 100644 index 000000000..4983b04a0 --- /dev/null +++ b/frontend/coprs_frontend/commands/change_storage.py @@ -0,0 +1,47 @@ +""" +Change a storage for a project + +Copr supports different storage solutions for repositories with the built RPM +packages (e.g. results directory on copr-backend or Pulp). This script allows to +configure the storage type for a given project and while doing so, it makes sure +DNF repositories for the project are created. + +Existing builds are not migrated from one storage to another. This may be an +useful feature but it is not implemented yet. +""" + +import sys +import click +from copr_common.enums import StorageEnum +from coprs import db +from coprs.logic.coprs_logic import CoprsLogic +from coprs.logic.actions_logic import ActionsLogic + + +@click.command() +@click.argument("fullname", required=True) +@click.argument( + "storage", + required=True, + type=click.Choice(["backend", "pulp"]) +) +def change_storage(fullname, storage): + """ + Change a storage for a project + """ + if "/" not in fullname: + print("Must be a fullname, e.g. @copr/copr-dev") + sys.exit(1) + + ownername, projectname = fullname.split("/", 1) + copr = CoprsLogic.get_by_ownername_coprname(ownername, projectname) + copr.storage = StorageEnum(storage) + db.session.add(copr) + + action = ActionsLogic.send_createrepo(copr) + db.session.add(action) + + db.session.commit() + print("Configured storage for {0} to {1}".format(copr.full_name, storage)) + print("Submitted action to create repositories: {0}".format(action.id)) + print("Existing builds not migrated (not implemented yet).") diff --git a/frontend/coprs_frontend/coprs/logic/actions_logic.py b/frontend/coprs_frontend/coprs/logic/actions_logic.py index 998ec1ec6..321d62d9f 100644 --- a/frontend/coprs_frontend/coprs/logic/actions_logic.py +++ b/frontend/coprs_frontend/coprs/logic/actions_logic.py @@ -138,7 +138,7 @@ def send_createrepo(cls, copr, dirnames=None, chroots=None, devel=None, if priority is not None: action.priority = priority db.session.add(action) - + return action @classmethod def send_delete_copr(cls, copr): diff --git a/frontend/coprs_frontend/manage.py b/frontend/coprs_frontend/manage.py index ed0c8f06f..e745e7484 100755 --- a/frontend/coprs_frontend/manage.py +++ b/frontend/coprs_frontend/manage.py @@ -44,6 +44,7 @@ import commands.warning_banner import commands.usage_treemap import commands.failed_to_succeeded_stats +import commands.change_storage from coprs import app @@ -98,6 +99,7 @@ "warning_banner", "usage_treemap", "failed_to_succeeded_stats", + "change_storage", ]