Patrick Rathje commited on
Commit
ea8e878
·
1 Parent(s): 02884b9

add recursive list

Browse files
Files changed (2) hide show
  1. app.py +19 -0
  2. filesystem_access.py +18 -1
app.py CHANGED
@@ -137,6 +137,19 @@ def directory_tree(path):
137
  """
138
  return safe_exec(fs.directory_tree, path)
139
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
  with gr.Blocks() as demo:
141
 
142
  gr.Markdown("""
@@ -171,6 +184,12 @@ with gr.Blocks() as demo:
171
  btn = gr.Button("Show Tree")
172
  btn.click(fn=directory_tree, inputs=path, outputs=output)
173
 
 
 
 
 
 
 
174
  with gr.Tab("Search Files"):
175
  path = gr.Textbox(label="Search Directory", value=".")
176
  pattern = gr.Textbox(label="Pattern", value="*.html")
 
137
  """
138
  return safe_exec(fs.directory_tree, path)
139
 
140
+ def recursive_list(path):
141
+ """
142
+ Get a recursive list of the Motion Canvas documentation directory at the given path.
143
+
144
+ Args:
145
+ path (str): The documentation directory path to show as a recursive list.
146
+
147
+ Returns:
148
+ str: The documentation directory recursive list as a string, or error message if operation fails.
149
+ """
150
+ return safe_exec(fs.recursive_list, path)
151
+
152
+
153
  with gr.Blocks() as demo:
154
 
155
  gr.Markdown("""
 
184
  btn = gr.Button("Show Tree")
185
  btn.click(fn=directory_tree, inputs=path, outputs=output)
186
 
187
+ with gr.Tab("Recursive List"):
188
+ path = gr.Textbox(label="Directory Path", value=".")
189
+ output = gr.Textbox(label="Contents")
190
+ btn = gr.Button("Show Recursive List")
191
+ btn.click(fn=recursive_list, inputs=path, outputs=output)
192
+
193
  with gr.Tab("Search Files"):
194
  path = gr.Textbox(label="Search Directory", value=".")
195
  pattern = gr.Textbox(label="Pattern", value="*.html")
filesystem_access.py CHANGED
@@ -18,6 +18,7 @@ class FilesystemAccess:
18
  raise PermissionError("Access outside root path is not allowed.")
19
  return full_path
20
 
 
21
  def read_file(self, path: str) -> str:
22
  full_path = self._resolve_path(path)
23
  try:
@@ -87,4 +88,20 @@ class FilesystemAccess:
87
  tree.append(" " + line)
88
  else:
89
  tree.append(f"[F] {item.name}")
90
- return tree
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  raise PermissionError("Access outside root path is not allowed.")
19
  return full_path
20
 
21
+
22
  def read_file(self, path: str) -> str:
23
  full_path = self._resolve_path(path)
24
  try:
 
88
  tree.append(" " + line)
89
  else:
90
  tree.append(f"[F] {item.name}")
91
+ return tree
92
+
93
+ def recursive_list(self, path: str) -> str:
94
+ full_path = self._resolve_path(path)
95
+ return "\n".join(self._recursive_list(full_path))
96
+
97
+ def _recursive_list(self, path: Path) -> List[str]:
98
+ recursive_list = []
99
+ for item in path.iterdir():
100
+ if item.is_dir():
101
+ recursive_list.append(f"{item.name}/")
102
+ sublist = self._recursive_list(item.resolve())
103
+ for line in sublist:
104
+ recursive_list.append(f"{item.name}/" + line)
105
+ else:
106
+ recursive_list.append(f"{item.name}")
107
+ return recursive_list