roundabout,
created on Sunday, 28 April 2024, 19:33:23 (1714332803),
received on Wednesday, 31 July 2024, 06:54:47 (1722408887)
Author identity: vlad <vlad.muntoiu@gmail.com>
e87c95551808f061bd835ca66be4f5f73a7f5044
app.py
@@ -1521,6 +1521,11 @@ def repository_settings_post(username, repository):
# Remove the site
result = celery_tasks.delete_site.delay(repo.route)
if repo.has_site == 2 or (had_site == 2 and had_site != repo.has_site):
# Deploy all other sites which were destroyed by the primary site
for other_repo in Repo.query.filter_by(owner=repo.owner, has_site=1):
result = celery_tasks.copy_site.delay(other_repo.route)
return flask.redirect(f"/{username}/{repository}/settings", 303)
celery_tasks.py
@@ -92,11 +92,9 @@ def copy_site(route):
from models import Repo
repo = db.session.get(Repo, route)
server_repo_location = os.path.join(config.REPOS_PATH, route.lstrip("/"))
if repo.has_site == 2:
subdomain = repo.owner.username
else:
subdomain = repo.name + "." + repo.owner.username
site_location = os.path.join(config.SITE_PATH, subdomain)
subdomain = repo.owner.username
subpath = repo.name if repo.has_site != 2 else "."
site_location = os.path.join(config.SITE_PATH, subdomain, subpath)
# Get the branch to be used for the site; if it somehow doesn't exist, use the default branch.
branch = repo.site_branch or repo.default_branch
# Make a shallow clone of the repo; this prevents getting the full git database when it's not needed.
@@ -104,17 +102,20 @@ def copy_site(route):
# Delete the old site.
shutil.rmtree(site_location)
common.git_command(config.SITE_PATH, b"", "clone", "--depth=1", f"--branch={branch}", os.path.join(os.getcwd(), server_repo_location), subdomain)
common.git_command(config.SITE_PATH, b"", "clone", "--depth=1", f"--branch={branch}", os.path.join(os.getcwd(), server_repo_location), os.path.join(subdomain, subpath))
@shared_task(ignore_result=False)
def delete_site(route):
from models import Repo
repo = db.session.get(Repo, route)
if repo.has_site == 2:
subdomain = repo.owner.username
else:
subdomain = repo.name + "." + repo.owner.username
site_location = os.path.join(config.SITE_PATH, subdomain)
subdomain = repo.owner.username
subpath = repo.name if repo.has_site != 2 else "."
site_location = os.path.join(config.SITE_PATH, subdomain, subpath)
if os.path.isdir(site_location):
shutil.rmtree(site_location)
# Redo the primary site.
primary_site = Repo.query.filter_by(owner=repo.owner, has_site=2).first()
if primary_site:
copy_site(primary_site.route)