Skip to content

Commit

Permalink
frontend: add script for changing storage for a project
Browse files Browse the repository at this point in the history
See #2533
  • Loading branch information
FrostyX committed Aug 27, 2024
1 parent 69957fc commit aea5680
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
47 changes: 47 additions & 0 deletions frontend/coprs_frontend/commands/change_storage.py
Original file line number Diff line number Diff line change
@@ -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).")
2 changes: 1 addition & 1 deletion frontend/coprs_frontend/coprs/logic/actions_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 2 additions & 0 deletions frontend/coprs_frontend/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -98,6 +99,7 @@
"warning_banner",
"usage_treemap",
"failed_to_succeeded_stats",
"change_storage",
]


Expand Down

0 comments on commit aea5680

Please sign in to comment.