2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-11-22 15:21:52 +00:00

[svn] Changes to file abstraction, that seemed to make it work by magic

Copied from http://cucc@cucc.survex.com/svn/trunk/expoweb/troggle/, rev. 8182 by julian @ 1/18/2009 5:07 PM
This commit is contained in:
substantialnoninfringinguser 2009-05-13 05:36:17 +01:00
parent f229ff35f9
commit 7f159a283a

View File

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