Merge pull request #116 from zeronet-conservancy/cm-impr
improve code in ContentManager
This commit is contained in:
commit
ff5274c753
1 changed files with 9 additions and 20 deletions
|
@ -401,10 +401,10 @@ class ContentManager(object):
|
||||||
# Return: { "sha512": "c29d73d...21f518", "size": 41 , "content_inner_path": "content.json"}
|
# Return: { "sha512": "c29d73d...21f518", "size": 41 , "content_inner_path": "content.json"}
|
||||||
def getFileInfo(self, inner_path, new_file=False):
|
def getFileInfo(self, inner_path, new_file=False):
|
||||||
dirs = inner_path.split("/") # Parent dirs of content.json
|
dirs = inner_path.split("/") # Parent dirs of content.json
|
||||||
inner_path_parts = [dirs.pop()] # Filename relative to content.json
|
inner_path_parts = [] # Filename relative to content.json
|
||||||
while True:
|
while dirs:
|
||||||
content_inner_path = "%s/content.json" % "/".join(dirs)
|
inner_path_parts.insert(0, dirs.pop())
|
||||||
content_inner_path = content_inner_path.strip("/")
|
content_inner_path = f'{"/".join(dirs)}/content.json'.strip('/')
|
||||||
content = self.contents.get(content_inner_path)
|
content = self.contents.get(content_inner_path)
|
||||||
|
|
||||||
# Check in files
|
# Check in files
|
||||||
|
@ -447,12 +447,6 @@ class ContentManager(object):
|
||||||
back["optional"] = None
|
back["optional"] = None
|
||||||
return back
|
return back
|
||||||
|
|
||||||
# No inner path in this dir, lets try the parent dir
|
|
||||||
if dirs:
|
|
||||||
inner_path_parts.insert(0, dirs.pop())
|
|
||||||
else: # No more parent dirs
|
|
||||||
break
|
|
||||||
|
|
||||||
# Not found
|
# Not found
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -472,20 +466,15 @@ class ContentManager(object):
|
||||||
|
|
||||||
dirs = inner_path.split("/") # Parent dirs of content.json
|
dirs = inner_path.split("/") # Parent dirs of content.json
|
||||||
inner_path_parts = [dirs.pop()] # Filename relative to content.json
|
inner_path_parts = [dirs.pop()] # Filename relative to content.json
|
||||||
inner_path_parts.insert(0, dirs.pop()) # Dont check in self dir
|
# Dont check in self dir
|
||||||
while True:
|
while dirs:
|
||||||
content_inner_path = "%s/content.json" % "/".join(dirs)
|
inner_path_parts.insert(0, dirs.pop())
|
||||||
parent_content = self.contents.get(content_inner_path.strip("/"))
|
content_inner_path = f'{"/".join(dirs)}/content.json'.strip('/')
|
||||||
|
parent_content = self.contents.get(content_inner_path)
|
||||||
if parent_content and "includes" in parent_content:
|
if parent_content and "includes" in parent_content:
|
||||||
return parent_content["includes"].get("/".join(inner_path_parts))
|
return parent_content["includes"].get("/".join(inner_path_parts))
|
||||||
elif parent_content and "user_contents" in parent_content:
|
elif parent_content and "user_contents" in parent_content:
|
||||||
return self.getUserContentRules(parent_content, inner_path, content)
|
return self.getUserContentRules(parent_content, inner_path, content)
|
||||||
else: # No inner path in this dir, lets try the parent dir
|
|
||||||
if dirs:
|
|
||||||
inner_path_parts.insert(0, dirs.pop())
|
|
||||||
else: # No more parent dirs
|
|
||||||
break
|
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Get rules for a user file
|
# Get rules for a user file
|
||||||
|
|
Loading…
Reference in a new issue