summaryrefslogtreecommitdiffstats
path: root/parsers/surveys.py
diff options
context:
space:
mode:
authorgoatchurch <goatchurch@ubuntu.clocksoft.dom>2009-09-10 22:07:31 +0100
committergoatchurch <goatchurch@ubuntu.clocksoft.dom>2009-09-10 22:07:31 +0100
commit735b729a414fdda2e4b832c58707decb19aaae6c (patch)
tree91d23745102961bdb4ce5c8e30c54ac69d33a59b /parsers/surveys.py
parentc5b933f922f922c7c3a3a2c3d11e8b866fe790b6 (diff)
downloadtroggle-735b729a414fdda2e4b832c58707decb19aaae6c.tar.gz
troggle-735b729a414fdda2e4b832c58707decb19aaae6c.tar.bz2
troggle-735b729a414fdda2e4b832c58707decb19aaae6c.zip
survey scans features added
Diffstat (limited to 'parsers/surveys.py')
-rw-r--r--parsers/surveys.py57
1 files changed, 55 insertions, 2 deletions
diff --git a/parsers/surveys.py b/parsers/surveys.py
index ff78355..9f7ba10 100644
--- a/parsers/surveys.py
+++ b/parsers/surveys.py
@@ -2,8 +2,8 @@ import sys, os, types, logging
#sys.path.append('C:\\Expo\\expoweb')
#from troggle import *
#os.environ['DJANGO_SETTINGS_MODULE']='troggle.settings'
-import troggle.settings as settings
-from troggle.core.models import *
+import settings
+from core.models import *
from PIL import Image
#import settings
#import core.models as models
@@ -146,3 +146,56 @@ def isInterlacedPNG(filePath): #We need to check for interlaced PNGs because the
return file.info['interlace']
else:
return False
+
+
+# handles url or file
+def GetListDir(sdir):
+ res = [ ]
+ if sdir[:7] == "http://":
+ s = urllib.urlopen(sdir)
+ else:
+ for f in os.listdir(sdir):
+ if f[0] != ".":
+ ff = os.path.join(sdir, f)
+ res.append((f, ff, os.path.isdir(ff)))
+ return res
+
+# this iterates through the scans directories (either here or on the remote server)
+# and builds up the models we can access later
+def LoadListScans(surveyscansdir):
+ SurvexScanSingle.objects.all().delete()
+ SurvexScansFolder.objects.all().delete()
+
+ for f, ff, fisdir in GetListDir(surveyscansdir):
+ if not fisdir:
+ continue
+
+ # do the year folders
+ if re.match("\d\d\d\d$", f):
+ for fy, ffy, fisdiry in GetListDir(ff):
+ assert fisdiry, ffy
+ survexscansfolder = SurvexScansFolder(fpath=ffy, walletname=fy)
+ survexscansfolder.save()
+ for fyf, ffyf, fisdiryf in GetListDir(ffy):
+ assert not fisdiryf, ffyf
+ survexscansingle = SurvexScanSingle(ffile=ffyf, name=fyf, survexscansfolder=survexscansfolder)
+ survexscansingle.save()
+ elif f != "thumbs":
+ survexscansfolder = SurvexScansFolder(fpath=ff, walletname=f)
+ survexscansfolder.save()
+ gld = [ ]
+
+ # flatten out any directories in these book files
+ for (fyf, ffyf, fisdiryf) in GetListDir(ff):
+ if fisdiryf:
+ gld.extend(GetListDir(ffyf))
+ else:
+ gld.append((fyf, ffyf, fisdiryf))
+
+ for (fyf, ffyf, fisdiryf) in gld:
+ assert not fisdiryf, ffyf
+ survexscansingle = SurvexScanSingle(ffile=ffyf, name=fyf, survexscansfolder=survexscansfolder)
+ survexscansingle.save()
+
+
+ \ No newline at end of file