Skip to content

Commit

Permalink
Merge pull request HelloZeroNet#842 from mishfit/refactorListAndWalk
Browse files Browse the repository at this point in the history
Rename SiteStorage.list to SiteStorage.walk
  • Loading branch information
HelloZeroNet authored Mar 4, 2017
2 parents 7d85a10 + 656c818 commit 0e2f742
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 6 deletions.
2 changes: 1 addition & 1 deletion plugins/Mute/MutePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def changeDb(self, auth_address, action):
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:
Expand Down
2 changes: 1 addition & 1 deletion src/Content/ContentManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ def hashFiles(self, dir_inner_path, ignore_pattern=None, optional_pattern=None):
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
Expand Down
7 changes: 6 additions & 1 deletion src/Site/SiteStorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def rename(self, inner_path_before, inner_path_after):
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("\\", "/")
Expand All @@ -213,6 +213,11 @@ def list(self, dir_inner_path):
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
Expand Down
13 changes: 11 additions & 2 deletions src/Test/TestSiteStorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,20 @@

@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"]
6 changes: 5 additions & 1 deletion src/Ui/UiWebsocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def __init__(self, ws, site, server, user, request):
"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):
Expand Down Expand Up @@ -525,6 +525,10 @@ def actionFileQuery(self, to, dir_inner_path, query):

# 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
Expand Down

0 comments on commit 0e2f742

Please sign in to comment.