2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-11-25 08:41:51 +00:00

[svn] Continued file abstracted work, to get survey files from either hard disk or the web.

Copied from http://cucc@cucc.survex.com/svn/trunk/expoweb/troggle/, rev. 8173 by julian @ 1/18/2009 12:45 AM
This commit is contained in:
substantialnoninfringinguser 2009-05-13 05:34:52 +01:00
parent 832f1f53c6
commit b66189bc9e
3 changed files with 43 additions and 33 deletions

25
expo/fileAbstraction.py Normal file
View File

@ -0,0 +1,25 @@
import troggle.settings as settings
import os
def urljoin(x, y): return x + "/" + y
def listdir(*path):
try:
l = ""
root = os.path.join(settings.FILES, *path)
for p in os.listdir(root):
if os.path.isdir(os.path.join(root, p)):
l += p + "/\n"
elif os.path.isfile(os.path.join(root, p)):
l += p + "\n"
#Ignore non-files and non-directories
return l
except:
return urllib.urlopen(settings.FILES + "listdir/" + reduce(urljoin, path))
def readFile(*path):
try:
f = open(os.path.join(settings.FILES, *path))
except:
f = urllib.urlopen(settings.FILES + "download/" + reduce(urljoin, path))
return f.read()

View File

@ -1,38 +1,22 @@
import troggle.settings as settings
import fileAbstraction
from django.http import HttpResponse, Http404
import os
def listdir(request, path):
try:
l = []
print settings.FILES, "t", path, "t"
root = os.path.join(settings.FILES, path)
print root
for p in os.listdir(root):
if os.path.isdir(os.path.join(root, p)):
l.append(p + "/")
elif os.path.isfile(os.path.join(root, p)):
l.append(p)
#Ignore non-files and non-directories
return HttpResponse(str(l), mimetype = "text/plain")
except:
try:
return HttpResponse(urllib.urlopen(settings.FILES + "listdir/" + name), mimetype = "text/plain")
except:
raise Http404
#try:
return HttpResponse(fileAbstraction.listdir(path), mimetype = "text/plain")
#except:
# raise Http404
def upload(request, path):
pass
def download(request, path):
try:
f = open(os.path.join(settings.FILES, path))
except:
try:
f = urllib.urlopen(settings.FILES + "download/" + path)
except:
raise Http404
return HttpResponse(f.read(), mimetype=getMimeType(path.split(".")[-1]))
#try:
return HttpResponse(fileAbstraction.readFile(path), mimetype=getMimeType(path.split(".")[-1]))
#except:
# raise Http404
def getMimeType(extension):
try:

View File

@ -7,6 +7,7 @@ from troggle import *
os.environ['DJANGO_SETTINGS_MODULE']='troggle.settings'
import troggle.settings as settings
import troggle.expo.models as models
import fileAbstraction
#import settings
#import expo.models as models
@ -16,9 +17,9 @@ import datetime
def openFileOrWeb(name):
try:
f = open(os.path.join(settings.SURVEYS, name))
f = open(os.path.join(settings.FILES, name))
except:
f = urllib.urlopen(settings.SURVEYS + name)
f = urllib.urlopen(settings.FILES + "download/" + name)
return f.readlines()
surveytab = openFileOrWeb("Surveys.csv")
@ -57,12 +58,12 @@ for survey in surveyreader:
# add survey scans
def parseSurveyScans(year):
yearPath=os.path.join(settings.SURVEYS, year.year)
yearFileList=os.listdir(yearPath)
for surveyFolder in yearFileList:
yearDirList = [d for d in fileAbstraction.listdir(year.year).split("\n") if d[-1] == "/"]
for surveyFolder in yearDirList:
print surveyFolder
try:
surveyNumber=re.match(r'\d\d\d\d#0*(\d+)',surveyFolder).groups()
scanList=os.listdir(os.path.join(yearPath,surveyFolder))
scanList=fileAbstraction.listdir(yearPath, surveyFolder).split("\n")
except AttributeError:
print surveyFolder + " ignored"
continue