2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-11-25 00:31:55 +00:00

moved 2 funct, deletion of FileAbstraction pending

This commit is contained in:
Philip Sargent 2020-06-04 23:38:57 +01:00
parent ac9ac5e397
commit 27816724f8
3 changed files with 48 additions and 47 deletions

View File

@ -48,7 +48,7 @@ class SimpleTest(SimpleTestCase):
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import get_object_or_404, render
from troggle.core.models import Expedition
from troggle.core.models_caves import CaveSlug, Cave, CaveAndEntrance, Survey, QM, CaveDescription, EntranceSlug, Entrance, Area, SurvexStation
from troggle.core.models_caves import CaveSlug, Cave, CaveAndEntrance, QM, CaveDescription, EntranceSlug, Entrance, Area, SurvexStation
from troggle.core.forms import CaveForm, CaveAndEntranceFormSet, VersionControlCommentForm, EntranceForm, EntranceLetterForm
from troggle.helper import login_required_if_public

View File

@ -1,44 +1,15 @@
import troggle.settings as settings
import os
import urllib.request, urllib.parse, urllib.error
from functools import reduce
# import troggle.settings as settings
# import os
# import urllib.request, urllib.parse, urllib.error
# from functools import reduce
def urljoin(x, y): return x + "/" + y
# All unused, but kept pending deletion
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"
# def urljoin(x, y): return x + "/" + y
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 dirsAsList(*path):
# return [d for d in listdir(*path).split("\n") if len(d) > 0 and d[-1] == "/"]
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 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.request.urlopen(settings.FILES + "download/" + reduce(urljoin, path))
return f.read()

View File

@ -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,9 +8,39 @@ 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:
@ -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