Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add update command to manage.py #247

Merged
merged 1 commit into from
Jul 25, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions pytition/petition/management/commands/update.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import subprocess
from functools import partial
from django.core.management.base import BaseCommand
from django.conf import settings
from pathlib import Path
import os

run = partial(subprocess.run, shell=True, check=True)


class Command(BaseCommand):
"""Update pytition install
"""

def handle(self, *args, **options):
try:
git_path = Path(settings.BASE_DIR).parent
os.chdir(git_path)
run("git checkout master && git pull")

version_cmd = "curl -s https://api.github.com/repos/pytition/pytition/releases/latest | grep 'tag_name' | cut -d : -f2,3 | tr -d \\\" | tr -d ,"
version = run(version_cmd, capture_output=True).stdout.decode().strip()

checkout_cmd = f"git checkout {version}"
run(checkout_cmd)

run("pip3 install --upgrade -r requirements.txt")

os.chdir(settings.BASE_DIR)
run("python3 manage.py migrate")
run("python3 manage.py collectstatic --no-input")
run("python3 manage.py compilemessages")
except subprocess.CalledProcessError as e:
print(e)
if e.stdout != None:
print(f"stdout: {e.stdout}")
if e.stderr != None:
print(f"stderr:{e.stderr}")