mirror of
https://expo.survex.com/repositories/expoweb/.git/
synced 2025-03-25 11:41:53 +00:00
[svn r8190] MOre work on abstracting the file locations on scanned survey notes
This commit is contained in:
parent
2f0eb4f25f
commit
7d1c2b6615
troggle
@ -25,9 +25,15 @@ def listdir(*path):
|
|||||||
c = reduce(urljoin, strippedpath)
|
c = reduce(urljoin, strippedpath)
|
||||||
else:
|
else:
|
||||||
c = ""
|
c = ""
|
||||||
print strippedpath, c
|
c = c.replace("#", "%23")
|
||||||
return urllib.urlopen(settings.FILES + "listdir/" + c)
|
print "FILE: ", settings.FILES + "listdir/" + c
|
||||||
|
return urllib.urlopen(settings.FILES + "listdir/" + c).read()
|
||||||
|
|
||||||
|
def dirsAsList(*path):
|
||||||
|
return [d for d in listdir(*path).split("\n") if len(d) > 0 and d[-1] == "/"]
|
||||||
|
|
||||||
|
def filesAsList(*path):
|
||||||
|
return [d for d in listdir(*path).split("\n") if len(d) > 0 and d[-1] != "/"]
|
||||||
|
|
||||||
def readFile(*path):
|
def readFile(*path):
|
||||||
try:
|
try:
|
||||||
|
@ -350,6 +350,7 @@ class Photo(models.Model):
|
|||||||
scansFileStorage = FileSystemStorage(location=settings.SURVEYS, base_url=settings.SURVEYS_URL)
|
scansFileStorage = FileSystemStorage(location=settings.SURVEYS, base_url=settings.SURVEYS_URL)
|
||||||
def get_scan_path(instance, filename):
|
def get_scan_path(instance, filename):
|
||||||
year=instance.survey.expedition.year
|
year=instance.survey.expedition.year
|
||||||
|
print "WN: ", type(instance.survey.wallet_number), instance.survey.wallet_number
|
||||||
number="%02d" % instance.survey.wallet_number + str(instance.survey.wallet_letter) #using %02d string formatting because convention was 2009#01
|
number="%02d" % instance.survey.wallet_number + str(instance.survey.wallet_letter) #using %02d string formatting because convention was 2009#01
|
||||||
return os.path.join('./',year,year+r'#'+number,instance.contents+str(instance.number_in_wallet)+r'.jpg')
|
return os.path.join('./',year,year+r'#'+number,instance.contents+str(instance.number_in_wallet)+r'.jpg')
|
||||||
|
|
||||||
|
@ -14,10 +14,11 @@ import troggle.expo.fileAbstraction as fileAbstraction
|
|||||||
import csv
|
import csv
|
||||||
import re
|
import re
|
||||||
import datetime
|
import datetime
|
||||||
|
import cStringIO
|
||||||
|
|
||||||
surveytab = fileAbstraction.readFile("Surveys.csv")
|
surveytab = fileAbstraction.readFile("Surveys.csv")
|
||||||
dialect=csv.Sniffer().sniff(surveytab)
|
dialect=csv.Sniffer().sniff(surveytab)
|
||||||
surveyreader = csv.reader(surveytab,dialect=dialect)
|
surveyreader = csv.reader(cStringIO.StringIO(surveytab),dialect=dialect)
|
||||||
print surveyreader
|
print surveyreader
|
||||||
headers = surveyreader.next()
|
headers = surveyreader.next()
|
||||||
header = dict(zip(headers, range(len(headers)))) #set up a dictionary where the indexes are header names and the values are column numbers
|
header = dict(zip(headers, range(len(headers)))) #set up a dictionary where the indexes are header names and the values are column numbers
|
||||||
@ -50,12 +51,13 @@ for survey in surveyreader:
|
|||||||
|
|
||||||
# add survey scans
|
# add survey scans
|
||||||
def parseSurveyScans(year):
|
def parseSurveyScans(year):
|
||||||
yearDirList = [d for d in fileAbstraction.listdir(year.year).split("\n") if d[-1] == "/"]
|
yearDirList = fileAbstraction.dirsAsList(year.year)
|
||||||
for surveyFolder in yearDirList:
|
for surveyFolder in yearDirList:
|
||||||
print surveyFolder
|
print surveyFolder
|
||||||
try:
|
try:
|
||||||
surveyNumber=re.match(r'\d\d\d\d#0*(\d+)',surveyFolder).groups()
|
surveyNumber=re.match(r'\d\d\d\d#0*(\d+)',surveyFolder).groups()
|
||||||
scanList=fileAbstraction.listdir(yearPath, surveyFolder).split("\n")
|
scanList=fileAbstraction.filesAsList(year.year, surveyFolder)
|
||||||
|
print "BAR: ", year.year, surveyFolder, scanList
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
print surveyFolder + " ignored"
|
print surveyFolder + " ignored"
|
||||||
continue
|
continue
|
||||||
@ -63,6 +65,7 @@ def parseSurveyScans(year):
|
|||||||
for scan in scanList:
|
for scan in scanList:
|
||||||
try:
|
try:
|
||||||
scanChopped=re.match(r'(?i).*(notes|elev|plan|elevation|extend)(\d*)\.(png|jpg|jpeg)',scan).groups()
|
scanChopped=re.match(r'(?i).*(notes|elev|plan|elevation|extend)(\d*)\.(png|jpg|jpeg)',scan).groups()
|
||||||
|
print "BAR: ", scanChopped
|
||||||
scanType,scanNumber,scanFormat=scanChopped
|
scanType,scanNumber,scanFormat=scanChopped
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
print "Adding scans: " + scan + " ignored"
|
print "Adding scans: " + scan + " ignored"
|
||||||
@ -86,7 +89,7 @@ def parseSurveyScans(year):
|
|||||||
number_in_wallet=scanNumber,
|
number_in_wallet=scanNumber,
|
||||||
survey=survey
|
survey=survey
|
||||||
)
|
)
|
||||||
#print "Added scanned image at " + str(scanObj)
|
print "Added scanned image at " + str(scanObj)
|
||||||
scanObj.save()
|
scanObj.save()
|
||||||
|
|
||||||
for year in models.Expedition.objects.filter(year__gte=2000): #expos since 2000, because paths and filenames were nonstandard before then
|
for year in models.Expedition.objects.filter(year__gte=2000): #expos since 2000, because paths and filenames were nonstandard before then
|
||||||
|
Loading…
x
Reference in New Issue
Block a user