diff options
author | Philip Sargent <philip.sargent@klebos.com> | 2020-06-04 23:38:57 +0100 |
---|---|---|
committer | Philip Sargent <philip.sargent@klebos.com> | 2020-06-04 23:38:57 +0100 |
commit | 27816724f81f1655bd605cdbd3161a19a0222dfe (patch) | |
tree | 80c2eaa64fff36989381c7792d3427689e83e4ef /core/view_surveys.py | |
parent | ac9ac5e397884770f801b787126b2b30ab9b5c93 (diff) | |
download | troggle-27816724f81f1655bd605cdbd3161a19a0222dfe.tar.gz troggle-27816724f81f1655bd605cdbd3161a19a0222dfe.tar.bz2 troggle-27816724f81f1655bd605cdbd3161a19a0222dfe.zip |
moved 2 funct, deletion of FileAbstraction pending
Diffstat (limited to 'core/view_surveys.py')
-rw-r--r-- | core/view_surveys.py | 42 |
1 files changed, 36 insertions, 6 deletions
diff --git a/core/view_surveys.py b/core/view_surveys.py index db33557..d78c3e6 100644 --- a/core/view_surveys.py +++ b/core/view_surveys.py @@ -1,5 +1,5 @@ from django.conf import settings -from . import fileAbstraction +#from . import fileAbstraction from django.shortcuts import render_to_response from django.http import HttpResponse, Http404 import os, stat @@ -8,10 +8,40 @@ from troggle.core.models_survex import SurvexScansFolder, SurvexScanSingle, Surv import parsers.surveys import urllib.request, urllib.parse, urllib.error -# inline fileabstraction into here if it's not going to be useful anywhere else -# keep things simple and ignore exceptions everywhere for now - +# inlined use of fileabstraction into here +def fa_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.request.urlopen(settings.FILES + "listdir/" + c).read() + +def fa_readFile(*path): + try: + f = open(os.path.join(settings.FILES, *path)) + except: + f = urllib.request.urlopen(settings.FILES + "download/" + reduce(urljoin, path)) + return f.read() + def getMimeType(extension): try: return {"txt": "text/plain", @@ -24,7 +54,7 @@ def getMimeType(extension): def listdir(request, path): #try: - return HttpResponse(fileAbstraction.listdir(path), content_type="text/plain") + return HttpResponse(fa_listdir(path), content_type="text/plain") #except: # raise Http404 @@ -34,7 +64,7 @@ def upload(request, path): def download(request, path): #try: - return HttpResponse(fileAbstraction.readFile(path), content_type=getMimeType(path.split(".")[-1])) + return HttpResponse(fa_readFile(path), content_type=getMimeType(path.split(".")[-1])) #except: # raise Http404 |