summaryrefslogtreecommitdiffstats
path: root/expo/fileAbstraction.py
blob: deb1a4a68e1b545116b0fafd904513d60466f7fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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()