mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2025-12-14 18:47:04 +00:00
tidying and prep for python3
This commit is contained in:
@@ -1,20 +1,26 @@
|
||||
from __future__ import (absolute_import, division,
|
||||
print_function)
|
||||
import os
|
||||
import time
|
||||
import timeit
|
||||
import json
|
||||
|
||||
import settings
|
||||
os.environ['PYTHONPATH'] = settings.PYTHON_PATH
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings')
|
||||
|
||||
from django.core import management
|
||||
from django.db import connection, close_old_connections
|
||||
from django.contrib.auth.models import User
|
||||
from django.http import HttpResponse
|
||||
from django.core.urlresolvers import reverse
|
||||
|
||||
from troggle.core.models import Cave, Entrance
|
||||
import troggle.settings
|
||||
import troggle.flatpages.models
|
||||
import json
|
||||
import troggle.logbooksdump
|
||||
|
||||
# NOTE databaseRest.py is *imported* by views_other.py as it is used in the control panel
|
||||
# NOTE databaseReset.py is *imported* by views_other.py as it is used in the control panel
|
||||
# presented there.
|
||||
|
||||
expouser=settings.EXPOUSER
|
||||
@@ -60,52 +66,52 @@ def dirsredirect():
|
||||
f.save()
|
||||
|
||||
def import_caves():
|
||||
import parsers.caves
|
||||
import troggle.parsers.caves
|
||||
print("Importing Caves")
|
||||
parsers.caves.readcaves()
|
||||
troggle.parsers.caves.readcaves()
|
||||
|
||||
def import_people():
|
||||
import parsers.people
|
||||
import troggle.parsers.people
|
||||
print("Importing People (folk.csv)")
|
||||
parsers.people.LoadPersonsExpos()
|
||||
troggle.parsers.people.LoadPersonsExpos()
|
||||
|
||||
def import_logbooks():
|
||||
import parsers.logbooks
|
||||
import troggle.parsers.logbooks
|
||||
print("Importing Logbooks")
|
||||
parsers.logbooks.LoadLogbooks()
|
||||
troggle.parsers.logbooks.LoadLogbooks()
|
||||
|
||||
def import_QMs():
|
||||
print("Importing QMs (old caves)")
|
||||
import parsers.QMs
|
||||
import troggle.parsers.QMs
|
||||
# import process itself runs on qm.csv in only 3 old caves, not the modern ones!
|
||||
|
||||
def import_survexblks():
|
||||
import parsers.survex
|
||||
import troggle.parsers.survex
|
||||
print("Importing Survex Blocks")
|
||||
parsers.survex.LoadAllSurvexBlocks()
|
||||
troggle.parsers.survex.LoadAllSurvexBlocks()
|
||||
|
||||
def import_survexpos():
|
||||
import parsers.survex
|
||||
import troggle.parsers.survex
|
||||
print("Importing Survex x/y/z Positions")
|
||||
parsers.survex.LoadPos()
|
||||
troggle.parsers.survex.LoadPos()
|
||||
|
||||
def import_surveyimgs():
|
||||
"""This appears to store data in unused objects. The code is kept
|
||||
for future re-working to manage progress against notes, plans and elevs.
|
||||
"""
|
||||
import parsers.surveys
|
||||
print("Importing survey images")
|
||||
parsers.surveys.parseSurveys(logfile=settings.LOGFILE)
|
||||
#import troggle.parsers.surveys
|
||||
print("NOT Importing survey images")
|
||||
#troggle.parsers.surveys.parseSurveys(logfile=settings.LOGFILE)
|
||||
|
||||
def import_surveyscans():
|
||||
import parsers.surveys
|
||||
import troggle.parsers.surveys
|
||||
print("Importing Survey Scans")
|
||||
parsers.surveys.LoadListScans()
|
||||
troggle.parsers.surveys.LoadListScans()
|
||||
|
||||
def import_tunnelfiles():
|
||||
import parsers.surveys
|
||||
import troggle.parsers.surveys
|
||||
print("Importing Tunnel files")
|
||||
parsers.surveys.LoadTunnelFiles()
|
||||
troggle.parsers.surveys.LoadTunnelFiles()
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# These functions moved to a different file - not used currently.
|
||||
@@ -152,7 +158,7 @@ class JobQueue():
|
||||
for j in data:
|
||||
self.results[j] = data[j]
|
||||
except:
|
||||
print "FAILURE parsing JSON file %s" % (self.tfile)
|
||||
print("FAILURE parsing JSON file %s" % (self.tfile))
|
||||
# Python bug: https://github.com/ShinNoNoir/twitterwebsearch/issues/12
|
||||
f.close()
|
||||
for j in self.results_order:
|
||||
@@ -176,7 +182,7 @@ class JobQueue():
|
||||
"""Run all the jobs in the queue provided - once
|
||||
"""
|
||||
|
||||
print "** Running job ", self.runlabel
|
||||
print("** Running job ", self.runlabel)
|
||||
jobstart = time.time()
|
||||
self.results["date"].pop()
|
||||
self.results["date"].append(jobstart)
|
||||
@@ -187,14 +193,14 @@ class JobQueue():
|
||||
start = time.time()
|
||||
i[1]() # looks ugly but invokes function passed in the second item in the tuple
|
||||
duration = time.time()-start
|
||||
print "\n*- Ended \"", i[0], "\" %.1f seconds" % duration
|
||||
print("\n*- Ended \"", i[0], "\" %.1f seconds" % duration)
|
||||
self.results[i[0]].pop() # the null item
|
||||
self.results[i[0]].append(duration)
|
||||
|
||||
|
||||
jobend = time.time()
|
||||
jobduration = jobend-jobstart
|
||||
print "** Ended job %s - %.1f seconds total." % (self.runlabel,jobduration)
|
||||
print("** Ended job %s - %.1f seconds total." % (self.runlabel,jobduration))
|
||||
|
||||
return True
|
||||
|
||||
@@ -221,7 +227,7 @@ class JobQueue():
|
||||
else:
|
||||
skipmem = True
|
||||
|
||||
print "-- ", settings.DATABASES['default']['NAME'], settings.DATABASES['default']['ENGINE']
|
||||
print("-- ", settings.DATABASES['default']['NAME'], settings.DATABASES['default']['ENGINE'])
|
||||
#print "-- DATABASES.default", settings.DATABASES['default']
|
||||
|
||||
if dbname ==":memory:":
|
||||
@@ -251,8 +257,8 @@ class JobQueue():
|
||||
'PORT': ''}
|
||||
|
||||
|
||||
print "-- ", settings.DATABASES['default']['NAME'], settings.DATABASES['default']['ENGINE']
|
||||
print "-- DATABASES.default", settings.DATABASES['default']
|
||||
print("-- ", settings.DATABASES['default']['NAME'], settings.DATABASES['default']['ENGINE'])
|
||||
#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 jobqueue may not start from scratch so we need to initialise the db properly first
|
||||
@@ -282,7 +288,7 @@ class JobQueue():
|
||||
settings.DATABASES['default'] = dbdefault
|
||||
settings.DATABASES['default']['ENGINE'] = dbengine
|
||||
settings.DATABASES['default']['NAME'] = dbname
|
||||
print "-- ", settings.DATABASES['default']['NAME'], settings.DATABASES['default']['ENGINE']
|
||||
print("-- ", settings.DATABASES['default']['NAME'], settings.DATABASES['default']['ENGINE'])
|
||||
|
||||
django.db.close_old_connections() # maybe not needed here
|
||||
for j in self.results_order:
|
||||
@@ -308,9 +314,9 @@ class JobQueue():
|
||||
elif k =="test":
|
||||
break
|
||||
elif k =="date":
|
||||
print " days ago ",
|
||||
print(" days ago ", end=' ')
|
||||
else:
|
||||
print '%10s (s)' % k,
|
||||
print('%10s (s)' % k, end=' ')
|
||||
percen=0
|
||||
r = self.results[k]
|
||||
|
||||
@@ -320,26 +326,30 @@ class JobQueue():
|
||||
rp = r[i]
|
||||
else:
|
||||
rp = " - "
|
||||
print '%8s' % rp,
|
||||
print('%8s' % rp, end=' ')
|
||||
elif k =="date":
|
||||
# Calculate dates as days before present
|
||||
if r[i]:
|
||||
if i == len(r)-1:
|
||||
print " this",
|
||||
print(" this", end=' ')
|
||||
else:
|
||||
# prints one place to the left of where you expect
|
||||
days = (r[i]-r[len(r)-1])/(24*60*60)
|
||||
print '%8.2f' % days,
|
||||
if r[len(r)-1]:
|
||||
s = r[i]-r[len(r)-1]
|
||||
else:
|
||||
s = 0
|
||||
days = (s)/(24*60*60)
|
||||
print('%8.2f' % days, end=' ')
|
||||
elif r[i]:
|
||||
print '%8.1f' % r[i],
|
||||
print('%8.1f' % r[i], end=' ')
|
||||
if i == len(r)-1 and r[i-1]:
|
||||
percen = 100* (r[i] - r[i-1])/r[i-1]
|
||||
if abs(percen) >0.1:
|
||||
print '%8.1f%%' % percen,
|
||||
print('%8.1f%%' % percen, end=' ')
|
||||
else:
|
||||
print " - ",
|
||||
print ""
|
||||
print "\n"
|
||||
print(" - ", end=' ')
|
||||
print("")
|
||||
print("\n")
|
||||
return True
|
||||
|
||||
|
||||
@@ -438,13 +448,15 @@ if __name__ == "__main__":
|
||||
elif "dumplogbooks" in sys.argv: # untested in 2020
|
||||
dumplogbooks()
|
||||
elif "profile" in sys.argv:
|
||||
jq.loadprofiles()
|
||||
jq.showprofile()
|
||||
exit()
|
||||
elif "help" in sys.argv:
|
||||
usage()
|
||||
exit()
|
||||
else:
|
||||
usage()
|
||||
print("%s not recognised as a command." % sys.argv[1])
|
||||
print(("%s not recognised as a command." % sys.argv[1]))
|
||||
exit()
|
||||
|
||||
jq.run()
|
||||
|
||||
Reference in New Issue
Block a user