diff --git a/Makefile b/Makefile index 7c3c25a256b1cd92fb50cd551728a9a7e1fef5a0..3dd614c86ac23378503faeb83ea56ac0ea4bf49c 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,7 @@ help: @echo "Application:" @echo " run Run the application on port ${PORT}" @echo " shell Access the Django shell" + @echo " sync Sync with the old contract registry" @echo "" @echo "Database:" @echo " migrations Generate migrations" @@ -47,6 +48,9 @@ run: venv shell: venv ${VENV}/bin/python manage.py shell --settings=${SETTINGS} +sync: + ${VENV}/bin/python manage.py import_old_contracts https://github.com/pirati-web/smlouvy.pirati.cz.git gh-pages --settings=${SETTINGS} --delete -v 3 + migrations: venv ${VENV}/bin/python manage.py makemigrations --settings=${SETTINGS} diff --git a/contracts/management/commands/import_old_contracts.py b/contracts/management/commands/import_old_contracts.py index e2758e160f1024d7a9ec24cb7f330d5c3d243f93..36a3b9e416f290261f1736fd9e15495626ec8f46 100644 --- a/contracts/management/commands/import_old_contracts.py +++ b/contracts/management/commands/import_old_contracts.py @@ -2,6 +2,7 @@ import io import os import re import string +import shutil from datetime import date, datetime import yaml @@ -57,6 +58,11 @@ class Command(BaseCommand): type=str, help="Directory to store the cloned repository in", ) + parser.add_argument( + "--delete", + action="store_true", + help="Delete the old temporary storage directory, if it exists.", + ) parser.add_argument( "--existing", action="store_true", @@ -1339,7 +1345,7 @@ class Command(BaseCommand): (options["directory"] if options["directory"] is not None else "git"), ) - if os.path.exists(git_dir): + if os.path.exists(git_dir) and not options["delete"]: if not options["existing"]: if self.verbosity >= 1: self.stderr.write( @@ -1356,6 +1362,12 @@ class Command(BaseCommand): if self.verbosity >= 2: self.stdout.write("Using existing git storage directory.") else: + if options["delete"] and os.path.exists(git_dir): + if self.verbosity >= 2: + self.stdout.write("Deleting old git storage directory.") + + shutil.rmtree(git_dir) + if self.verbosity >= 2: self.stdout.write("Cloning repository.")