[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()