Support fileList command of archives
This commit is contained in:
parent
7048987157
commit
e8a0d56ff8
1 changed files with 22 additions and 4 deletions
|
@ -16,7 +16,7 @@ def closeArchive(archive_path):
|
||||||
del archive_cache[archive_path]
|
del archive_cache[archive_path]
|
||||||
|
|
||||||
|
|
||||||
def openArchive(archive_path, path_within):
|
def openArchive(archive_path):
|
||||||
if archive_path not in archive_cache:
|
if archive_path not in archive_cache:
|
||||||
if archive_path.endswith("tar.gz"):
|
if archive_path.endswith("tar.gz"):
|
||||||
import tarfile
|
import tarfile
|
||||||
|
@ -30,7 +30,10 @@ def openArchive(archive_path, path_within):
|
||||||
gevent.spawn_later(5, lambda: closeArchive(archive_path)) # Close after 5 sec
|
gevent.spawn_later(5, lambda: closeArchive(archive_path)) # Close after 5 sec
|
||||||
|
|
||||||
archive = archive_cache[archive_path]
|
archive = archive_cache[archive_path]
|
||||||
|
return archive
|
||||||
|
|
||||||
|
def openArchiveFile(archive_path, path_within):
|
||||||
|
archive = openArchive(archive_path)
|
||||||
if archive_path.endswith(".zip"):
|
if archive_path.endswith(".zip"):
|
||||||
return archive.open(path_within)
|
return archive.open(path_within)
|
||||||
else:
|
else:
|
||||||
|
@ -56,7 +59,7 @@ class UiRequestPlugin(object):
|
||||||
if not result:
|
if not result:
|
||||||
return self.error404(path)
|
return self.error404(path)
|
||||||
try:
|
try:
|
||||||
file = openArchive(archive_path, path_within)
|
file = openArchiveFile(archive_path, path_within)
|
||||||
content_type = self.getContentType(file_path)
|
content_type = self.getContentType(file_path)
|
||||||
self.sendHeader(200, content_type=content_type, noscript=kwargs.get("header_noscript", False))
|
self.sendHeader(200, content_type=content_type, noscript=kwargs.get("header_noscript", False))
|
||||||
return self.streamFile(file)
|
return self.streamFile(file)
|
||||||
|
@ -84,7 +87,22 @@ class SiteStoragePlugin(object):
|
||||||
def isFile(self, inner_path):
|
def isFile(self, inner_path):
|
||||||
if ".zip/" in inner_path or ".tar.gz/" in inner_path:
|
if ".zip/" in inner_path or ".tar.gz/" in inner_path:
|
||||||
match = re.match("^(.*\.(?:tar.gz|tar.bz2|zip))/(.*)", inner_path)
|
match = re.match("^(.*\.(?:tar.gz|tar.bz2|zip))/(.*)", inner_path)
|
||||||
inner_archive_path, path_within = match.groups()
|
archive_inner_path, path_within = match.groups()
|
||||||
return super(SiteStoragePlugin, self).isFile(inner_archive_path)
|
return super(SiteStoragePlugin, self).isFile(archive_inner_path)
|
||||||
else:
|
else:
|
||||||
return super(SiteStoragePlugin, self).isFile(inner_path)
|
return super(SiteStoragePlugin, self).isFile(inner_path)
|
||||||
|
|
||||||
|
def walk(self, inner_path):
|
||||||
|
if ".zip" in inner_path or ".tar.gz" in inner_path:
|
||||||
|
match = re.match("^(.*\.(?:tar.gz|tar.bz2|zip))(.*)", inner_path)
|
||||||
|
archive_inner_path, path_within = match.groups()
|
||||||
|
archive = openArchive(self.getPath(archive_inner_path))
|
||||||
|
if archive_inner_path.endswith(".zip"):
|
||||||
|
namelist = [name for name in archive.namelist() if not name.endswith("/")]
|
||||||
|
else:
|
||||||
|
namelist = [item.name for item in archive.getmembers() if not item.isdir()]
|
||||||
|
return namelist
|
||||||
|
|
||||||
|
else:
|
||||||
|
return super(SiteStoragePlugin, self).walk(inner_path)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue