2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2025-07-28 21:36:38 +01:00
Files
core
management
templatetags
__init__.py
admin.py
context.py
fileAbstraction.py
forms.py
imagekit_specs.py
imageposcalc.ods
models.py
models_survex.py
view_surveys.py
views.py
views_caves.py
views_logbooks.py
views_other.py
views_survex.py
docker
docsEtc
export
flatpages
helper
imagekit
media
parsers
profiles
templates
wiki
.hgignore
README.txt
__init__.py
databaseReset.py
localsettingspotatohut.py
localsettingsserver.py
localsettingsubuntu.py
localsettingswindows.py
manage.py
middleware.py
modelviz.py
settings.py
urls.py
utils.py
wsgi.py
troggle/core/fileAbstraction.py
Sam Wenham 7f92a7280d Prevent troggle adding the menu if there is one in the file
Add a Docker compose file to bring up a dev troggle easily
Various PEP improvments
2019-02-23 15:30:58 +00:00

43 lines
1.4 KiB
Python

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) #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.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 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.urlopen(settings.FILES + "download/" + reduce(urljoin, path))
return f.read()