forked from AnshMNSoni/squirix
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinux_commands.py
More file actions
186 lines (161 loc) · 7.99 KB
/
Copy pathlinux_commands.py
File metadata and controls
186 lines (161 loc) · 7.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# Basic Linux Commands
from rich.console import Console
from rich.prompt import Prompt
import os, psutil, shutil, math, threading, socket, requests
from sympy import symbols, sympify, diff, integrate, pretty
console = Console()
lock = threading.Lock()
class Commands:
# Commands
def list_files(self, ):
console.print("\nFiles and Directories:", style="bold cyan")
for item in os.listdir():
console.print(f" - {item}")
def create_file(self, filename):
with open(filename, 'w') as f:
content = Prompt.ask("Enter content")
f.write(content)
console.print(f"File '{filename}' created.", style="bold green")
def delete_file(self, filename):
if os.path.exists(filename):
os.remove(filename)
console.print(f"File '{filename}' deleted.", style="bold red")
else:
console.print("File not found.", style="bold yellow")
def system_info(self, ):
console.print("\n[bold blue]System Info:[/bold blue]")
console.print(f" CPU Usage: {psutil.cpu_percent()}%")
console.print(f" RAM Usage: {psutil.virtual_memory().percent}%")
def network_info(self, *args):
try:
local_ip = socket.gethostbyname(socket.gethostname())
external_ip = requests.get("https://api64.ipify.org").text
console.print(f"Local IP: {local_ip}")
console.print(f"External IP: {external_ip}")
except Exception as e:
console.print(f"Network Error: {e}", style="bold red")
def create_folder(self, folder_name):
os.makedirs(folder_name, exist_ok=True)
console.print(f"Folder '{folder_name}' created.", style="bold green")
def delete_folder(self, folder_name):
if os.path.exists(folder_name):
os.rmdir(folder_name)
console.print(f"Folder '{folder_name}' deleted.", style="bold red")
else:
console.print("Folder not found or not empty.", style="bold yellow")
def change_directory(self, path):
try:
os.chdir(path)
console.print(f"Changed directory to {os.getcwd()}", style="bold green")
except Exception as e:
console.print(str(e), style="bold red")
def text_editor(self, filename):
if not os.path.exists(filename):
console.print("File not found. Creating a new file.", style="bold yellow")
with open(filename, 'a+') as f:
console.print("Enter text (type 'exit' to save and exit):", style="bold cyan")
while True:
line = input()
if line.lower() == 'exit':
break
f.write(line + '\n')
console.print(f"File '{filename}' saved.", style="bold green")
def rename_item(self, args):
if len(args) < 2:
console.print("Usage: rename <old_name> <new_name>", style="bold red")
return
old_name, new_name = args
with lock:
try:
os.rename(old_name, new_name)
console.print(f"'{old_name}' renamed to '{new_name}'", style="bold green")
except FileNotFoundError:
console.print("Item not found.", style="bold red")
def move_file(self, args):
if len(args) < 2:
console.print("Usage: move <source> <destination>", style="bold red")
return
src, dest = args
with lock:
try:
shutil.move(src, dest)
console.print(f"Moved '{src}' to '{dest}'", style="bold green")
except Exception as e:
console.print(str(e), style="bold red")
def copy_file(args):
if len(args) < 2:
console.print("Usage: copy <source> <destination>", style="bold red")
return
src, dest = args
with lock:
try:
shutil.copy(src, dest)
console.print(f"Copied '{src}' to '{dest}'", style="bold green")
except Exception as e:
console.print(str(e), style="bold red")
# Built-in Calculator
def math_help(self, *args):
"""Displays available mathematical functions and their usage."""
help_text = """
Available Mathematical Functions:
- abs(x) : Returns the absolute value of x
- ceil(x) : Returns the ceiling of x (smallest integer >= x)
- floor(x) : Returns the floor of x (largest integer <= x)
- trunc(x) : Truncates x (removes the decimal part)
- exp(x) : Returns e^x (exponential function)
- log(x) : Returns the natural logarithm of x (base e)
- log(x, base) : Returns the logarithm of x with specified base
- log10(x) : Returns the base-10 logarithm of x
- log2(x) : Returns the base-2 logarithm of x
- sqrt(x) : Returns the square root of x
- pow(x, y) : Returns x raised to the power y (x^y)
- sin(x) : Returns the sine of x (x in radians)
- cos(x) : Returns the cosine of x (x in radians)
- tan(x) : Returns the tangent of x (x in radians)
- asin(x) : Returns the inverse sine of x (result in radians)
- acos(x) : Returns the inverse cosine of x (result in radians)
- atan(x) : Returns the inverse tangent of x (result in radians)
- sinh(x) : Returns the hyperbolic sine of x
- cosh(x) : Returns the hyperbolic cosine of x
- tanh(x) : Returns the hyperbolic tangent of x
- degrees(x) : Converts radians to degrees
- radians(x) : Converts degrees to radians
- gcd(x, y) : Returns the greatest common divisor of x and y
- lcm(x, y) : Returns the least common multiple of x and y (Python 3.9+)
- factorial(x) : Returns x! (factorial of x)
- isfinite(x) : Returns True if x is neither infinity nor NaN
- isinf(x) : Returns True if x is infinity
- isnan(x) : Returns True if x is NaN (Not a Number)
- copysign(x, y) : Returns x with the sign of y
- fmod(x, y) : Returns remainder of x / y
Example Usage:
- calc sin(3.14) # Returns sine of 3.14 radians
- calc log(10) # Returns natural log of 10
- calc sqrt(25) # Returns 5.0
- calc pow(2, 3) # Returns 2^3 = 8
- calc degrees(3.14) # Converts 3.14 radians to degrees
- calc gcd(54, 24) # Returns GCD of 54 and 24
"""
console.print(help_text, style="bold cyan")
def calculator(self, args):
if not args:
console.print("Usage:\n- calc <expression>\n- calc diff <expression> <variable>\n- calc integrate <expression> <variable>", style="bold red")
return
try:
command = args[0]
if command == "diff" and len(args) >= 3:
expression = " ".join(args[1:-1])
var = symbols(args[-1])
result = diff(sympify(expression), var)
console.print(f"Derivative of [bold yellow]{pretty(expression)}[/bold yellow] w.r.t [cyan]{var}[/cyan]:\n{pretty(result)}", style="bold green")
elif command == "integrate" and len(args) >= 3:
expression = " ".join(args[1:-1])
var = symbols(args[-1])
result = integrate(sympify(expression), var)
console.print(f"Integral of [bold yellow]{pretty(expression)}[/bold yellow] w.r.t [cyan]{var}[/cyan]:\n{pretty(result)}", style="bold green")
else:
expression = " ".join(args)
result = eval(expression, {"__builtins__": None}, math.__dict__)
console.print(f"Result: {result}", style="bold green")
except Exception as e:
console.print(f"Error: {e}", style="bold red")