summaryrefslogtreecommitdiffstats
path: root/parsers/surveys.py
diff options
context:
space:
mode:
authorsubstantialnoninfringinguser <substantialnoninfringinguser@gmail.com>2009-05-13 05:58:18 +0100
committersubstantialnoninfringinguser <substantialnoninfringinguser@gmail.com>2009-05-13 05:58:18 +0100
commite8da6b9b8b0d5390d26832af42550c4e651a82dd (patch)
tree3839c6f56e0e502294b3c360d417facfdf33bf3d /parsers/surveys.py
parent4b34241a16af5e9cbfff0c3b2ede76394e94a3b5 (diff)
downloadtroggle-e8da6b9b8b0d5390d26832af42550c4e651a82dd.tar.gz
troggle-e8da6b9b8b0d5390d26832af42550c4e651a82dd.tar.bz2
troggle-e8da6b9b8b0d5390d26832af42550c4e651a82dd.zip
[svn] Further attempts to make troggle work on windows using surveys stored on an external server
settings.PHOTOS changed to setting.PHOTO_ROOT Made databaseReset.py get info from external server if appropriate (hope this did not break linus disk based scripts) Still needs more work, to get everything working Auto create photos directory if it does not already exist Copied from http://cucc@cucc.survex.com/svn/trunk/expoweb/troggle/, rev. 8262 by julian @ 3/2/2009 1:30 AM
Diffstat (limited to 'parsers/surveys.py')
-rw-r--r--parsers/surveys.py24
1 files changed, 18 insertions, 6 deletions
diff --git a/parsers/surveys.py b/parsers/surveys.py
index 53632e8..ca2f153 100644
--- a/parsers/surveys.py
+++ b/parsers/surveys.py
@@ -13,7 +13,11 @@ import csv
import re
import datetime
-surveytab = open(os.path.join(settings.SURVEYS, "Surveys.csv"))
+try:
+ surveytab = open(os.path.join(settings.SURVEYS, "Surveys.csv"))
+except IOError:
+ import cStringIO, urllib
+ surveytab = cStringIO.StringIO(urllib.urlopen(settings.SURVEYS + "download/Surveys.csv").read())
dialect=csv.Sniffer().sniff(surveytab.read())
surveytab.seek(0,0)
surveyreader = csv.reader(surveytab,dialect=dialect)
@@ -29,7 +33,7 @@ models.Survey.objects.all().delete()
for survey in surveyreader:
walletNumberLetter = re.match(r'(?P<number>\d*)(?P<letter>[a-zA-Z]*)',survey[header['Survey Number']]) #I hate this, but some surveys have a letter eg 2000#34a. This line deals with that.
# print walletNumberLetter.groups()
-
+
surveyobj = models.Survey(
expedition = models.Expedition.objects.filter(year=survey[header['Year']])[0],
wallet_number = walletNumberLetter.group('number'),
@@ -43,15 +47,23 @@ for survey in surveyreader:
pass
surveyobj.save()
print "added survey " + survey[header['Year']] + "#" + surveyobj.wallet_number + "\r",
-
+
+def listdir(*directories):
+ try:
+ return os.listdir(os.path.join(settings.SURVEYS, *directories))
+ except:
+ import urllib
+ url = settings.SURVEYS + reduce(lambda x, y: x + "/" + y, ["listdir"] + list(directories))
+ folders = urllib.urlopen(url.replace("#", "%23")).readlines()
+ return [folder.rstrip(r"/") for folder in folders]
+
# add survey scans
def parseSurveyScans(year):
- yearPath=os.path.join(settings.SURVEYS, year.year)
- yearFileList=os.listdir(yearPath)
+ yearFileList = listdir(year.year)
for surveyFolder in yearFileList:
try:
surveyNumber=re.match(r'\d\d\d\d#0*(\d+)',surveyFolder).groups()
- scanList=os.listdir(os.path.join(yearPath,surveyFolder))
+ scanList = listdir(year.year, surveyFolder)
except AttributeError:
print surveyFolder + " ignored",
continue