diff options
author | goatchurch <goatchurch@ubuntu.clocksoft.dom> | 2009-09-11 23:56:47 +0100 |
---|---|---|
committer | goatchurch <goatchurch@ubuntu.clocksoft.dom> | 2009-09-11 23:56:47 +0100 |
commit | 12cf3a6d534e5038b5d78b11a03cef2b81f5f852 (patch) | |
tree | 30d6f4e0891ae28750ca9dd97c74432c17683384 /parsers | |
parent | b80168c099b5805dfc9c1fee576d00cabc31e2d2 (diff) | |
download | troggle-12cf3a6d534e5038b5d78b11a03cef2b81f5f852.tar.gz troggle-12cf3a6d534e5038b5d78b11a03cef2b81f5f852.tar.bz2 troggle-12cf3a6d534e5038b5d78b11a03cef2b81f5f852.zip |
tunnelfiles scheme added
Diffstat (limited to 'parsers')
-rw-r--r-- | parsers/logbooks.py | 51 | ||||
-rw-r--r-- | parsers/survex.py | 6 | ||||
-rw-r--r-- | parsers/surveys.py | 35 |
3 files changed, 43 insertions, 49 deletions
diff --git a/parsers/logbooks.py b/parsers/logbooks.py index ec314b6..7d7d7d1 100644 --- a/parsers/logbooks.py +++ b/parsers/logbooks.py @@ -88,14 +88,14 @@ def EnterLogIntoDbase(date, place, title, text, trippeople, expedition, logtime_ cave=GetCaveLookup().get(lplace)
#Check for an existing copy of the current entry, and save
+ expeditionday = expedition.get_expedition_day(date)
lookupAttribs={'date':date, 'title':title}
- nonLookupAttribs={'place':place, 'text':text, 'author':author, 'expedition':expedition, 'cave':cave, 'slug':slugify(title)[:50]}
+ nonLookupAttribs={'place':place, 'text':text, 'author':author, 'expedition':expedition, 'expeditionday':expeditionday, 'cave':cave, 'slug':slugify(title)[:50]}
lbo, created=save_carefully(models.LogbookEntry, lookupAttribs, nonLookupAttribs)
- expeditiondate = expedition.get_expedition_date(date)
for tripperson, time_underground in trippersons:
- lookupAttribs={'person_expedition':tripperson, 'logbook_entry':lbo}
- nonLookupAttribs={'time_underground':time_underground, 'date':date, 'expeditiondate':expeditiondate, 'is_logbook_entry_author':(tripperson == author)}
+ lookupAttribs={'personexpedition':tripperson, 'logbook_entry':lbo}
+ nonLookupAttribs={'time_underground':time_underground, 'date':date, 'expeditionday':expeditionday, 'is_logbook_entry_author':(tripperson == author)}
#print nonLookupAttribs
save_carefully(models.PersonTrip, lookupAttribs, nonLookupAttribs)
@@ -281,10 +281,6 @@ def SetDatesFromLogbookEntries(expedition): """
for personexpedition in expedition.personexpedition_set.all():
persontrips = personexpedition.persontrip_set.order_by('logbook_entry__date')
- personexpedition.date_from = min([persontrip.logbook_entry.date for persontrip in persontrips] or [None])
- personexpedition.date_to = max([persontrip.logbook_entry.date for persontrip in persontrips] or [None])
- personexpedition.save()
-
# sequencing is difficult to do
lprevpersontrip = None
for persontrip in persontrips:
@@ -296,46 +292,11 @@ def SetDatesFromLogbookEntries(expedition): lprevpersontrip = persontrip
persontrip.save()
- # from trips rather than logbook entries, which may include events outside the expedition
- expedition.date_from = min([personexpedition.date_from for personexpedition in expedition.personexpedition_set.all() if personexpedition.date_from] or [None])
- expedition.date_to = max([personexpedition.date_to for personexpedition in expedition.personexpedition_set.all() if personexpedition.date_to] or [None])
- expedition.save()
-
-# The below has been replaced with the methods get_next_by_id and get_previous_by_id
-# # order by appearance in the logbook (done by id)
-# lprevlogbookentry = None
-# for logbookentry in expedition.logbookentry_set.order_by('id'):
-# logbookentry.logbookentry_prev = lprevlogbookentry
-# if lprevlogbookentry:
-# lprevlogbookentry.logbookentry_next = logbookentry
-# lprevlogbookentry.save()
-# logbookentry.logbookentry_next = None
-# logbookentry.save()
-# lprevlogbookentry = logbookentry
-
-# This combined date / number key is a weird way of doing things. Use the primary key instead. If we are going to use the date for looking up entries, we should set it up to allow multiple results.
- # order by date for setting the references
-# lprevlogbookentry = None
-# for logbookentry in expedition.logbookentry_set.order_by('date'):
-# if lprevlogbookentry and lprevlogbookentry.date == logbookentry.date:
-# mcount = re.search("_(\d+)$", lprevlogbookentry.href)
-# mc = mcount and (int(mcount.group(1)) + 1) or 1
-# logbookentry.href = "%s_%d" % (logbookentry.date, mc)
-# else:
-# logbookentry.href = "%s" % logbookentry.date
-# logbookentry.save()
-# lprevlogbookentry = logbookentry
-
def LoadLogbookForExpedition(expedition):
""" Parses all logbook entries for one expedition """
-
- #We're checking for stuff that's changed in admin before deleting it now.
- #print "deleting logbooks for", expedition
- #expedition.logbookentry_set.all().delete()
- #models.PersonTrip.objects.filter(person_expedition__expedition=expedition).delete()
-
+
expowebbase = os.path.join(settings.EXPOWEB, "years")
year = str(expedition.year)
for lyear, lloc, parsefunc in yearlinks:
@@ -347,7 +308,7 @@ def LoadLogbookForExpedition(expedition): fin.close()
parsefunc(year, expedition, txt)
SetDatesFromLogbookEntries(expedition)
- return "TOLOAD: " + year + " " + str(expedition.personexpedition_set.all()[1].logbookentry_set.count()) + " " + str(models.PersonTrip.objects.filter(person_expedition__expedition=expedition).count())
+ return "TOLOAD: " + year + " " + str(expedition.personexpedition_set.all()[1].logbookentry_set.count()) + " " + str(models.PersonTrip.objects.filter(personexpedition__expedition=expedition).count())
def LoadLogbooks():
diff --git a/parsers/survex.py b/parsers/survex.py index 985d4e5..f8ec6d4 100644 --- a/parsers/survex.py +++ b/parsers/survex.py @@ -69,7 +69,6 @@ def RecursiveLoad(survexblock, survexfile, fin, textlines): mref = comment and re.match('.*?ref.*?(\d+)\s*#\s*(\d+)', comment) if mref: refscan = "%s#%s" % (mref.group(1), mref.group(2)) - print refscan survexscansfolders = models.SurvexScansFolder.objects.filter(walletname=refscan) if survexscansfolders: survexblock.survexscansfolder = survexscansfolders[0] @@ -125,7 +124,9 @@ def RecursiveLoad(survexblock, survexfile, fin, textlines): if expeditions: assert len(expeditions) == 1 survexblock.expedition = expeditions[0] - survexblock.expeditiondate = survexblock.expedition.get_expedition_day(survexblock.date) + survexblock.expeditionday = survexblock.expedition.get_expedition_day(survexblock.date) + survexblock.save() + elif re.match("team$(?i)", cmd): mteammember = re.match("(Insts|Notes|Tape|Dog|Useless|Pics|Helper|Disto|Consultant)\s+(.*)$(?i)", line) if mteammember: @@ -135,6 +136,7 @@ def RecursiveLoad(survexblock, survexfile, fin, textlines): if (personexpedition, tm) not in teammembers: teammembers.append((personexpedition, tm)) personrole = models.SurvexPersonRole(survexblock=survexblock, nrole=mteammember.group(1).lower(), personexpedition=personexpedition, personname=tm) + personrole.expeditionday = survexblock.expeditionday if personexpedition: personrole.person=personexpedition.person personrole.save() diff --git a/parsers/surveys.py b/parsers/surveys.py index 9f7ba10..86f6405 100644 --- a/parsers/surveys.py +++ b/parsers/surveys.py @@ -24,6 +24,7 @@ def get_or_create_placeholder(year): placeholder_logbook_entry, newly_created = save_carefully(LogbookEntry, lookupAttribs, nonLookupAttribs)
return placeholder_logbook_entry
+# dead
def readSurveysFromCSV():
try: # could probably combine these two
surveytab = open(os.path.join(settings.SURVEY_SCANS, "Surveys.csv"))
@@ -75,6 +76,7 @@ def readSurveysFromCSV(): logging.info("added survey " + survey[header['Year']] + "#" + surveyobj.wallet_number + "\r")
+# dead
def listdir(*directories):
try:
return os.listdir(os.path.join(settings.SURVEYS, *directories))
@@ -134,11 +136,13 @@ def parseSurveyScans(year, logfile=None): continue
scanObj.save()
+# dead
def parseSurveys(logfile=None):
readSurveysFromCSV()
for year in Expedition.objects.filter(year__gte=2000): #expos since 2000, because paths and filenames were nonstandard before then
parseSurveyScans(year)
+# dead
def isInterlacedPNG(filePath): #We need to check for interlaced PNGs because the thumbnail engine can't handle them (uses PIL)
file=Image.open(filePath)
print filePath
@@ -148,10 +152,11 @@ def isInterlacedPNG(filePath): #We need to check for interlaced PNGs because the return False
-# handles url or file
+# handles url or file, so we can refer to a set of scans on another server
def GetListDir(sdir):
res = [ ]
if sdir[:7] == "http://":
+ assert False, "Not written"
s = urllib.urlopen(sdir)
else:
for f in os.listdir(sdir):
@@ -198,4 +203,30 @@ def LoadListScans(surveyscansdir): survexscansingle.save()
-
\ No newline at end of file +
+def LoadTunnelFiles(tunneldatadir):
+ TunnelFile.objects.all().delete()
+ tunneldirs = [ "" ]
+ while tunneldirs:
+ tunneldir = tunneldirs.pop()
+ for f in os.listdir(os.path.join(tunneldatadir, tunneldir)):
+ if f[0] == "." or f[-1] == "~":
+ continue
+ lf = os.path.join(tunneldir, f)
+ ff = os.path.join(tunneldatadir, lf)
+ if os.path.isdir(ff):
+ tunneldirs.append(lf)
+ elif f[-4:] == ".xml":
+ fin = open(ff)
+ mtype = re.search("<(fontcolours|sketch)", fin.read(200))
+ assert mtype, lf
+ fin.close()
+ tunnelfile = TunnelFile(tunnelpath=lf, bfontcolours=(mtype.group(1)=="fontcolours"))
+ tunnelfile.save()
+
+
+# survexscans = models.ManyToManyField("SurvexScanSingle")
+# survexblocks = models.ManyToManyField("SurvexBlock")
+# tunnelcontains = models.ManyToManyField("TunnelFile") # case when its a frame type
+
+
|