diff options
author | Philip Sargent <philip@Muscogee.localdomain> | 2020-05-14 17:21:34 +0100 |
---|---|---|
committer | Philip Sargent <philip@Muscogee.localdomain> | 2020-05-14 17:21:34 +0100 |
commit | ccc5813b3f7e2e07d2792e8e7aabb371005b4a62 (patch) | |
tree | 8a4ddbf824a7d8b696a0e50bb47acd2a41ab7479 /databaseReset.py | |
parent | 314d0e8b710703706d41fbc4d2567445214509f1 (diff) | |
download | troggle-ccc5813b3f7e2e07d2792e8e7aabb371005b4a62.tar.gz troggle-ccc5813b3f7e2e07d2792e8e7aabb371005b4a62.tar.bz2 troggle-ccc5813b3f7e2e07d2792e8e7aabb371005b4a62.zip |
indent recursion and update comments
Diffstat (limited to 'databaseReset.py')
-rw-r--r-- | databaseReset.py | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/databaseReset.py b/databaseReset.py index 2400048..43d5e04 100644 --- a/databaseReset.py +++ b/databaseReset.py @@ -108,6 +108,7 @@ def import_tunnelfiles(): parsers.surveys.LoadTunnelFiles() # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# These functions moved to a different file - not used currently. #import logbooksdump #def import_auto_logbooks(): #def dumplogbooks(): @@ -172,7 +173,7 @@ class JobQueue(): return True def runqonce(self): - """Run all the jobs in the queue provided once + """Run all the jobs in the queue provided - once """ print "** Running job ", self.runlabel @@ -199,6 +200,12 @@ class JobQueue(): def run(self): + """First runs all the jobs in the queue against a scratch in-memory db + then re-runs the import against the db specified in settings.py + Default behaviour is to skip the in-memory phase. + When MySQL is the db the in-memory phase crashes as MySQL does not properly + relinquish some kind of db connection (not fixed yet) + """ self.loadprofiles() # save db settings for later dbengine = settings.DATABASES['default']['ENGINE'] @@ -214,15 +221,15 @@ class JobQueue(): else: skipmem = True + print "-- ", settings.DATABASES['default']['NAME'], settings.DATABASES['default']['ENGINE'] + #print "-- DATABASES.default", settings.DATABASES['default'] + if dbname ==":memory:": # just run, and save the sql file - print "-- ", settings.DATABASES['default']['NAME'], settings.DATABASES['default']['ENGINE'] - print "-- DATABASES.default", settings.DATABASES['default'] self.runqonce() - self.memdumpsql() + self.memdumpsql() # saved contents of scratch db, could be imported later.. self.saveprofiles() elif skipmem: - print "-- DATABASES.default", settings.DATABASES['default'] self.runqonce() self.saveprofiles() else: @@ -248,9 +255,9 @@ class JobQueue(): print "-- DATABASES.default", settings.DATABASES['default'] # but because the user may be expecting to add this to a db with lots of tables already there, - # the jobque may not start from scratch so we need to initialise the db properly first + # the jobqueue may not start from scratch so we need to initialise the db properly first # because we are using an empty :memory: database - # But initiating twice crashes, so be sure to do it once only. + # But initiating twice crashes it; so be sure to do it once only. # Damn. syncdb() is still calling MySQL somehow **conn_params not sqlite3. So crashes on expo server. @@ -259,9 +266,9 @@ class JobQueue(): if ("dirsredirect",dirsredirect) not in self.queue: dirsredirect() if ("caves",import_caves) not in self.queue: - import_caves() # sometime extract the initialising code from this and put in reinit + import_caves() # sometime extract the initialising code from this and put in reinit... if ("people",import_people) not in self.queue: - import_people() # sometime extract the initialising code from this and put in reinit + import_people() # sometime extract the initialising code from this and put in reinit... django.db.close_old_connections() # maybe not needed here @@ -284,7 +291,6 @@ class JobQueue(): django.db.close_old_connections() # magic rune. works. found by looking in django.db__init__.py #django.setup() # should this be needed? - self.runqonce() # crashes because it thinks it has no migrations to apply, when it does. self.saveprofiles() @@ -292,7 +298,8 @@ class JobQueue(): return True def showprofile(self): - """Prints out the time it took to run the jobqueue""" + """Prints out the time it took to run the jobqueue + """ for k in self.results_order: if k =="dirsredirect": break @@ -306,7 +313,6 @@ class JobQueue(): print '%10s (s)' % k, percen=0 r = self.results[k] - #print "min=",min for i in range(len(r)): if k == "runlabel": @@ -432,9 +438,9 @@ if __name__ == "__main__": #parse_descriptions() # no longer present # elif "writeCaves" in sys.argv: # writeCaves() # no longer present - elif "autologbooks" in sys.argv: + elif "autologbooks" in sys.argv: # untested in 2020 import_auto_logbooks() - elif "dumplogbooks" in sys.argv: + elif "dumplogbooks" in sys.argv: # untested in 2020 dumplogbooks() else: usage() |