MCPcopy Create free account
hub / github.com/Kitware/VTK / listServerDirectory

Method listServerDirectory

Web/Python/vtkmodules/web/protocols.py:681–734  ·  view source on GitHub ↗

RPC Callback to list a server directory relative to the basePath provided at start-up.

(self, relativeDir=".")

Source from the content-addressed store, hash-verified

679
680 @exportRpc("file.server.directory.list")
681 def listServerDirectory(self, relativeDir="."):
682 """
683 RPC Callback to list a server directory relative to the basePath
684 provided at start-up.
685 """
686 path = [self.rootName]
687 if len(relativeDir) > len(self.rootName):
688 relativeDir = relativeDir[len(self.rootName) + 1 :]
689 path += relativeDir.replace("\\", "/").split("/")
690
691 currentPath = os.path.join(self.baseDirectory, relativeDir)
692 result = {
693 "label": relativeDir,
694 "files": [],
695 "dirs": [],
696 "groups": [],
697 "path": path,
698 }
699 if relativeDir == ".":
700 result["label"] = self.rootName
701 for file in os.listdir(currentPath):
702 if os.path.isfile(os.path.join(currentPath, file)) and not re.search(
703 self.pattern, file
704 ):
705 result["files"].append({"label": file, "size": -1})
706 elif os.path.isdir(os.path.join(currentPath, file)) and not re.search(
707 self.pattern, file
708 ):
709 result["dirs"].append(file)
710
711 # Filter files to create groups
712 files = result["files"]
713 files.sort()
714 groups = result["groups"]
715 groupIdx = {}
716 filesToRemove = []
717 for file in files:
718 fileSplit = re.split(self.gPattern, file["label"])
719 if len(fileSplit) == 2:
720 filesToRemove.append(file)
721 gName = "*.".join(fileSplit)
722 if gName in groupIdx:
723 groupIdx[gName]["files"].append(file["label"])
724 else:
725 groupIdx[gName] = {"files": [file["label"]], "label": gName}
726 groups.append(groupIdx[gName])
727 for file in filesToRemove:
728 gName = "*.".join(re.split(self.gPattern, file["label"]))
729 if len(groupIdx[gName]["files"]) > 1:
730 files.remove(file)
731 else:
732 groups.remove(groupIdx[gName])
733
734 return result
735
736
737# =============================================================================

Callers

nothing calls this directly

Calls 5

searchMethod · 0.80
joinMethod · 0.45
appendMethod · 0.45
sortMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected