def getFile(self,fileName):
"""Return file itself
"""
# TODO: set propper Content/type
try:
if fileName.find(".shp") or fileName.find(".tab"):
(path,fn) = os.path.split(fileName)
old_path = os.path.abspath(os.path.curdir)
os.chdir(path)
fn_noext = os.path.splitext(fn)[0]
from zipfile import ZipFile
from io import BytesIO
filelike = BytesIO()
zipout = ZipFile(filelike,"w")
for f in os.listdir(os.path.curdir):
if f.find(fn_noext) > -1:
zipout.write(f)
zipout.close()
web.header('Content-Disposition','attachment; filename="%s.zip"'% fn_noext)
os.chdir(old_path)
fn_noext = os.path.splitext(fn)[0]
return (200, filelike.getvalue())
else:
return (200, open(fileName).read())
except Exception as e:
message = "LayEd: getFile(): Unable to read from the file named '" + fileName + "'. Exception received: " + str(e)
raise LaymanError(500, message)
评论列表
文章目录