summaryrefslogtreecommitdiffstats
path: root/databaseReset.py
diff options
context:
space:
mode:
authorPhilip Sargent <philip.sargent@klebos.com>2020-06-07 16:16:35 +0100
committerPhilip Sargent <philip.sargent@klebos.com>2020-06-07 16:16:35 +0100
commitfcfda644d3a05c365217bff9f12a16bb343a57d5 (patch)
tree7409e039cb7e5a3a516d6317de95ff286fbe3802 /databaseReset.py
parent75bac01f3a1cf9a5daedf66dc390b668ecd11620 (diff)
downloadtroggle-fcfda644d3a05c365217bff9f12a16bb343a57d5.tar.gz
troggle-fcfda644d3a05c365217bff9f12a16bb343a57d5.tar.bz2
troggle-fcfda644d3a05c365217bff9f12a16bb343a57d5.zip
Fix un-cleared db error (partial)
Diffstat (limited to 'databaseReset.py')
-rw-r--r--databaseReset.py29
1 files changed, 19 insertions, 10 deletions
diff --git a/databaseReset.py b/databaseReset.py
index 0d5d5c2..2d08492 100644
--- a/databaseReset.py
+++ b/databaseReset.py
@@ -39,7 +39,7 @@ if os.geteuid() == 0:
expouser=settings.EXPOUSER
expouserpass=settings.EXPOUSERPASS
expouseremail=settings.EXPOUSER_EMAIL
-print(" - SETTINGS: {} ({:.5}...) <{}> on module loading".format(expouser, expouserpass, expouseremail))
+print(" - settings: {} ({:.5}...) <{}> on module loading".format(expouser, expouserpass, expouseremail))
@@ -47,12 +47,16 @@ def reinit_db():
"""Rebuild database from scratch. Deletes the file first if sqlite is used,
otherwise it drops the database and creates it.
"""
+ django.db.close_old_connections() # wipes an in-memory sqlite db
currentdbname = settings.DATABASES['default']['NAME']
- if settings.DATABASES['default']['ENGINE'] == 'django.db.backends.sqlite3':
+ if settings.DATABASES['default']['NAME'] == ':memory:':
+ pass
+ elif settings.DATABASES['default']['ENGINE'] == 'django.db.backends.sqlite3':
try:
os.remove(currentdbname)
except OSError:
- pass
+ print(" ! OSError on removing: " + currentdbname + " (Is the file open in another app?\n")
+ raise
else:
cursor = connection.cursor()
cursor.execute("DROP DATABASE %s" % currentdbname)
@@ -65,12 +69,17 @@ def reinit_db():
def syncuser():
"""Sync user - needed after reload
"""
- print("Synchronizing user")
+ print(" - Synchronizing user on: " + settings.DATABASES['default']['NAME'])
management.call_command('migrate', interactive=False)
- user = User.objects.create_user(expouser, expouseremail, expouserpass)
- user.is_staff = True
- user.is_superuser = True
- user.save()
+ try:
+ user = User.objects.create_user(expouser, expouseremail, expouserpass)
+ user.is_staff = True
+ user.is_superuser = True
+ user.save()
+ except:
+ print(" ! INTEGRITY ERROR user on: " + settings.DATABASES['default']['NAME'])
+ print(" ! You probably have not got a clean db when you thought you had.\n")
+ raise
def dirsredirect():
"""Make directories that troggle requires and sets up page redirects
@@ -438,7 +447,7 @@ if __name__ == "__main__":
runlabel=None
jq = JobQueue(runlabel)
- jq.run_now_django_tests(1)
+ #jq.run_now_django_tests(1)
if len(sys.argv)==1:
usage()
@@ -446,7 +455,7 @@ if __name__ == "__main__":
elif "test" in sys.argv:
jq.enq("caves",import_caves)
jq.enq("people",import_people)
- #jq.run_now_django_tests(2)
+ jq.run_now_django_tests(2)
elif "caves" in sys.argv:
jq.enq("caves",import_caves)
elif "logbooks" in sys.argv: