mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2024-11-25 16:51:54 +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:
parent
832f1f53c6
commit
b66189bc9e
25
expo/fileAbstraction.py
Normal file
25
expo/fileAbstraction.py
Normal 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()
|
@ -1,38 +1,22 @@
|
|||||||
import troggle.settings as settings
|
import fileAbstraction
|
||||||
from django.http import HttpResponse, Http404
|
from django.http import HttpResponse, Http404
|
||||||
import os
|
|
||||||
|
|
||||||
def listdir(request, path):
|
def listdir(request, path):
|
||||||
try:
|
#try:
|
||||||
l = []
|
return HttpResponse(fileAbstraction.listdir(path), mimetype = "text/plain")
|
||||||
print settings.FILES, "t", path, "t"
|
#except:
|
||||||
root = os.path.join(settings.FILES, path)
|
# raise Http404
|
||||||
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
|
|
||||||
|
|
||||||
def upload(request, path):
|
def upload(request, path):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def download(request, path):
|
def download(request, path):
|
||||||
try:
|
#try:
|
||||||
f = open(os.path.join(settings.FILES, path))
|
return HttpResponse(fileAbstraction.readFile(path), mimetype=getMimeType(path.split(".")[-1]))
|
||||||
except:
|
#except:
|
||||||
try:
|
# raise Http404
|
||||||
f = urllib.urlopen(settings.FILES + "download/" + path)
|
|
||||||
except:
|
|
||||||
raise Http404
|
|
||||||
return HttpResponse(f.read(), mimetype=getMimeType(path.split(".")[-1]))
|
|
||||||
|
|
||||||
def getMimeType(extension):
|
def getMimeType(extension):
|
||||||
try:
|
try:
|
||||||
|
@ -7,6 +7,7 @@ from troggle import *
|
|||||||
os.environ['DJANGO_SETTINGS_MODULE']='troggle.settings'
|
os.environ['DJANGO_SETTINGS_MODULE']='troggle.settings'
|
||||||
import troggle.settings as settings
|
import troggle.settings as settings
|
||||||
import troggle.expo.models as models
|
import troggle.expo.models as models
|
||||||
|
import fileAbstraction
|
||||||
|
|
||||||
#import settings
|
#import settings
|
||||||
#import expo.models as models
|
#import expo.models as models
|
||||||
@ -16,9 +17,9 @@ import datetime
|
|||||||
|
|
||||||
def openFileOrWeb(name):
|
def openFileOrWeb(name):
|
||||||
try:
|
try:
|
||||||
f = open(os.path.join(settings.SURVEYS, name))
|
f = open(os.path.join(settings.FILES, name))
|
||||||
except:
|
except:
|
||||||
f = urllib.urlopen(settings.SURVEYS + name)
|
f = urllib.urlopen(settings.FILES + "download/" + name)
|
||||||
return f.readlines()
|
return f.readlines()
|
||||||
|
|
||||||
surveytab = openFileOrWeb("Surveys.csv")
|
surveytab = openFileOrWeb("Surveys.csv")
|
||||||
@ -57,12 +58,12 @@ for survey in surveyreader:
|
|||||||
|
|
||||||
# add survey scans
|
# add survey scans
|
||||||
def parseSurveyScans(year):
|
def parseSurveyScans(year):
|
||||||
yearPath=os.path.join(settings.SURVEYS, year.year)
|
yearDirList = [d for d in fileAbstraction.listdir(year.year).split("\n") if d[-1] == "/"]
|
||||||
yearFileList=os.listdir(yearPath)
|
for surveyFolder in yearDirList:
|
||||||
for surveyFolder in yearFileList:
|
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=os.listdir(os.path.join(yearPath,surveyFolder))
|
scanList=fileAbstraction.listdir(yearPath, surveyFolder).split("\n")
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
print surveyFolder + " ignored"
|
print surveyFolder + " ignored"
|
||||||
continue
|
continue
|
||||||
|
Loading…
Reference in New Issue
Block a user