Merge pull request #842 from mishfit/refactorListAndWalk

Rename SiteStorage.list to SiteStorage.walk
This commit is contained in:
ZeroNet 2017-03-04 12:39:06 +01:00 committed by GitHub
commit 0e2f742b7e
5 changed files with 24 additions and 6 deletions

View file

@ -36,7 +36,7 @@ class UiWebsocketPlugin(object):
if not site:
continue
dir_inner_path = helper.getDirname(row["inner_path"])
for file_name in site.storage.list(dir_inner_path):
for file_name in site.storage.walk(dir_inner_path):
if action == "remove":
site.storage.onUpdated(dir_inner_path + file_name, False)
else:

View file

@ -458,7 +458,7 @@ class ContentManager(object):
ignored = True
self.log.error("- [ERROR] Only ascii encoded directories allowed: %s" % dir_inner_path)
for file_relative_path in self.site.storage.list(dir_inner_path):
for file_relative_path in self.site.storage.walk(dir_inner_path):
file_name = helper.getFilename(file_relative_path)
ignored = optional = False

View file

@ -202,7 +202,7 @@ class SiteStorage(object):
raise err
# List files from a directory
def list(self, dir_inner_path):
def walk(self, dir_inner_path):
directory = self.getPath(dir_inner_path)
for root, dirs, files in os.walk(directory):
root = root.replace("\\", "/")
@ -213,6 +213,11 @@ class SiteStorage(object):
else:
yield file_name
# list directories in a directory
def list(self, dir_inner_path):
directory = self.getPath(dir_inner_path)
return os.listdir(directory)
# Site content updated
def onUpdated(self, inner_path, file=None):
# Update Sql cache

View file

@ -3,11 +3,20 @@ import pytest
@pytest.mark.usefixtures("resetSettings")
class TestSiteStorage:
def testWalk(self, site):
# Rootdir
walk_root = list(site.storage.walk(""))
assert "content.json" in walk_root
assert "css/all.css" in walk_root
# Subdir
assert list(site.storage.walk("data-default")) == ["data.json", "users/content-default.json"]
def testList(self, site):
# Rootdir
list_root = list(site.storage.list(""))
assert "content.json" in list_root
assert "css/all.css" in list_root
assert "css/all.css" not in list_root
# Subdir
assert list(site.storage.list("data-default")) == ["data.json", "users/content-default.json"]
assert list(site.storage.list("data-default")) == ["data.json", "users"]

View file

@ -37,7 +37,7 @@ class UiWebsocket(object):
"channelJoinAllsite", "serverUpdate", "serverPortcheck", "serverShutdown", "certSet", "configSet",
"actionPermissionAdd", "actionPermissionRemove"
)
self.async_commands = ("fileGet", "fileList")
self.async_commands = ("fileGet", "fileList", "dirList")
# Start listener loop
def start(self):
@ -525,6 +525,10 @@ class UiWebsocket(object):
# List files in directory
def actionFileList(self, to, inner_path):
return self.response(to, list(self.site.storage.walk(inner_path)))
# List directories in a directory
def actionDirList(self, to, inner_path):
return self.response(to, list(self.site.storage.list(inner_path)))
# Sql query