Naming things....

This commit is contained in:
René Pfeuffer
2018-10-11 16:32:06 +02:00
parent b4c854ee99
commit 7845443d62

View File

@@ -47,6 +47,11 @@ class File_Collector:
self.recursive = recursive self.recursive = recursive
self.structure = defaultdict(dict, ((FILE_MARKER, []),)) self.structure = defaultdict(dict, ((FILE_MARKER, []),))
def collect(self, paths, path = "", dir_only = False):
for p in paths:
if p.startswith(path):
self.attach(self.extract_name_without_parent(path, p), self.structure, dir_only)
def attach(self, branch, trunk, dir_only = False): def attach(self, branch, trunk, dir_only = False):
parts = branch.split('/', 1) parts = branch.split('/', 1)
if len(parts) == 1: # branch is a file if len(parts) == 1: # branch is a file
@@ -61,18 +66,13 @@ class File_Collector:
if self.recursive: if self.recursive:
self.attach(others, trunk[node], dir_only) self.attach(others, trunk[node], dir_only)
def create_path(self, parent, path): def extract_name_without_parent(self, parent, name_with_parent):
if len(parent) > 0: if len(parent) > 0:
newPath = path[len(parent):] name_without_parent = name_with_parent[len(parent):]
if newPath.startswith("/"): if name_without_parent.startswith("/"):
newPath = newPath[1:] name_without_parent = name_without_parent[1:]
return newPath return name_without_parent
return path return name_with_parent
def collect(self, paths, path = "", dir_only = False):
for p in paths:
if p.startswith(path):
self.attach(self.create_path(path, p), self.structure, dir_only)
class File_Object: class File_Object:
def __init__(self, directory, path): def __init__(self, directory, path):