summaryrefslogtreecommitdiffstats
path: root/expo/fileAbstraction.py
blob: 44314800fdf61567ccfbdf09ea80de6e30b4b4a2 (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
26
27
28
29
30
31
32
33
34
35
36
37
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)
        #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 = ""
        print strippedpath, c
        return urllib.urlopen(settings.FILES + "listdir/" + c)


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