summaryrefslogtreecommitdiffstats
path: root/core/fileAbstraction.py
diff options
context:
space:
mode:
authorsubstantialnoninfringinguser <substantialnoninfringinguser@gmail.com>2009-07-02 20:43:18 +0100
committersubstantialnoninfringinguser <substantialnoninfringinguser@gmail.com>2009-07-02 20:43:18 +0100
commite565a6b73b70f670335c4a095992eab26a1bfbf9 (patch)
treea93c4069e8d858b77e9527e794305f97946d21b1 /core/fileAbstraction.py
parent5baddea474b068ece9d6b93bcc90f4d76f97e5a3 (diff)
downloadtroggle-e565a6b73b70f670335c4a095992eab26a1bfbf9.tar.gz
troggle-e565a6b73b70f670335c4a095992eab26a1bfbf9.tar.bz2
troggle-e565a6b73b70f670335c4a095992eab26a1bfbf9.zip
[svn] Renaming troggle.expo to troggle.core. To do this, used:
perl -p -i -e "s/expo(?=[\s\.']+)/core/g" `find -name \*.py` and then manually checked each change (had to remove a couple)
Diffstat (limited to 'core/fileAbstraction.py')
-rw-r--r--core/fileAbstraction.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/core/fileAbstraction.py b/core/fileAbstraction.py
new file mode 100644
index 0000000..94b8b0c
--- /dev/null
+++ b/core/fileAbstraction.py
@@ -0,0 +1,43 @@
+import troggle.settings as settings
+import os
+import urllib
+
+def urljoin(x, y): return x + "/" + y
+
+def listdir(*path):
+ try:
+ strippedpath = [p for p in path if p]
+ root = os.path.join(settings.FILES, *strippedpath )
+ l = ""
+ #l = root + "\n"
+ isdir = os.path.isdir(root) #This seems to be required for os.path.isdir to work...
+ #l += str(isdir) + "\n"
+ 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:
+ if strippedpath:
+ c = reduce(urljoin, strippedpath)
+ else:
+ c = ""
+ c = c.replace("#", "%23")
+ print "FILE: ", settings.FILES + "listdir/" + c
+ return urllib.urlopen(settings.FILES + "listdir/" + c).read()
+
+def dirsAsList(*path):
+ return [d for d in listdir(*path).split("\n") if len(d) > 0 and d[-1] == "/"]
+
+def filesAsList(*path):
+ return [d for d in listdir(*path).split("\n") if len(d) > 0 and d[-1] != "/"]
+
+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