From b66189bc9e506109766b7377a46b0321bcca71e5 Mon Sep 17 00:00:00 2001 From: substantialnoninfringinguser Date: Wed, 13 May 2009 05:34:52 +0100 Subject: [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 --- expo/fileAbstraction.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 expo/fileAbstraction.py (limited to 'expo/fileAbstraction.py') diff --git a/expo/fileAbstraction.py b/expo/fileAbstraction.py new file mode 100644 index 0000000..deb1a4a --- /dev/null +++ b/expo/fileAbstraction.py @@ -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() \ No newline at end of file -- cgit v1.2.3