[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

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: