forked from expo/troggle
moved 2 funct, deletion of FileAbstraction pending
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user