2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2025-12-14 04:38:16 +00:00

Fix un-cleared db error (partial)

This commit is contained in:
Philip Sargent
2020-06-07 16:16:35 +01:00
parent 75bac01f3a
commit fcfda644d3
2 changed files with 93 additions and 10 deletions

View File

@@ -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: