qimomo-py-linux 0.1.0__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.
- qimomo_py_linux-0.1.0/LICENSE +9 -0
- qimomo_py_linux-0.1.0/PKG-INFO +23 -0
- qimomo_py_linux-0.1.0/README.md +3 -0
- qimomo_py_linux-0.1.0/pylinux/__init__.py +1 -0
- qimomo_py_linux-0.1.0/pylinux/pylinux.py +449 -0
- qimomo_py_linux-0.1.0/pyproject.toml +20 -0
- qimomo_py_linux-0.1.0/qimomo_py_linux.egg-info/PKG-INFO +23 -0
- qimomo_py_linux-0.1.0/qimomo_py_linux.egg-info/SOURCES.txt +10 -0
- qimomo_py_linux-0.1.0/qimomo_py_linux.egg-info/dependency_links.txt +1 -0
- qimomo_py_linux-0.1.0/qimomo_py_linux.egg-info/requires.txt +2 -0
- qimomo_py_linux-0.1.0/qimomo_py_linux.egg-info/top_level.txt +1 -0
- qimomo_py_linux-0.1.0/setup.cfg +4 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
Copyright 2025 七魔陌
|
|
2
|
+
|
|
3
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
4
|
+
|
|
5
|
+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
6
|
+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
7
|
+
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
8
|
+
|
|
9
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: qimomo-py-linux
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: pylinux python中简单运行linux命令
|
|
5
|
+
Author-email: Your Name <qimomo.17@qq.com>
|
|
6
|
+
License: Copyright 2025 七魔陌
|
|
7
|
+
|
|
8
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
9
|
+
|
|
10
|
+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
11
|
+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
12
|
+
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
13
|
+
|
|
14
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
Requires-Dist: requests>=2.25.1
|
|
18
|
+
Requires-Dist: tqdm
|
|
19
|
+
Dynamic: license-file
|
|
20
|
+
|
|
21
|
+
## Author
|
|
22
|
+
**七魔陌**
|
|
23
|
+
- Email: qimomo.17@qq.com
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .core import linux
|
|
@@ -0,0 +1,449 @@
|
|
|
1
|
+
"""
|
|
2
|
+
=====简介=====
|
|
3
|
+
模块名称:pylinux
|
|
4
|
+
作者:qimomo
|
|
5
|
+
实现python中运行简单命令
|
|
6
|
+
"""
|
|
7
|
+
__help__ ="""
|
|
8
|
+
模块名称:pylinux
|
|
9
|
+
作者:qimomo
|
|
10
|
+
pylinux:help
|
|
11
|
+
class linux:
|
|
12
|
+
run() : 执行命令
|
|
13
|
+
命令:
|
|
14
|
+
return ~~~ : 将命令 ~~~ 返回输出
|
|
15
|
+
linux-system ~~~ : 向系统发送 ~~~
|
|
16
|
+
clear_screen : 用于清屏
|
|
17
|
+
calculate_folder_depth : 用于查看文件夹最深深度(几个文件夹)
|
|
18
|
+
get_folder_size_getsize : 获取文件,文件夹大小
|
|
19
|
+
download_file : 用于下载文件
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
print("pylinux:正在导入模块... \n Importing module...")
|
|
24
|
+
import time
|
|
25
|
+
import os
|
|
26
|
+
import shutil
|
|
27
|
+
import subprocess
|
|
28
|
+
import sys
|
|
29
|
+
import time
|
|
30
|
+
import requests
|
|
31
|
+
from tqdm import tqdm
|
|
32
|
+
from getpass import getpass#password = getpass("请输入密码") 输入时不会显示内容
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
print("pylinux:模块导入:ok \n Importing module:ok\npylinux:正在准备函数... \n Preparing the function...")
|
|
36
|
+
linux_file_path = None
|
|
37
|
+
def calculate_folder_depth(path):#深度
|
|
38
|
+
if not os.path.isdir(path):
|
|
39
|
+
return 0
|
|
40
|
+
max_depth = 0
|
|
41
|
+
for root, dirs, files in os.walk(path):
|
|
42
|
+
current_depth = len(root.split(os.sep)) - len(path.split(os.sep)) - 1 # 减去1因为path本身不计入深度
|
|
43
|
+
max_depth = max(max_depth, current_depth)
|
|
44
|
+
return max_depth + 1 if max_depth > 0 else 0
|
|
45
|
+
|
|
46
|
+
def get_folder_size_getsize(file_path):#大小
|
|
47
|
+
total_size = 0
|
|
48
|
+
if os.path.isdir(file_path):
|
|
49
|
+
for dirpath, dirnames, filenames in os.walk(file_path):
|
|
50
|
+
for filename in filenames:
|
|
51
|
+
file_path = os.path.join(dirpath, filename)
|
|
52
|
+
if os.path.isfile(file_path):
|
|
53
|
+
total_size += os.path.getsize(file_path)
|
|
54
|
+
else:
|
|
55
|
+
total_size=os.path.getsize(file_path)
|
|
56
|
+
return total_size
|
|
57
|
+
|
|
58
|
+
def download_file(url, filename=None):
|
|
59
|
+
if not filename:
|
|
60
|
+
filename = url.split('/')[-1]
|
|
61
|
+
response = requests.get(url, stream=True)
|
|
62
|
+
response.raise_for_status()
|
|
63
|
+
total_size = int(response.headers.get('content-length', 0))
|
|
64
|
+
with open(filename, 'wb') as f, tqdm(
|
|
65
|
+
desc=filename,
|
|
66
|
+
total=total_size,
|
|
67
|
+
unit='iB',
|
|
68
|
+
unit_scale=True,
|
|
69
|
+
unit_divisor=1024,
|
|
70
|
+
) as bar:
|
|
71
|
+
for chunk in response.iter_content(chunk_size=8192):
|
|
72
|
+
size = f.write(chunk)
|
|
73
|
+
bar.update(size)
|
|
74
|
+
print(f"\nDownload completed: {filename}")
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
# 检查是否授予存储权限(仅限部分设备)
|
|
78
|
+
def check():
|
|
79
|
+
result = os.popen("pm list permissions").read()
|
|
80
|
+
if "android.permission.WRITE_EXTERNAL_STORAGE" in result:
|
|
81
|
+
print("已授予存储权限")
|
|
82
|
+
if "MANAGE_EXTERNAL_STORAGE" in result:
|
|
83
|
+
print("已授予MANAGE_EXTERNAL_STORAGE权限")
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def clear_screen():
|
|
87
|
+
# 对于 Windows 系统
|
|
88
|
+
if os.name == 'nt':
|
|
89
|
+
os.system('cls')
|
|
90
|
+
# 对于 Linux 和 macOS 系统
|
|
91
|
+
else:
|
|
92
|
+
os.system('clear')
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
class linux():
|
|
99
|
+
def __init__(Linux):
|
|
100
|
+
|
|
101
|
+
print("pylinux:正在初始化... \n Initializing...")
|
|
102
|
+
#Linux.time=time;Linux.os=os;Linux.shutil=shutil;Linux.subprocess=subprocess;Linux.sys=sys
|
|
103
|
+
Linux.access = os.getcwd() # "#/*/" #默认权限
|
|
104
|
+
Linux.user = "" #默认用户
|
|
105
|
+
Linux.default_access = os.getcwd() #Default 默认
|
|
106
|
+
Linux.login_tf = False
|
|
107
|
+
Linux.工作路径=os.getcwd()
|
|
108
|
+
Linux.history_temp="";Linux.str_input=""
|
|
109
|
+
print("pylinux:正在读取history.txt文件... \n Reading the history.txt file...")
|
|
110
|
+
try:
|
|
111
|
+
with open("history.txt") as open_history:
|
|
112
|
+
Linux.history_temp+=open_history.read()
|
|
113
|
+
open_history.close()
|
|
114
|
+
print("pylinux:读取history.txt:ok\n Reading the history.txt file:ok")
|
|
115
|
+
except Exception as Ex:
|
|
116
|
+
print(f"pylinux:读取history.txt文件失败\n pylinux: Failed to read the history.txt file \n [{Ex}] \npylinux: 已跳过 Skipped ")
|
|
117
|
+
Linux.print=""
|
|
118
|
+
Linux.linux_help =[[
|
|
119
|
+
["cd"+" "*8+":更换目录位置如果路径中有空格请用'\-'取代空格",
|
|
120
|
+
"history"+" "*3+":查看写过的命令",
|
|
121
|
+
"ls"+" "*8+":查看目录下的文件",
|
|
122
|
+
"pwd"+" "*7+":查看此目录的路径",
|
|
123
|
+
"cat"+" "*7+":查看文件内容",
|
|
124
|
+
"\033[91mfind\033[0m"+" "*6+"\033[91m查看某个文件的位置[find / -name ]\033[0m",
|
|
125
|
+
"rm"+" "*8+":删除文件(夹)[rm -r]",
|
|
126
|
+
"mkdir"+" "*5+":创建文件夹",
|
|
127
|
+
"touch"+" "*5+":创建文件",
|
|
128
|
+
"bash"+" "*6+":执行bash脚本"],
|
|
129
|
+
["clear"+" "*6+":清屏",
|
|
130
|
+
"su"+" "*8+":登录用户",
|
|
131
|
+
"linux-wget"+":pylinux下载工具",
|
|
132
|
+
"return ~~~ : 将命令 ~~~ 返回输出",
|
|
133
|
+
"linux-system ~~~ : 向系统发送 ~~~"
|
|
134
|
+
]
|
|
135
|
+
]]
|
|
136
|
+
Linux.run = Linux.执行命令
|
|
137
|
+
print("pylinux:初始化:ok\n Initializing:ok")
|
|
138
|
+
if not linux_file_path:
|
|
139
|
+
print("如果使用'su'请先设置文件存放地(pylinux_file_path)\n 请使用'pylinux-file-path [you path file]'设置")
|
|
140
|
+
def 执行命令(Linux,*命令):
|
|
141
|
+
命令= str(*命令) if 命令 else False
|
|
142
|
+
if 命令=="\n":
|
|
143
|
+
return None
|
|
144
|
+
Linux.命令_列表=[]
|
|
145
|
+
路径_print='..'+Linux.工作路径[-10:] if len(Linux.工作路径)>10 else Linux.工作路径
|
|
146
|
+
Linux.str_input=str(input(f"\033[92m(Linux)-[{Linux.print}{路径_print}]$\033[0m") if not 命令 else 命令)
|
|
147
|
+
##################################
|
|
148
|
+
if Linux.str_input:
|
|
149
|
+
Linux.history_temp+=Linux.str_input+"\n"
|
|
150
|
+
Linux.命令_列表=Linux.str_input.split(" ")#分割字符
|
|
151
|
+
Linux.命令_列表 = [data.replace("/-"," ") for data in Linux.命令_列表 if data != ""]
|
|
152
|
+
Linux.命令长度=len(Linux.命令_列表)
|
|
153
|
+
print(f"\033[92m>\033[0m\033[94m{Linux.str_input}\033[0m\033[92m>\033[0m")
|
|
154
|
+
if Linux.命令_列表[0]=="cd":#
|
|
155
|
+
LJ_temp=Linux.工作路径
|
|
156
|
+
"""
|
|
157
|
+
if ((Linux.命令_列表[1][-1]=="\\" ) and (Linux.命令_列表[1]!="/")) if len(Linux.命令_列表[1])>1 else False:
|
|
158
|
+
jio=Linux.命令_列表[1][:-1]
|
|
159
|
+
else:
|
|
160
|
+
jio=Linux.命令_列表[1]
|
|
161
|
+
"""
|
|
162
|
+
if len(Linux.命令_列表[1])>1 :
|
|
163
|
+
if Linux.access != "#/*/" :
|
|
164
|
+
if Linux.access in Linux.命令_列表[1] or Linux.access == "0" :#and Linux.access != Linux.命令_列表[1]:
|
|
165
|
+
Linux.工作路径=Linux.命令_列表[1]
|
|
166
|
+
else:
|
|
167
|
+
print("\033[91m您没有足够的权限访问\033[0m")
|
|
168
|
+
Linux.工作路径=LJ_temp
|
|
169
|
+
try:
|
|
170
|
+
os.listdir(Linux.工作路径)
|
|
171
|
+
except PermissionError :
|
|
172
|
+
print("\033[91m您没有足够的权限访问\033[0m")
|
|
173
|
+
Linux.工作路径=LJ_temp
|
|
174
|
+
except Exception as Ex:
|
|
175
|
+
print(f"\033[91m错误{[Ex]}\033[0m")
|
|
176
|
+
Linux.工作路径=LJ_temp
|
|
177
|
+
os.chdir(Linux.工作路径)
|
|
178
|
+
Linux.工作路径=os.getcwd() if ( os.getcwd()[-1]=="/" or os.getcwd()[-1]==r"\\") else (os.getcwd() + "/" if ( "/" in os.getcwd() ) else os.getcwd()+"\\")
|
|
179
|
+
elif Linux.命令_列表[0]=="ls":
|
|
180
|
+
if Linux.access in Linux.工作路径 or Linux.access == "0" :
|
|
181
|
+
try:
|
|
182
|
+
#os.path.isdir()如果是文件夹则返回True isfile
|
|
183
|
+
if Linux.命令长度 == 1 or ( Linux.命令长度 == 2 and Linux.命令_列表[1] not in ["-t","-b","-l"] and (Linux.access in Linux.命令_列表[1] or Linux.access == "0")):
|
|
184
|
+
for i in os.listdir(os.getcwd() if Linux.命令长度 != 2 else Linux.命令_列表[1]):
|
|
185
|
+
print("\033[94m"+i+"\033[0m" if os.path.isdir(i) else i)
|
|
186
|
+
elif Linux.命令长度==2:
|
|
187
|
+
if Linux.命令_列表[1]=="-t":
|
|
188
|
+
for i in os.listdir(Linux.工作路径):
|
|
189
|
+
print(f"\033[94m{i} -- "+str(calculate_folder_depth(i))+"\033[0m" if os.path.isdir(i) else i)
|
|
190
|
+
elif Linux.命令_列表[1]=="-l":
|
|
191
|
+
for i in os.listdir(Linux.工作路径):
|
|
192
|
+
print(f"\033[94m{i} -- "+str(get_folder_size_getsize(i))+"\033[0m" if os.path.isdir(i) else f"{i} -- "+str(get_folder_size_getsize(i))+"B")
|
|
193
|
+
else:
|
|
194
|
+
print("错误还没有此功能")
|
|
195
|
+
except PermissionError:
|
|
196
|
+
print(f"\033[91m您没有足够的权限\033[0m")
|
|
197
|
+
except Exception as Ex:
|
|
198
|
+
print(f"错误{Ex}")
|
|
199
|
+
else:
|
|
200
|
+
print(f"\033[91m您没有足够的权限查看\033[0m")
|
|
201
|
+
elif Linux.命令_列表[0]=="history":
|
|
202
|
+
try :
|
|
203
|
+
|
|
204
|
+
Linux.history_temp= "" if ( Linux.命令_列表[1]=="-c" if len(Linux.命令_列表)>1 else False) else Linux.history_temp
|
|
205
|
+
if (Linux.命令_列表[1]=="-a" if len(Linux.命令_列表)>1 else False) :
|
|
206
|
+
if linux_file_path:
|
|
207
|
+
temp_path = Linux.工作路径
|
|
208
|
+
Linux.执行命令(f'cd {pylinux_file_path}')
|
|
209
|
+
if "su" in os.listdir():
|
|
210
|
+
lk_history=open("histort.txt","a")
|
|
211
|
+
lk_history.write(Linux.history_temp+"\n")
|
|
212
|
+
lk_history.close()
|
|
213
|
+
else:
|
|
214
|
+
print(f"在{pylinux_file_path}中没有histort.txt文件")
|
|
215
|
+
Linux.执行命令(f"cd {temp_path}")
|
|
216
|
+
else:
|
|
217
|
+
print("还没有设置pylinux_file_path,请使用'pylinux-file-path [you path file]'设置命令设置文件位置")
|
|
218
|
+
elif Linux.命令_列表[1]=="-c" if len(Linux.命令_列表)>1 else False:
|
|
219
|
+
Linux.history_temp = ""
|
|
220
|
+
else :
|
|
221
|
+
print(Linux.history_temp)
|
|
222
|
+
except Exception as Ex:
|
|
223
|
+
print(f"错误[{Ex}]")
|
|
224
|
+
elif Linux.命令_列表[0]=="pwd":
|
|
225
|
+
print(os.getcwd())
|
|
226
|
+
elif Linux.命令_列表[0]=="cat":
|
|
227
|
+
if Linux.命令长度>1:
|
|
228
|
+
if Linux.access in Linux.工作路径 or Linux.access == "0" :
|
|
229
|
+
try:
|
|
230
|
+
预处理=open(Linux.命令_列表[1],"r")
|
|
231
|
+
print(预处理.read())
|
|
232
|
+
预处理.close()
|
|
233
|
+
except Exception as Ex:
|
|
234
|
+
print(f"没有\"{Linux.命令_列表[1]}\"文件")
|
|
235
|
+
else:
|
|
236
|
+
print(f"\033[91m您没有足够的权限查看\033[0m")
|
|
237
|
+
else:
|
|
238
|
+
print("没有要打开的文件")
|
|
239
|
+
elif Linux.命令_列表[0]=="rm":
|
|
240
|
+
if Linux.命令长度>2:
|
|
241
|
+
#os.path.exists(路径) 用于判断是否为有效路径不区分文件或目录
|
|
242
|
+
if (Linux.access in Linux.工作路径 or Linux.access == "0") and os.path.exists(Linux.命令_列表[2]) :
|
|
243
|
+
if Linux.命令_列表[1]=="-r":
|
|
244
|
+
# 递归删除目录及其内容shutil.rmtree()
|
|
245
|
+
#删除文件os.remove()
|
|
246
|
+
try:
|
|
247
|
+
if os.path.isdir(Linux.命令_列表[2]):
|
|
248
|
+
shutil.rmtree(Linux.命令_列表[2])
|
|
249
|
+
else:
|
|
250
|
+
os.remove(Linux.命令_列表[2]) #os.remove(临时路径) if os.path.isfile(临时路径) else shutil.rmtree(临时路径)
|
|
251
|
+
except Exception as Ex:
|
|
252
|
+
print(f"\033[91m删除失败[{Ex}]\033[0m")
|
|
253
|
+
else:
|
|
254
|
+
print(f"\033[91m您没有足够的权删除{Linux.命令_列表[2]}\033[0m")
|
|
255
|
+
elif Linux.命令_列表[0]=="find":
|
|
256
|
+
if Linux.命令长度>3:
|
|
257
|
+
if Linux.命令_列表[1]=="/":
|
|
258
|
+
if Linux.命令_列表[2]=="-name":
|
|
259
|
+
try:
|
|
260
|
+
print(Linux.命令_列表[3],":[",os.path.dirname(Linux.命令_列表[3]),"]")
|
|
261
|
+
except FileNotFoundError :
|
|
262
|
+
print("\033[91m{Linux.命令_列表[3]}不存在\033[0m")
|
|
263
|
+
except Exception as Ex:
|
|
264
|
+
print("请检查名称是否正确")
|
|
265
|
+
else :
|
|
266
|
+
print("\033[91m请写完整指令\033[0m")
|
|
267
|
+
elif Linux.命令_列表[0]=="mkdir":#创建文件夹
|
|
268
|
+
if Linux.命令长度>1:
|
|
269
|
+
if (Linux.access in Linux.工作路径 or Linux.access == "0") and ((Linux.access in Linux.命令_列表[1]) if os.path.exists(Linux.命令_列表[1]) else True):
|
|
270
|
+
try:
|
|
271
|
+
os.makedirs(Linux.命令_列表[1])
|
|
272
|
+
except Exception as Ex:
|
|
273
|
+
print(f"\033[91m创建失败{Ex}\033[0m")
|
|
274
|
+
else:
|
|
275
|
+
print(f"\033[91m您没有足够的权限创建{Linux.命令_列表[1]}文件夹\033[0m")
|
|
276
|
+
else:
|
|
277
|
+
print("\033[91m请把命令写完整\033[0m")
|
|
278
|
+
elif Linux.命令_列表[0]=="touch":#创建文件
|
|
279
|
+
if 1 < Linux.命令长度 <= 2:
|
|
280
|
+
if (Linux.access in Linux.工作路径 or Linux.access == "0") and ((Linux.access in Linux.命令_列表[1]) if os.path.exists(Linux.命令_列表[1]) else True) :
|
|
281
|
+
try:
|
|
282
|
+
with open(Linux.命令_列表[1],"w") as open_:
|
|
283
|
+
open_.close()
|
|
284
|
+
except PermissionError:
|
|
285
|
+
print("\033[91m你没有足够的权限\033[0m")
|
|
286
|
+
except Exception as Ex:
|
|
287
|
+
print(f"\033[91m创建{Linux.命令_列表[1]}失败[{Ex}]\033[0m")
|
|
288
|
+
else:
|
|
289
|
+
print(f"\033[91m您没有足够的权限创建{Linux.命令_列表[1]}文件\033[0m")
|
|
290
|
+
else:
|
|
291
|
+
print("\033[91m请把命令写完整\033[0m")
|
|
292
|
+
elif Linux.命令_列表[0]=="bash":
|
|
293
|
+
if Linux.命令长度==2:
|
|
294
|
+
try:
|
|
295
|
+
print(">bash>开始执行:")
|
|
296
|
+
#with open(Linux.工作路径+Linux.命令_列表[1] if "//" not in Linux.命令_列表[1] and "\\" not in Linux.命令_列表[1] else Linux.命令_列表[1],"r") as 预处理:
|
|
297
|
+
with open(Linux.命令_列表[1] if "//" not in Linux.命令_列表[1] and "\\" not in Linux.命令_列表[1] else Linux.命令_列表[1],"r") as 预处理:
|
|
298
|
+
for 文件命令 in 预处理:
|
|
299
|
+
Linux.执行命令(文件命令.rstrip("\n"))
|
|
300
|
+
预处理.close()
|
|
301
|
+
print("执行结束")
|
|
302
|
+
except FileNotFoundError :
|
|
303
|
+
print(f"没有{Linux.命令_列表[1]}文件")
|
|
304
|
+
except Exception as Ex:
|
|
305
|
+
print(f"执行时出现错误[错误{Ex}]")
|
|
306
|
+
elif Linux.命令_列表[0].upper() in ["PYTHON","PY"]:
|
|
307
|
+
if Linux.命令长度==2 :
|
|
308
|
+
执行文件路径=Linux.命令_列表[1]
|
|
309
|
+
"""
|
|
310
|
+
if ("/" not in Linux.命令_列表[1]) or ("\\" not in Linux.命令_列表[1]):
|
|
311
|
+
执行文件路径=Linux.工作路径+Linux.命令_列表[1]
|
|
312
|
+
print(执行文件路径)
|
|
313
|
+
"""
|
|
314
|
+
try:
|
|
315
|
+
try:
|
|
316
|
+
预处理=open(执行文件路径,"r")
|
|
317
|
+
except Exception as Ex:
|
|
318
|
+
print("\033[91m请检查路径或者文件名称是否正确\033[0m")
|
|
319
|
+
print("\033[91m>开始执行>\033[0m");exec(预处理.read());print("\033[91m执行结束\033[0m")
|
|
320
|
+
预处理.close()
|
|
321
|
+
except Exception as Ex:
|
|
322
|
+
print(f"\033[91m执行文件时发生错误[{Ex}]\033[0m")
|
|
323
|
+
elif Linux.命令长度>=5 or Linux.命令长度==7:
|
|
324
|
+
安装命令列表=[]
|
|
325
|
+
print(Linux.命令长度)
|
|
326
|
+
if Linux.命令长度==5:
|
|
327
|
+
#执行安装命令
|
|
328
|
+
安装命令列表=[sys.executable,Linux.命令_列表[1],Linux.命令_列表[2],Linux.命令_列表[3],Linux.命令_列表[4]]
|
|
329
|
+
elif Linux.命令长度==7:
|
|
330
|
+
安装命令列表=[sys.executable,*Linux.命令_列表[1:].extend(" ","")]
|
|
331
|
+
try:
|
|
332
|
+
subprocess.check_call(安装命令列表)
|
|
333
|
+
except Exception as Ex:
|
|
334
|
+
print(f"\033[91m命令书写错误[错误{Ex}]\033[0m")
|
|
335
|
+
elif len(Linux.命令_列表)==1:
|
|
336
|
+
print("\033[92m>>开始执行\033[0m");tf_py=True
|
|
337
|
+
while tf_py:
|
|
338
|
+
执行=input(">>>")
|
|
339
|
+
if 执行 !="f":
|
|
340
|
+
try:
|
|
341
|
+
exec(执行)
|
|
342
|
+
except Exception as Ex:
|
|
343
|
+
print(f"错误{Ex}")
|
|
344
|
+
else :
|
|
345
|
+
tf_py=False
|
|
346
|
+
print(f"\033[91m{Linux.str_input}结束>\033[0m")
|
|
347
|
+
elif Linux.命令_列表[0]=="cp":
|
|
348
|
+
if len(Linux.命令_列表)>2:
|
|
349
|
+
if (Linux.access in Linux.工作路径 or Linux.access == "0") and (((Linux.access in Linux.命令_列表[2]) if ("./" not in Linux.命令_列表[2] or ".\\" not in Linux.命令_列表[2]) else (Linux.access in Linux.工作路径 or Linux.access == "0") ) if os.path.exists(Linux.命令_列表[2]) else os.path.isfile(Linux.命令_列表[2])) :
|
|
350
|
+
try:
|
|
351
|
+
if os.path.isfile(Linux.命令_列表[1]):
|
|
352
|
+
shutil.copy(Linux.命令_列表[1], Linux.命令_列表[2])
|
|
353
|
+
else:
|
|
354
|
+
shutil.copytree(Linux.命令_列表[1], Linux.命令_列表[2])
|
|
355
|
+
except FileExistsError as File:
|
|
356
|
+
print(f"\033[91m[错误{Linux.命令_列表[1]}在{Linux.命令_列表[2]}中存在][详细:{File}]\033[0m")
|
|
357
|
+
if input(f"请问您要覆盖{Linux.命令_列表[2]}中{Linux.命令_列表[1]}吗(Y/n/是/否)").upper() in ["Y","N","是","否"]:
|
|
358
|
+
shutil.copytree(Linux.命令_列表[1], Linux.命令_列表[2],dirs_exist_ok=True)
|
|
359
|
+
except Exception as Ex:
|
|
360
|
+
print(f"\033[91m[错误{Ex}]\033[0m")
|
|
361
|
+
else:
|
|
362
|
+
print(f"\033[91m您没有足够的权限复制{Linux.命令_列表[1]}到{Linux.命令_列表[2]}\033[0m")
|
|
363
|
+
else:
|
|
364
|
+
print("还没有此功能或查看命令是否正确")
|
|
365
|
+
#[@_&]
|
|
366
|
+
#
|
|
367
|
+
elif Linux.命令_列表[0]=="su":
|
|
368
|
+
if linux_file_path :
|
|
369
|
+
if 2 <= Linux.命令长度 <= 3 :
|
|
370
|
+
TF = False
|
|
371
|
+
TF_user = False
|
|
372
|
+
if Linux.命令_列表[1] == "-" and Linux.命令长度 == 3:
|
|
373
|
+
sequence = 2
|
|
374
|
+
else:
|
|
375
|
+
sequence = 1
|
|
376
|
+
temp_path = Linux.工作路径
|
|
377
|
+
Linux.执行命令(f'cd {pylinux_file_path}')
|
|
378
|
+
if "su" in os.listdir():
|
|
379
|
+
with open("su") as open_su:
|
|
380
|
+
for i in open_su.read().split("\n"):
|
|
381
|
+
list_i=i.split("#*$")
|
|
382
|
+
if Linux.命令_列表[sequence] == list_i[0] :
|
|
383
|
+
#getpass.getpass
|
|
384
|
+
TF_user = True
|
|
385
|
+
if (getpass("输入密码: ") == list_i[2] ) if list_i[2] != "0" else True :
|
|
386
|
+
Linux.access=list_i[1]
|
|
387
|
+
TF = True;Linux.login_tf = True
|
|
388
|
+
else:
|
|
389
|
+
print("密码错误")
|
|
390
|
+
break
|
|
391
|
+
open_su.close()
|
|
392
|
+
else:
|
|
393
|
+
print(f"没有'su'文件")
|
|
394
|
+
if TF:
|
|
395
|
+
Linux.print=f"@{Linux.命令_列表[sequence]}: "
|
|
396
|
+
elif TF_user :
|
|
397
|
+
pass
|
|
398
|
+
else:
|
|
399
|
+
print(f"\033[91m没有用户{Linux.命令_列表[1]}\033[0m")
|
|
400
|
+
Linux.执行命令(f"cd {temp_path}")
|
|
401
|
+
else:
|
|
402
|
+
print("还没有设置pylinux_file_path,请使用'pylinux-file-path [you path file]'设置命令设置文件位置")
|
|
403
|
+
elif Linux.命令_列表[0] == "clear":
|
|
404
|
+
clear_screen()
|
|
405
|
+
elif Linux.命令_列表[0]=="linux-wget":
|
|
406
|
+
if 2 <= Linux.命令长度 < 4 :
|
|
407
|
+
print("正在下载")
|
|
408
|
+
download_file(Linux.命令_列表[1],filename= Linux.命令_列表[2] if Linux.命令长度 == 3 else None )
|
|
409
|
+
print("下载完成")
|
|
410
|
+
elif Linux.命令_列表[0].upper() in ["EXIT","F"]:
|
|
411
|
+
if Linux.命令长度 == 2:
|
|
412
|
+
if Linux.命令_列表[1] == "-l":
|
|
413
|
+
return "exit"
|
|
414
|
+
if Linux.login_tf :
|
|
415
|
+
Linux.print = ""
|
|
416
|
+
Linux.user = ""
|
|
417
|
+
Linux.access = Linux.default_access
|
|
418
|
+
Linux.login_tf=False
|
|
419
|
+
return None
|
|
420
|
+
else:
|
|
421
|
+
return "exit"
|
|
422
|
+
elif Linux.命令_列表[0] == "return":
|
|
423
|
+
return_str = ""
|
|
424
|
+
for i in Linux.命令_列表[1:]:
|
|
425
|
+
return_str += i +" "
|
|
426
|
+
return return_str
|
|
427
|
+
elif Linux.命令_列表[0] == "linux-system":
|
|
428
|
+
return_str = ""
|
|
429
|
+
for i in Linux.命令_列表[1:]:
|
|
430
|
+
return_str += i +" "
|
|
431
|
+
os.system(return_str)
|
|
432
|
+
elif Linux.命令_列表[0] == "pylinux-file-path":
|
|
433
|
+
if Linux.命令长度 >1 :
|
|
434
|
+
linux_file_path = Linux.命令_列表[1]
|
|
435
|
+
else:
|
|
436
|
+
print("命令不正确")
|
|
437
|
+
else :
|
|
438
|
+
try :
|
|
439
|
+
subprocess.run([*Linux.命令_列表])#os.system()
|
|
440
|
+
except Exception as Ex:
|
|
441
|
+
print(Ex)
|
|
442
|
+
for i_cmd_ml_ in Linux.linux_help [0]:
|
|
443
|
+
for ii_cmd_ml_ in i_cmd_ml_:
|
|
444
|
+
print(ii_cmd_ml_)
|
|
445
|
+
if input(">")=='f':
|
|
446
|
+
break
|
|
447
|
+
if 命令:
|
|
448
|
+
return "exit"
|
|
449
|
+
print("pylinux:函数准备:ok \n Preparing the function:ok")
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "qimomo-py-linux"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
authors = [
|
|
9
|
+
{ name="Your Name", email="qimomo.17@qq.com" },
|
|
10
|
+
]
|
|
11
|
+
description = "pylinux python中简单运行linux命令"
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
license = { file="LICENSE" }
|
|
14
|
+
dependencies = [
|
|
15
|
+
"requests>=2.25.1",
|
|
16
|
+
"tqdm",
|
|
17
|
+
]
|
|
18
|
+
[tool.setuptools]
|
|
19
|
+
packages = ["pylinux"]
|
|
20
|
+
package-dir = { "pylinux" = "pylinux" }
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: qimomo-py-linux
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: pylinux python中简单运行linux命令
|
|
5
|
+
Author-email: Your Name <qimomo.17@qq.com>
|
|
6
|
+
License: Copyright 2025 七魔陌
|
|
7
|
+
|
|
8
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
9
|
+
|
|
10
|
+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
11
|
+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
12
|
+
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
13
|
+
|
|
14
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
Requires-Dist: requests>=2.25.1
|
|
18
|
+
Requires-Dist: tqdm
|
|
19
|
+
Dynamic: license-file
|
|
20
|
+
|
|
21
|
+
## Author
|
|
22
|
+
**七魔陌**
|
|
23
|
+
- Email: qimomo.17@qq.com
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
pylinux/__init__.py
|
|
5
|
+
pylinux/pylinux.py
|
|
6
|
+
qimomo_py_linux.egg-info/PKG-INFO
|
|
7
|
+
qimomo_py_linux.egg-info/SOURCES.txt
|
|
8
|
+
qimomo_py_linux.egg-info/dependency_links.txt
|
|
9
|
+
qimomo_py_linux.egg-info/requires.txt
|
|
10
|
+
qimomo_py_linux.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pylinux
|