Merge branch 'main' into motion_canvas
Browse files
app.py
CHANGED
|
@@ -22,9 +22,27 @@ def safe_exec(func, *args, **kwargs):
|
|
| 22 |
return f"Error"
|
| 23 |
|
| 24 |
def read_file(path):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
return safe_exec(fs.read_file, path)
|
| 26 |
|
| 27 |
def read_multiple_files(paths):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
path_list = [p.strip() for p in paths.split(',') if p.strip()]
|
| 29 |
|
| 30 |
file_contents = []
|
|
@@ -43,22 +61,80 @@ def read_multiple_files(paths):
|
|
| 43 |
return f"Error"
|
| 44 |
|
| 45 |
def write_file(path, content):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
return safe_exec(fs.write_file, path, content) or "File written successfully."
|
| 47 |
|
| 48 |
def create_directory(path):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
return safe_exec(fs.create_directory, path) or "Directory ensured."
|
| 50 |
|
| 51 |
def list_directory(path):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
return '\n'.join(safe_exec(fs.list_directory, path))
|
| 53 |
|
| 54 |
def move_file(source, destination):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
return safe_exec(fs.move_file, source, destination) or "Move successful."
|
| 56 |
|
| 57 |
def search_files(path, pattern, exclude):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
exclude_list = [e.strip() for e in exclude.split(',') if e.strip()]
|
| 59 |
return '\n'.join(safe_exec(fs.search_files, path, pattern, exclude_list))
|
| 60 |
|
| 61 |
def directory_tree(path):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
return safe_exec(fs.directory_tree, path)
|
| 63 |
|
| 64 |
with gr.Blocks() as demo:
|
|
|
|
| 22 |
return f"Error"
|
| 23 |
|
| 24 |
def read_file(path):
|
| 25 |
+
"""
|
| 26 |
+
Read the contents of a file at the given path.
|
| 27 |
+
|
| 28 |
+
Args:
|
| 29 |
+
path (str): The path to the file to read.
|
| 30 |
+
|
| 31 |
+
Returns:
|
| 32 |
+
str: The contents of the file, or an error message if not found.
|
| 33 |
+
"""
|
| 34 |
return safe_exec(fs.read_file, path)
|
| 35 |
|
| 36 |
def read_multiple_files(paths):
|
| 37 |
+
"""
|
| 38 |
+
Read the contents of multiple files specified by a comma-separated list of paths.
|
| 39 |
+
|
| 40 |
+
Args:
|
| 41 |
+
paths (str): Comma-separated file paths to read.
|
| 42 |
+
|
| 43 |
+
Returns:
|
| 44 |
+
str: The concatenated contents of all files, or error messages for files that could not be read.
|
| 45 |
+
"""
|
| 46 |
path_list = [p.strip() for p in paths.split(',') if p.strip()]
|
| 47 |
|
| 48 |
file_contents = []
|
|
|
|
| 61 |
return f"Error"
|
| 62 |
|
| 63 |
def write_file(path, content):
|
| 64 |
+
"""
|
| 65 |
+
Write content to a file at the given path.
|
| 66 |
+
|
| 67 |
+
Args:
|
| 68 |
+
path (str): The path to the file to write.
|
| 69 |
+
content (str): The content to write to the file.
|
| 70 |
+
|
| 71 |
+
Returns:
|
| 72 |
+
str: Success message or error message if the write fails.
|
| 73 |
+
"""
|
| 74 |
return safe_exec(fs.write_file, path, content) or "File written successfully."
|
| 75 |
|
| 76 |
def create_directory(path):
|
| 77 |
+
"""
|
| 78 |
+
Create a directory at the given path, including any necessary parent directories.
|
| 79 |
+
|
| 80 |
+
Args:
|
| 81 |
+
path (str): The directory path to create.
|
| 82 |
+
|
| 83 |
+
Returns:
|
| 84 |
+
str: Success message or error message if creation fails.
|
| 85 |
+
"""
|
| 86 |
return safe_exec(fs.create_directory, path) or "Directory ensured."
|
| 87 |
|
| 88 |
def list_directory(path):
|
| 89 |
+
"""
|
| 90 |
+
List the contents of a directory at the given path.
|
| 91 |
+
|
| 92 |
+
Args:
|
| 93 |
+
path (str): The directory path to list.
|
| 94 |
+
|
| 95 |
+
Returns:
|
| 96 |
+
str: Newline-separated list of directory contents, or error message if listing fails.
|
| 97 |
+
"""
|
| 98 |
return '\n'.join(safe_exec(fs.list_directory, path))
|
| 99 |
|
| 100 |
def move_file(source, destination):
|
| 101 |
+
"""
|
| 102 |
+
Move a file from source to destination path.
|
| 103 |
+
|
| 104 |
+
Args:
|
| 105 |
+
source (str): The source file path.
|
| 106 |
+
destination (str): The destination file path.
|
| 107 |
+
|
| 108 |
+
Returns:
|
| 109 |
+
str: Success message or error message if move fails.
|
| 110 |
+
"""
|
| 111 |
return safe_exec(fs.move_file, source, destination) or "Move successful."
|
| 112 |
|
| 113 |
def search_files(path, pattern, exclude):
|
| 114 |
+
"""
|
| 115 |
+
Search for files in a directory matching a pattern, excluding specified patterns.
|
| 116 |
+
|
| 117 |
+
Args:
|
| 118 |
+
path (str): The directory path to search in.
|
| 119 |
+
pattern (str): The glob pattern to match files.
|
| 120 |
+
exclude (str): Comma-separated patterns to exclude from results.
|
| 121 |
+
|
| 122 |
+
Returns:
|
| 123 |
+
str: Newline-separated list of matching file paths, or error message if search fails.
|
| 124 |
+
"""
|
| 125 |
exclude_list = [e.strip() for e in exclude.split(',') if e.strip()]
|
| 126 |
return '\n'.join(safe_exec(fs.search_files, path, pattern, exclude_list))
|
| 127 |
|
| 128 |
def directory_tree(path):
|
| 129 |
+
"""
|
| 130 |
+
Get a tree representation of the directory at the given path.
|
| 131 |
+
|
| 132 |
+
Args:
|
| 133 |
+
path (str): The directory path to show as a tree.
|
| 134 |
+
|
| 135 |
+
Returns:
|
| 136 |
+
str: The directory tree as a string, or error message if operation fails.
|
| 137 |
+
"""
|
| 138 |
return safe_exec(fs.directory_tree, path)
|
| 139 |
|
| 140 |
with gr.Blocks() as demo:
|