flyshell 1.0.8__tar.gz → 1.0.10__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {flyshell-1.0.8/src/flyshell.egg-info → flyshell-1.0.10}/PKG-INFO +1 -1
- flyshell-1.0.10/src/flyshell/builtin/diskops.py +211 -0
- {flyshell-1.0.8 → flyshell-1.0.10}/src/flyshell/constants.py +2 -2
- {flyshell-1.0.8 → flyshell-1.0.10}/src/flyshell/core/directory.py +1 -0
- {flyshell-1.0.8 → flyshell-1.0.10}/src/flyshell/main.py +1 -1
- {flyshell-1.0.8 → flyshell-1.0.10/src/flyshell.egg-info}/PKG-INFO +1 -1
- flyshell-1.0.8/src/flyshell/builtin/diskops.py +0 -114
- {flyshell-1.0.8 → flyshell-1.0.10}/LICENSE +0 -0
- {flyshell-1.0.8 → flyshell-1.0.10}/README.md +0 -0
- {flyshell-1.0.8 → flyshell-1.0.10}/pyproject.toml +0 -0
- {flyshell-1.0.8 → flyshell-1.0.10}/setup.cfg +0 -0
- {flyshell-1.0.8 → flyshell-1.0.10}/src/flyshell/__init__.py +0 -0
- {flyshell-1.0.8 → flyshell-1.0.10}/src/flyshell/abstract/__init__.py +0 -0
- {flyshell-1.0.8 → flyshell-1.0.10}/src/flyshell/abstract/base_cmd.py +0 -0
- {flyshell-1.0.8 → flyshell-1.0.10}/src/flyshell/abstract/base_plugin.py +0 -0
- {flyshell-1.0.8 → flyshell-1.0.10}/src/flyshell/abstract/parent_cmd.py +0 -0
- {flyshell-1.0.8 → flyshell-1.0.10}/src/flyshell/builtin/__init__.py +0 -0
- {flyshell-1.0.8 → flyshell-1.0.10}/src/flyshell/builtin/fs.py +0 -0
- {flyshell-1.0.8 → flyshell-1.0.10}/src/flyshell/builtin/system.py +0 -0
- {flyshell-1.0.8 → flyshell-1.0.10}/src/flyshell/builtin/utils.py +0 -0
- {flyshell-1.0.8 → flyshell-1.0.10}/src/flyshell/core/__init__.py +0 -0
- {flyshell-1.0.8 → flyshell-1.0.10}/src/flyshell/core/auth.py +0 -0
- {flyshell-1.0.8 → flyshell-1.0.10}/src/flyshell/core/console.py +0 -0
- {flyshell-1.0.8 → flyshell-1.0.10}/src/flyshell/core/data.py +0 -0
- {flyshell-1.0.8 → flyshell-1.0.10}/src/flyshell/core/loader.py +0 -0
- {flyshell-1.0.8 → flyshell-1.0.10}/src/flyshell.egg-info/SOURCES.txt +0 -0
- {flyshell-1.0.8 → flyshell-1.0.10}/src/flyshell.egg-info/dependency_links.txt +0 -0
- {flyshell-1.0.8 → flyshell-1.0.10}/src/flyshell.egg-info/entry_points.txt +0 -0
- {flyshell-1.0.8 → flyshell-1.0.10}/src/flyshell.egg-info/requires.txt +0 -0
- {flyshell-1.0.8 → flyshell-1.0.10}/src/flyshell.egg-info/top_level.txt +0 -0
- {flyshell-1.0.8 → flyshell-1.0.10}/tests/test_auth.py +0 -0
- {flyshell-1.0.8 → flyshell-1.0.10}/tests/test_data.py +0 -0
- {flyshell-1.0.8 → flyshell-1.0.10}/tests/test_directory.py +0 -0
- {flyshell-1.0.8 → flyshell-1.0.10}/tests/test_loader.py +0 -0
- {flyshell-1.0.8 → flyshell-1.0.10}/tests/test_security.py +0 -0
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
# src\flyshell\builtin\diskops.py
|
|
2
|
+
|
|
3
|
+
from flyshell import constants as c
|
|
4
|
+
from flyshell.abstract.base_cmd import BaseCmd
|
|
5
|
+
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
import os
|
|
8
|
+
import shutil
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class Cat(BaseCmd):
|
|
12
|
+
name = "cat"
|
|
13
|
+
description = "Display the contents of a text file"
|
|
14
|
+
min_args = 1
|
|
15
|
+
options = "Target file"
|
|
16
|
+
aliases = ["read"]
|
|
17
|
+
|
|
18
|
+
def execute(self, args):
|
|
19
|
+
show_numbers = ("-n" in args) or ("--number" in args)
|
|
20
|
+
limit = None
|
|
21
|
+
filtered_args = []
|
|
22
|
+
skip_next = False
|
|
23
|
+
for i, token in enumerate(args):
|
|
24
|
+
if skip_next:
|
|
25
|
+
skip_next = False
|
|
26
|
+
continue
|
|
27
|
+
if token in ("-n", "--number"):
|
|
28
|
+
continue
|
|
29
|
+
if token in ("-l", "--limit"):
|
|
30
|
+
if i + 1 < len(args) and args[i + 1].isdigit():
|
|
31
|
+
limit = int(args[i + 1])
|
|
32
|
+
skip_next = True
|
|
33
|
+
continue
|
|
34
|
+
else:
|
|
35
|
+
return (1, f"\nCommand Error: '{token}' requires a positive integer limit.\n")
|
|
36
|
+
filtered_args.append(token)
|
|
37
|
+
if not filtered_args:
|
|
38
|
+
return (1, "\nCommand Error: Target file not specified.\n")
|
|
39
|
+
raw_target = " ".join(filtered_args).strip("\"'")
|
|
40
|
+
target_path = Path(raw_target).expanduser().resolve()
|
|
41
|
+
if not target_path.exists():
|
|
42
|
+
return (1, f"\nSystem Error: File '{raw_target}' not found.\n")
|
|
43
|
+
if target_path.is_dir():
|
|
44
|
+
return (1, f"\nSystem Error: '{raw_target}' is a directory, not a file.\n")
|
|
45
|
+
try:
|
|
46
|
+
with open(target_path, "r", encoding="utf-8", errors="replace") as f:
|
|
47
|
+
lines = f.readlines()
|
|
48
|
+
total_lines = len(lines)
|
|
49
|
+
if total_lines == 0:
|
|
50
|
+
return (1, f"\nSystem Error: '{raw_target}' is empty.\n")
|
|
51
|
+
if limit is not None:
|
|
52
|
+
lines = lines[:limit]
|
|
53
|
+
output_lines = [
|
|
54
|
+
f"\nDisplaying contents of file '{target_path.name}' ({len(lines)}/{total_lines} lines)\n"
|
|
55
|
+
]
|
|
56
|
+
for line_idx, line in enumerate(lines, start=1):
|
|
57
|
+
clean_line = line.rstrip("\r\n")
|
|
58
|
+
if show_numbers:
|
|
59
|
+
output_lines.append(f"{line_idx:4d} | {clean_line}")
|
|
60
|
+
else:
|
|
61
|
+
output_lines.append(clean_line)
|
|
62
|
+
output_lines.append(f"\nEnd of '{target_path.name}'\n")
|
|
63
|
+
return (0, "\n".join(output_lines))
|
|
64
|
+
except PermissionError:
|
|
65
|
+
return (1, f"\nSystem Error: Permission denied. Cannot read '{raw_target}'\n")
|
|
66
|
+
except Exception as e:
|
|
67
|
+
return (1, f"\nSystem Error: Failed to read file '{raw_target}' ({e})\n")
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
class Dir(BaseCmd):
|
|
71
|
+
name = "dir"
|
|
72
|
+
description = "List all files in the current working directory"
|
|
73
|
+
min_args = 0
|
|
74
|
+
options = None
|
|
75
|
+
aliases = ["ls"]
|
|
76
|
+
|
|
77
|
+
def execute(self, args):
|
|
78
|
+
try:
|
|
79
|
+
current_path = os.getcwd()
|
|
80
|
+
items = os.listdir(current_path)
|
|
81
|
+
lines = [f"\nDirectory: '{current_path}'"]
|
|
82
|
+
for item in items:
|
|
83
|
+
if os.path.isdir(os.path.join(current_path, item)):
|
|
84
|
+
lines.append(f"[DIR] {item}/")
|
|
85
|
+
else:
|
|
86
|
+
lines.append(f"[FILE] {item}")
|
|
87
|
+
lines.append(f"\nTotal items in directory: {len(items)}\n")
|
|
88
|
+
return (0, "\n".join(lines))
|
|
89
|
+
except Exception as e:
|
|
90
|
+
return (1, f"\nSystem Error: Unable to list directory ({e})\n")
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
class MkDir(BaseCmd):
|
|
94
|
+
name = "mkdir"
|
|
95
|
+
description = "Create a new directory from the current working directory"
|
|
96
|
+
min_args = 1
|
|
97
|
+
options = "Directory name"
|
|
98
|
+
aliases = ["md"]
|
|
99
|
+
|
|
100
|
+
def execute(self, args):
|
|
101
|
+
use_parents = ("-p" in args) or ("--parents" in args)
|
|
102
|
+
path_tokens = [arg for arg in args if arg not in ("-p", "--parents")]
|
|
103
|
+
target = " ".join(path_tokens).strip("\"'")
|
|
104
|
+
try:
|
|
105
|
+
if use_parents:
|
|
106
|
+
os.makedirs(target, exist_ok=True)
|
|
107
|
+
else:
|
|
108
|
+
os.mkdir(target)
|
|
109
|
+
return (0, f"\nSUCCESS! Created directory '{target}'\n")
|
|
110
|
+
except FileExistsError:
|
|
111
|
+
return (1, f"\nSystem Error: Directory '{target}' already exists.\n")
|
|
112
|
+
except FileNotFoundError:
|
|
113
|
+
return (
|
|
114
|
+
1,
|
|
115
|
+
"\nSystem Error: Parent directory does not exist. Use '-p' or '--parents' to create parent directories.\n",
|
|
116
|
+
)
|
|
117
|
+
except PermissionError:
|
|
118
|
+
return (1, f"\nSystem Error: Permission denied. Cannot create '{target}'\n")
|
|
119
|
+
except Exception as e:
|
|
120
|
+
return (1, f"\nSystem Error: Unable to create directory '{target}' ({e})\n")
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
class RmDir(BaseCmd):
|
|
124
|
+
name = "rmdir"
|
|
125
|
+
description = "Remove the specified directory"
|
|
126
|
+
min_args = 1
|
|
127
|
+
options = "Target directory"
|
|
128
|
+
aliases = []
|
|
129
|
+
|
|
130
|
+
def execute(self, args):
|
|
131
|
+
force = ("-f" in args) or ("--force" in args)
|
|
132
|
+
path_tokens = [arg for arg in args if arg not in ("-f", "--force")]
|
|
133
|
+
raw_target = " ".join(path_tokens).strip("\"'")
|
|
134
|
+
target_path = Path(raw_target).expanduser().resolve()
|
|
135
|
+
if target_path == target_path.parent or str(target_path) == target_path.anchor:
|
|
136
|
+
return (
|
|
137
|
+
1,
|
|
138
|
+
"\nSecurity Error: Flyshell has blocked this action.\n"
|
|
139
|
+
"You cannot delete the root filesystem directory.\n",
|
|
140
|
+
)
|
|
141
|
+
critical_system_dirs = [
|
|
142
|
+
Path.home().parent.resolve(),
|
|
143
|
+
Path.home().resolve(),
|
|
144
|
+
]
|
|
145
|
+
if c.HOST_OS == "Windows":
|
|
146
|
+
system_drive = os.environ.get("SystemDrive", "C:")
|
|
147
|
+
critical_system_dirs.extend([
|
|
148
|
+
Path(f"{system_drive}\\Windows").resolve(),
|
|
149
|
+
Path(f"{system_drive}\\Program Files").resolve(),
|
|
150
|
+
Path(f"{system_drive}\\Program Files (x86)").resolve(),
|
|
151
|
+
])
|
|
152
|
+
else:
|
|
153
|
+
critical_system_dirs.extend([
|
|
154
|
+
Path("/bin").resolve(),
|
|
155
|
+
Path("/etc").resolve(),
|
|
156
|
+
Path("/usr").resolve(),
|
|
157
|
+
Path("/var").resolve(),
|
|
158
|
+
])
|
|
159
|
+
if target_path in critical_system_dirs:
|
|
160
|
+
return (
|
|
161
|
+
1,
|
|
162
|
+
"\nSecurity Error: Flyshell has blocked this action.\n"
|
|
163
|
+
f"Target '{raw_target}' is a protected operating system directory.\n",
|
|
164
|
+
)
|
|
165
|
+
if target_path == Path(os.getcwd()).resolve():
|
|
166
|
+
return (
|
|
167
|
+
1,
|
|
168
|
+
"\nSystem Error: Cannot remove current working directory.\n"
|
|
169
|
+
"Switch to a different directory using 'cd' first.\n",
|
|
170
|
+
)
|
|
171
|
+
flyshell_dirs = [
|
|
172
|
+
c.APP_DIR.resolve(),
|
|
173
|
+
c.PACKAGE_ROOT.resolve(),
|
|
174
|
+
c.PROJECT_ROOT.resolve(),
|
|
175
|
+
]
|
|
176
|
+
for protected in flyshell_dirs:
|
|
177
|
+
if target_path == protected or target_path.is_relative_to(protected):
|
|
178
|
+
return (
|
|
179
|
+
1,
|
|
180
|
+
"\nSecurity Error: Flyshell has blocked this action.\n"
|
|
181
|
+
f"Target '{raw_target}' contains or belongs to Flyshell system files.\n"
|
|
182
|
+
"If you wish to delete Flyshell, use the host.\n",
|
|
183
|
+
)
|
|
184
|
+
try:
|
|
185
|
+
has_contents = any(target_path.iterdir())
|
|
186
|
+
if has_contents and not force:
|
|
187
|
+
return (
|
|
188
|
+
1,
|
|
189
|
+
f"\nDirectory Error: Directory '{raw_target}' is not empty.\n"
|
|
190
|
+
"Use '-f' or '--force' to remove a non-empty directory and its contents.\n",
|
|
191
|
+
)
|
|
192
|
+
if has_contents and force:
|
|
193
|
+
shutil.rmtree(target_path)
|
|
194
|
+
else:
|
|
195
|
+
os.rmdir(target_path)
|
|
196
|
+
return (0, f"\nSUCCESS! Removed directory '{raw_target}'\n")
|
|
197
|
+
except PermissionError:
|
|
198
|
+
return (
|
|
199
|
+
1,
|
|
200
|
+
f"\nSystem Error: Permission denied. Cannot delete '{raw_target}'\n",
|
|
201
|
+
)
|
|
202
|
+
except OSError as e:
|
|
203
|
+
return (
|
|
204
|
+
1,
|
|
205
|
+
f"\nSystem Error: Unable to remove directory '{raw_target}' ({e.strerror})\n",
|
|
206
|
+
)
|
|
207
|
+
except Exception as e:
|
|
208
|
+
return (
|
|
209
|
+
1,
|
|
210
|
+
f"\nSystem Error: Unexpected error removing '{raw_target}' ({e})\n",
|
|
211
|
+
)
|
|
@@ -83,7 +83,7 @@ def main():
|
|
|
83
83
|
sys.exit(0)
|
|
84
84
|
else:
|
|
85
85
|
print(
|
|
86
|
-
f"\nCRITICAL ERROR: Host operating system '{
|
|
86
|
+
f"\nCRITICAL ERROR: Host operating system '{c.HOST_OS}' is not supported."
|
|
87
87
|
)
|
|
88
88
|
print(
|
|
89
89
|
"Flyshell cannot launch because your operating system is not supported."
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
# src\flyshell\builtin\diskops.py
|
|
2
|
-
|
|
3
|
-
from flyshell import constants as c
|
|
4
|
-
from flyshell.abstract.base_cmd import BaseCmd
|
|
5
|
-
|
|
6
|
-
from pathlib import Path
|
|
7
|
-
import os
|
|
8
|
-
import shutil
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class Dir(BaseCmd):
|
|
12
|
-
name = "dir"
|
|
13
|
-
description = "List all files in the current working directory"
|
|
14
|
-
min_args = 0
|
|
15
|
-
options = None
|
|
16
|
-
aliases = ["ls"]
|
|
17
|
-
|
|
18
|
-
def execute(self, args):
|
|
19
|
-
try:
|
|
20
|
-
current_path = os.getcwd()
|
|
21
|
-
items = os.listdir(current_path)
|
|
22
|
-
lines = [f"\nDirectory: '{current_path}'"]
|
|
23
|
-
for item in items:
|
|
24
|
-
if os.path.isdir(os.path.join(current_path, item)):
|
|
25
|
-
lines.append(f"[DIR] {item}/")
|
|
26
|
-
else:
|
|
27
|
-
lines.append(f"[FILE] {item}")
|
|
28
|
-
lines.append(f"\nTotal items in directory: {len(items)}\n")
|
|
29
|
-
return (0, "\n".join(lines))
|
|
30
|
-
except Exception as e:
|
|
31
|
-
return (1, f"\nSystem Error: Unable to list directory ({e})\n")
|
|
32
|
-
|
|
33
|
-
class MkDir(BaseCmd):
|
|
34
|
-
name = "mkdir"
|
|
35
|
-
description = "Create a new directory from the current working directory"
|
|
36
|
-
min_args = 1
|
|
37
|
-
options = "Directory name"
|
|
38
|
-
aliases = ["md"]
|
|
39
|
-
|
|
40
|
-
def execute(self, args):
|
|
41
|
-
use_parents = ("-p" in args) or ("--parents" in args)
|
|
42
|
-
path_tokens = [arg for arg in args if arg not in ("-p", "--parents")]
|
|
43
|
-
target = " ".join(path_tokens).strip("\"'")
|
|
44
|
-
try:
|
|
45
|
-
if use_parents:
|
|
46
|
-
os.makedirs(target, exist_ok=True)
|
|
47
|
-
else:
|
|
48
|
-
os.mkdir(target)
|
|
49
|
-
return (0, f"\nSUCCESS! Created directory '{target}'\n")
|
|
50
|
-
except FileExistsError:
|
|
51
|
-
return (1, f"\nSystem Error: Directory '{target}' already exists.\n")
|
|
52
|
-
except FileNotFoundError:
|
|
53
|
-
return (1, f"\nSystem Error: Parent directory does not exist. Use '-p' or '--parents' to create parent directories.\n")
|
|
54
|
-
except PermissionError:
|
|
55
|
-
return (1, f"\nSystem Error: Permission denied. Cannot create '{target}'\n")
|
|
56
|
-
except Exception as e:
|
|
57
|
-
return (1, f"\nSystem Error: Unable to create directory '{target}' ({e})\n")
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
class RmDir(BaseCmd):
|
|
61
|
-
name = "rmdir"
|
|
62
|
-
description = "Remove the specified directory"
|
|
63
|
-
min_args = 1
|
|
64
|
-
options = "Target directory"
|
|
65
|
-
aliases = []
|
|
66
|
-
|
|
67
|
-
def execute(self, args):
|
|
68
|
-
force = ("-f" in args) or ("--force" in args)
|
|
69
|
-
path_tokens = [arg for arg in args if arg not in ("-f", "--force")]
|
|
70
|
-
raw_target = " ".join(path_tokens).strip("\"'")
|
|
71
|
-
target_path = Path(raw_target).expanduser().resolve()
|
|
72
|
-
if not target_path.exists():
|
|
73
|
-
return (1, f"\nSystem Error: Directory '{raw_target}' not found.\n")
|
|
74
|
-
if not target_path.is_dir():
|
|
75
|
-
return (1, f"\nCommand Error: '{raw_target}' is a file, not a directory.\n")
|
|
76
|
-
if target_path == target_path.anchor or target_path.parent == target_path:
|
|
77
|
-
return (
|
|
78
|
-
1,
|
|
79
|
-
"\nSecurity Error: Flyshell has blocked this action.\n"
|
|
80
|
-
"You cannot delete the root filesystem directory.\n",
|
|
81
|
-
)
|
|
82
|
-
flyshell_app = c.APP_DIR.resolve()
|
|
83
|
-
flyshell_package = c.PACKAGE_ROOT.resolve()
|
|
84
|
-
if target_path in (flyshell_app, flyshell_package) or flyshell_app in target_path.parents or flyshell_package in target_path.parents:
|
|
85
|
-
return (
|
|
86
|
-
1,
|
|
87
|
-
"\nSecurity Error: Flyshell has blocked this action.\n"
|
|
88
|
-
f"You cannot delete '{raw_target}' because it contains core Flyshell files or data.\n",
|
|
89
|
-
)
|
|
90
|
-
if target_path == Path(os.getcwd()).resolve():
|
|
91
|
-
return (
|
|
92
|
-
1,
|
|
93
|
-
"\nSystem Error: Cannot remove current working directory.\n"
|
|
94
|
-
"Switch to a different directory using 'cd' first.\n",
|
|
95
|
-
)
|
|
96
|
-
try:
|
|
97
|
-
has_contents = any(target_path.iterdir())
|
|
98
|
-
if has_contents and not force:
|
|
99
|
-
return (
|
|
100
|
-
1,
|
|
101
|
-
f"\nDirectory Error: Directory '{raw_target}' is not empty.\n"
|
|
102
|
-
"Use '-f' or '--force' to remove a non-empty directory and its contents.\n",
|
|
103
|
-
)
|
|
104
|
-
if has_contents and force:
|
|
105
|
-
shutil.rmtree(target_path)
|
|
106
|
-
else:
|
|
107
|
-
os.rmdir(target_path)
|
|
108
|
-
return (0, f"\nSUCCESS! Removed directory '{raw_target}'\n")
|
|
109
|
-
except PermissionError:
|
|
110
|
-
return (1, f"\nSystem Error: Permission denied. Cannot delete '{raw_target}'\n")
|
|
111
|
-
except OSError as e:
|
|
112
|
-
return (1, f"\nSystem Error: Unable to remove directory '{raw_target}' ({e.strerror})\n")
|
|
113
|
-
except Exception as e:
|
|
114
|
-
return (1, f"\nSystem Error: Unexpected error removing '{raw_target}' ({e})\n")
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|