bcmd 0.5.3__py3-none-any.whl → 0.5.4__py3-none-any.whl
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.
Potentially problematic release.
This version of bcmd might be problematic. Click here for more details.
- bcmd/common/func.py +19 -19
- bcmd/common/password.py +34 -34
- bcmd/main.py +10 -10
- bcmd/resources/project/.vscode/launch.json +14 -14
- bcmd/resources/project/.vscode/tasks.json +67 -67
- bcmd/tasks/__init__.py +15 -15
- bcmd/tasks/bin.py +104 -104
- bcmd/tasks/code.py +96 -96
- bcmd/tasks/crypto.py +116 -116
- bcmd/tasks/debian.py +78 -78
- bcmd/tasks/download.py +74 -74
- bcmd/tasks/image.py +205 -201
- bcmd/tasks/json.py +25 -25
- bcmd/tasks/lib.py +118 -118
- bcmd/tasks/math.py +97 -97
- bcmd/tasks/mirror.py +46 -46
- bcmd/tasks/project.py +34 -34
- bcmd/tasks/proxy.py +55 -54
- bcmd/tasks/time.py +81 -81
- bcmd/tasks/venv.py +217 -217
- {bcmd-0.5.3.dist-info → bcmd-0.5.4.dist-info}/METADATA +1 -1
- bcmd-0.5.4.dist-info/RECORD +30 -0
- bcmd-0.5.3.dist-info/RECORD +0 -30
- {bcmd-0.5.3.dist-info → bcmd-0.5.4.dist-info}/WHEEL +0 -0
- {bcmd-0.5.3.dist-info → bcmd-0.5.4.dist-info}/entry_points.txt +0 -0
- {bcmd-0.5.3.dist-info → bcmd-0.5.4.dist-info}/top_level.txt +0 -0
bcmd/tasks/code.py
CHANGED
|
@@ -1,96 +1,96 @@
|
|
|
1
|
-
from pathlib import Path
|
|
2
|
-
from typing import Final
|
|
3
|
-
|
|
4
|
-
import typer
|
|
5
|
-
from beni import bfile, bpath, btask
|
|
6
|
-
from beni.bcolor import printGreen, printMagenta, printYellow
|
|
7
|
-
from beni.bfunc import syncCall
|
|
8
|
-
|
|
9
|
-
app: Final = btask.newSubApp('code 工具')
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
@app.command()
|
|
13
|
-
@syncCall
|
|
14
|
-
async def tidy_tasks(
|
|
15
|
-
tasks_path: Path = typer.Argument(Path.cwd(), help="tasks 路径"),
|
|
16
|
-
):
|
|
17
|
-
'整理 task 项目中的 tasks/__init__.py'
|
|
18
|
-
|
|
19
|
-
initFile = tasks_path / '__init__.py'
|
|
20
|
-
btask.assertTrue(initFile.is_file(), '文件不存在', initFile)
|
|
21
|
-
files = bpath.listFile(tasks_path)
|
|
22
|
-
files = [x for x in files if not x.name.startswith('_')]
|
|
23
|
-
contents = [f'from . import {x.stem}' for x in files]
|
|
24
|
-
contents.insert(0, '# type: ignore')
|
|
25
|
-
contents.append('')
|
|
26
|
-
content = '\n'.join(contents)
|
|
27
|
-
oldContent = await bfile.readText(initFile)
|
|
28
|
-
if oldContent != content:
|
|
29
|
-
await bfile.writeText(
|
|
30
|
-
initFile,
|
|
31
|
-
content,
|
|
32
|
-
)
|
|
33
|
-
printYellow(initFile)
|
|
34
|
-
printMagenta(content)
|
|
35
|
-
printGreen('OK')
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
@app.command()
|
|
39
|
-
@syncCall
|
|
40
|
-
async def tidy_modules(
|
|
41
|
-
modules_path: Path = typer.Argument(Path.cwd(), help="modules_path 路径"),
|
|
42
|
-
):
|
|
43
|
-
'整理 fastapi 项目中的 modules/__init__.py'
|
|
44
|
-
|
|
45
|
-
importContents: list[str] = []
|
|
46
|
-
managerContents: list[str] = []
|
|
47
|
-
|
|
48
|
-
xxdict: dict[str, set[Path]] = {}
|
|
49
|
-
for file in sorted(modules_path.glob('**/*Manager.py')):
|
|
50
|
-
if file.parent == modules_path:
|
|
51
|
-
subName = '.'
|
|
52
|
-
elif file.parent.parent == modules_path:
|
|
53
|
-
subName = f'.{file.parent.stem}'
|
|
54
|
-
else:
|
|
55
|
-
continue
|
|
56
|
-
xxdict.setdefault(subName, set()).add(file)
|
|
57
|
-
for subName in sorted(xxdict.keys()):
|
|
58
|
-
files = sorted(xxdict[subName])
|
|
59
|
-
importContents.append(f'from {subName} import {", ".join([x.stem for x in files])}')
|
|
60
|
-
managerContents.extend([f' {x.stem},' for x in sorted([y for x in xxdict.values() for y in x])])
|
|
61
|
-
|
|
62
|
-
managerContents = [x for x in managerContents if x]
|
|
63
|
-
contents = [
|
|
64
|
-
'\n'.join(importContents),
|
|
65
|
-
'managers = [\n' + '\n'.join(managerContents) + '\n]',
|
|
66
|
-
]
|
|
67
|
-
content = '\n\n'.join(contents) + '\n'
|
|
68
|
-
file = modules_path / '__init__.py'
|
|
69
|
-
printYellow(str(file))
|
|
70
|
-
printMagenta(content)
|
|
71
|
-
await bfile.writeText(file, content)
|
|
72
|
-
printGreen('OK')
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
@app.command()
|
|
76
|
-
@syncCall
|
|
77
|
-
async def gen_init_py(
|
|
78
|
-
workspace_path: Path = typer.Argument(Path.cwd(), help='workspace 路径'),
|
|
79
|
-
):
|
|
80
|
-
'递归生成 __init__.py 文件'
|
|
81
|
-
|
|
82
|
-
async def makeInitFiles(p: Path):
|
|
83
|
-
if p.name == '__pycache__':
|
|
84
|
-
return
|
|
85
|
-
if p.name.startswith('.'):
|
|
86
|
-
return
|
|
87
|
-
if workspace_path != p:
|
|
88
|
-
initFile = p / '__init__.py'
|
|
89
|
-
if not initFile.exists():
|
|
90
|
-
printYellow(initFile)
|
|
91
|
-
await bfile.writeText(initFile, '')
|
|
92
|
-
for x in bpath.listDir(p):
|
|
93
|
-
await makeInitFiles(x)
|
|
94
|
-
|
|
95
|
-
await makeInitFiles(workspace_path)
|
|
96
|
-
printGreen('OK')
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
from typing import Final
|
|
3
|
+
|
|
4
|
+
import typer
|
|
5
|
+
from beni import bfile, bpath, btask
|
|
6
|
+
from beni.bcolor import printGreen, printMagenta, printYellow
|
|
7
|
+
from beni.bfunc import syncCall
|
|
8
|
+
|
|
9
|
+
app: Final = btask.newSubApp('code 工具')
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@app.command()
|
|
13
|
+
@syncCall
|
|
14
|
+
async def tidy_tasks(
|
|
15
|
+
tasks_path: Path = typer.Argument(Path.cwd(), help="tasks 路径"),
|
|
16
|
+
):
|
|
17
|
+
'整理 task 项目中的 tasks/__init__.py'
|
|
18
|
+
|
|
19
|
+
initFile = tasks_path / '__init__.py'
|
|
20
|
+
btask.assertTrue(initFile.is_file(), '文件不存在', initFile)
|
|
21
|
+
files = bpath.listFile(tasks_path)
|
|
22
|
+
files = [x for x in files if not x.name.startswith('_')]
|
|
23
|
+
contents = [f'from . import {x.stem}' for x in files]
|
|
24
|
+
contents.insert(0, '# type: ignore')
|
|
25
|
+
contents.append('')
|
|
26
|
+
content = '\n'.join(contents)
|
|
27
|
+
oldContent = await bfile.readText(initFile)
|
|
28
|
+
if oldContent != content:
|
|
29
|
+
await bfile.writeText(
|
|
30
|
+
initFile,
|
|
31
|
+
content,
|
|
32
|
+
)
|
|
33
|
+
printYellow(initFile)
|
|
34
|
+
printMagenta(content)
|
|
35
|
+
printGreen('OK')
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
@app.command()
|
|
39
|
+
@syncCall
|
|
40
|
+
async def tidy_modules(
|
|
41
|
+
modules_path: Path = typer.Argument(Path.cwd(), help="modules_path 路径"),
|
|
42
|
+
):
|
|
43
|
+
'整理 fastapi 项目中的 modules/__init__.py'
|
|
44
|
+
|
|
45
|
+
importContents: list[str] = []
|
|
46
|
+
managerContents: list[str] = []
|
|
47
|
+
|
|
48
|
+
xxdict: dict[str, set[Path]] = {}
|
|
49
|
+
for file in sorted(modules_path.glob('**/*Manager.py')):
|
|
50
|
+
if file.parent == modules_path:
|
|
51
|
+
subName = '.'
|
|
52
|
+
elif file.parent.parent == modules_path:
|
|
53
|
+
subName = f'.{file.parent.stem}'
|
|
54
|
+
else:
|
|
55
|
+
continue
|
|
56
|
+
xxdict.setdefault(subName, set()).add(file)
|
|
57
|
+
for subName in sorted(xxdict.keys()):
|
|
58
|
+
files = sorted(xxdict[subName])
|
|
59
|
+
importContents.append(f'from {subName} import {", ".join([x.stem for x in files])}')
|
|
60
|
+
managerContents.extend([f' {x.stem},' for x in sorted([y for x in xxdict.values() for y in x])])
|
|
61
|
+
|
|
62
|
+
managerContents = [x for x in managerContents if x]
|
|
63
|
+
contents = [
|
|
64
|
+
'\n'.join(importContents),
|
|
65
|
+
'managers = [\n' + '\n'.join(managerContents) + '\n]',
|
|
66
|
+
]
|
|
67
|
+
content = '\n\n'.join(contents) + '\n'
|
|
68
|
+
file = modules_path / '__init__.py'
|
|
69
|
+
printYellow(str(file))
|
|
70
|
+
printMagenta(content)
|
|
71
|
+
await bfile.writeText(file, content)
|
|
72
|
+
printGreen('OK')
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
@app.command()
|
|
76
|
+
@syncCall
|
|
77
|
+
async def gen_init_py(
|
|
78
|
+
workspace_path: Path = typer.Argument(Path.cwd(), help='workspace 路径'),
|
|
79
|
+
):
|
|
80
|
+
'递归生成 __init__.py 文件'
|
|
81
|
+
|
|
82
|
+
async def makeInitFiles(p: Path):
|
|
83
|
+
if p.name == '__pycache__':
|
|
84
|
+
return
|
|
85
|
+
if p.name.startswith('.'):
|
|
86
|
+
return
|
|
87
|
+
if workspace_path != p:
|
|
88
|
+
initFile = p / '__init__.py'
|
|
89
|
+
if not initFile.exists():
|
|
90
|
+
printYellow(initFile)
|
|
91
|
+
await bfile.writeText(initFile, '')
|
|
92
|
+
for x in bpath.listDir(p):
|
|
93
|
+
await makeInitFiles(x)
|
|
94
|
+
|
|
95
|
+
await makeInitFiles(workspace_path)
|
|
96
|
+
printGreen('OK')
|
bcmd/tasks/crypto.py
CHANGED
|
@@ -1,116 +1,116 @@
|
|
|
1
|
-
import getpass
|
|
2
|
-
import json
|
|
3
|
-
from pathlib import Path
|
|
4
|
-
from typing import Final
|
|
5
|
-
|
|
6
|
-
import pyperclip
|
|
7
|
-
import typer
|
|
8
|
-
from beni import bcolor, bcrypto, btask
|
|
9
|
-
from beni.bfunc import syncCall
|
|
10
|
-
from rich.console import Console
|
|
11
|
-
|
|
12
|
-
app: Final = btask.newSubApp('加密(v2)')
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
@app.command()
|
|
16
|
-
@syncCall
|
|
17
|
-
async def encrypt_text():
|
|
18
|
-
'加密文本(使用剪贴板内容)'
|
|
19
|
-
content = pyperclip.paste()
|
|
20
|
-
assert content, '剪贴板内容不能为空'
|
|
21
|
-
bcolor.printGreen(content)
|
|
22
|
-
password = _genPassword()
|
|
23
|
-
result = bcrypto.encryptText(content, password)
|
|
24
|
-
pyperclip.copy(result)
|
|
25
|
-
print('密文已复制到剪贴板')
|
|
26
|
-
bcolor.printYellow(result)
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
@app.command()
|
|
30
|
-
@syncCall
|
|
31
|
-
async def decrypt_text():
|
|
32
|
-
'解密文本(使用剪贴板内容)'
|
|
33
|
-
content = pyperclip.paste().strip()
|
|
34
|
-
bcolor.printYellow(content)
|
|
35
|
-
while True:
|
|
36
|
-
try:
|
|
37
|
-
password = getpass.getpass('输入密码:')
|
|
38
|
-
result = bcrypto.decryptText(content, password)
|
|
39
|
-
print('解密成功')
|
|
40
|
-
bcolor.printGreen(result)
|
|
41
|
-
return
|
|
42
|
-
except KeyboardInterrupt:
|
|
43
|
-
break
|
|
44
|
-
except BaseException:
|
|
45
|
-
pass
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
@app.command()
|
|
49
|
-
@syncCall
|
|
50
|
-
async def encrypt_json():
|
|
51
|
-
'生成JSON密文(使用剪贴板内容)'
|
|
52
|
-
content = pyperclip.paste()
|
|
53
|
-
try:
|
|
54
|
-
data = json.loads(content)
|
|
55
|
-
except:
|
|
56
|
-
return btask.abort('错误:剪贴板内容必须是JSON格式', content)
|
|
57
|
-
Console().print_json(data=data, indent=4, ensure_ascii=False, sort_keys=True)
|
|
58
|
-
password = _genPassword()
|
|
59
|
-
result = bcrypto.encryptJson(data, password)
|
|
60
|
-
pyperclip.copy(result)
|
|
61
|
-
print('密文已复制到剪贴板')
|
|
62
|
-
bcolor.printYellow(result)
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
@app.command()
|
|
66
|
-
@syncCall
|
|
67
|
-
async def decrypt_json():
|
|
68
|
-
'还原JSON密文内容(使用剪贴板内容)'
|
|
69
|
-
content = pyperclip.paste().strip()
|
|
70
|
-
bcolor.printYellow(content)
|
|
71
|
-
while True:
|
|
72
|
-
try:
|
|
73
|
-
password = getpass.getpass('输入密码:')
|
|
74
|
-
data = bcrypto.decryptJson(content, password)
|
|
75
|
-
Console().print_json(data=data, indent=4, ensure_ascii=False, sort_keys=True)
|
|
76
|
-
return
|
|
77
|
-
except KeyboardInterrupt:
|
|
78
|
-
break
|
|
79
|
-
except BaseException:
|
|
80
|
-
pass
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
@app.command()
|
|
84
|
-
@syncCall
|
|
85
|
-
async def encrypt_file(
|
|
86
|
-
file: Path = typer.Argument(..., help='指定需要加密的文件')
|
|
87
|
-
):
|
|
88
|
-
'加密文件(文件路径使用剪贴板内容)'
|
|
89
|
-
assert file.is_file(), '文件不存在'
|
|
90
|
-
password = _genPassword()
|
|
91
|
-
await bcrypto.encryptFile(file, password)
|
|
92
|
-
bcolor.printGreen('OK')
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
@app.command()
|
|
96
|
-
@syncCall
|
|
97
|
-
async def decrypt_file(
|
|
98
|
-
file: Path = typer.Argument(..., help='指定需要解密的文件')
|
|
99
|
-
):
|
|
100
|
-
'解密文件(文件路径使用剪贴板内容)'
|
|
101
|
-
assert file.is_file(), '文件不存在'
|
|
102
|
-
password = getpass.getpass('输入密码:')
|
|
103
|
-
await bcrypto.decryptFile(file, password)
|
|
104
|
-
bcolor.printGreen('OK')
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
# ------------------------------------------------------------------------------------
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
def _genPassword():
|
|
111
|
-
password = ''
|
|
112
|
-
while not password:
|
|
113
|
-
password = getpass.getpass('输入密码:')
|
|
114
|
-
while password != getpass.getpass('再次密码:'):
|
|
115
|
-
pass
|
|
116
|
-
return password
|
|
1
|
+
import getpass
|
|
2
|
+
import json
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from typing import Final
|
|
5
|
+
|
|
6
|
+
import pyperclip
|
|
7
|
+
import typer
|
|
8
|
+
from beni import bcolor, bcrypto, btask
|
|
9
|
+
from beni.bfunc import syncCall
|
|
10
|
+
from rich.console import Console
|
|
11
|
+
|
|
12
|
+
app: Final = btask.newSubApp('加密(v2)')
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@app.command()
|
|
16
|
+
@syncCall
|
|
17
|
+
async def encrypt_text():
|
|
18
|
+
'加密文本(使用剪贴板内容)'
|
|
19
|
+
content = pyperclip.paste()
|
|
20
|
+
assert content, '剪贴板内容不能为空'
|
|
21
|
+
bcolor.printGreen(content)
|
|
22
|
+
password = _genPassword()
|
|
23
|
+
result = bcrypto.encryptText(content, password)
|
|
24
|
+
pyperclip.copy(result)
|
|
25
|
+
print('密文已复制到剪贴板')
|
|
26
|
+
bcolor.printYellow(result)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@app.command()
|
|
30
|
+
@syncCall
|
|
31
|
+
async def decrypt_text():
|
|
32
|
+
'解密文本(使用剪贴板内容)'
|
|
33
|
+
content = pyperclip.paste().strip()
|
|
34
|
+
bcolor.printYellow(content)
|
|
35
|
+
while True:
|
|
36
|
+
try:
|
|
37
|
+
password = getpass.getpass('输入密码:')
|
|
38
|
+
result = bcrypto.decryptText(content, password)
|
|
39
|
+
print('解密成功')
|
|
40
|
+
bcolor.printGreen(result)
|
|
41
|
+
return
|
|
42
|
+
except KeyboardInterrupt:
|
|
43
|
+
break
|
|
44
|
+
except BaseException:
|
|
45
|
+
pass
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
@app.command()
|
|
49
|
+
@syncCall
|
|
50
|
+
async def encrypt_json():
|
|
51
|
+
'生成JSON密文(使用剪贴板内容)'
|
|
52
|
+
content = pyperclip.paste()
|
|
53
|
+
try:
|
|
54
|
+
data = json.loads(content)
|
|
55
|
+
except:
|
|
56
|
+
return btask.abort('错误:剪贴板内容必须是JSON格式', content)
|
|
57
|
+
Console().print_json(data=data, indent=4, ensure_ascii=False, sort_keys=True)
|
|
58
|
+
password = _genPassword()
|
|
59
|
+
result = bcrypto.encryptJson(data, password)
|
|
60
|
+
pyperclip.copy(result)
|
|
61
|
+
print('密文已复制到剪贴板')
|
|
62
|
+
bcolor.printYellow(result)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
@app.command()
|
|
66
|
+
@syncCall
|
|
67
|
+
async def decrypt_json():
|
|
68
|
+
'还原JSON密文内容(使用剪贴板内容)'
|
|
69
|
+
content = pyperclip.paste().strip()
|
|
70
|
+
bcolor.printYellow(content)
|
|
71
|
+
while True:
|
|
72
|
+
try:
|
|
73
|
+
password = getpass.getpass('输入密码:')
|
|
74
|
+
data = bcrypto.decryptJson(content, password)
|
|
75
|
+
Console().print_json(data=data, indent=4, ensure_ascii=False, sort_keys=True)
|
|
76
|
+
return
|
|
77
|
+
except KeyboardInterrupt:
|
|
78
|
+
break
|
|
79
|
+
except BaseException:
|
|
80
|
+
pass
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
@app.command()
|
|
84
|
+
@syncCall
|
|
85
|
+
async def encrypt_file(
|
|
86
|
+
file: Path = typer.Argument(..., help='指定需要加密的文件')
|
|
87
|
+
):
|
|
88
|
+
'加密文件(文件路径使用剪贴板内容)'
|
|
89
|
+
assert file.is_file(), '文件不存在'
|
|
90
|
+
password = _genPassword()
|
|
91
|
+
await bcrypto.encryptFile(file, password)
|
|
92
|
+
bcolor.printGreen('OK')
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
@app.command()
|
|
96
|
+
@syncCall
|
|
97
|
+
async def decrypt_file(
|
|
98
|
+
file: Path = typer.Argument(..., help='指定需要解密的文件')
|
|
99
|
+
):
|
|
100
|
+
'解密文件(文件路径使用剪贴板内容)'
|
|
101
|
+
assert file.is_file(), '文件不存在'
|
|
102
|
+
password = getpass.getpass('输入密码:')
|
|
103
|
+
await bcrypto.decryptFile(file, password)
|
|
104
|
+
bcolor.printGreen('OK')
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
# ------------------------------------------------------------------------------------
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def _genPassword():
|
|
111
|
+
password = ''
|
|
112
|
+
while not password:
|
|
113
|
+
password = getpass.getpass('输入密码:')
|
|
114
|
+
while password != getpass.getpass('再次密码:'):
|
|
115
|
+
pass
|
|
116
|
+
return password
|
bcmd/tasks/debian.py
CHANGED
|
@@ -1,78 +1,78 @@
|
|
|
1
|
-
import os
|
|
2
|
-
from typing import Final
|
|
3
|
-
|
|
4
|
-
from beni import bcolor, bfile, bpath, btask, binput
|
|
5
|
-
from beni.bfunc import syncCall
|
|
6
|
-
|
|
7
|
-
app: Final = btask.newSubApp('Debian 系统管理')
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
@app.command()
|
|
11
|
-
@syncCall
|
|
12
|
-
async def install_python():
|
|
13
|
-
'安装python脚本'
|
|
14
|
-
pythonZipFile = ''
|
|
15
|
-
pythonName = ''
|
|
16
|
-
pythonVersion = ''
|
|
17
|
-
bcolor.printYellow(f'官网地址:https://www.python.org/downloads/source/')
|
|
18
|
-
bcolor.printYellow(f'先从官网上下载 python 源码压缩包(.tar.xz)')
|
|
19
|
-
while True:
|
|
20
|
-
pythonZipFile = input('输入python压缩文件名(如:Python-3.12.1.tar.xz):').strip()
|
|
21
|
-
if pythonZipFile.endswith('.tar.xz'):
|
|
22
|
-
pythonName = pythonZipFile.replace('.tar.xz', '')
|
|
23
|
-
pythonVersion = '.'.join(pythonName.split('-')[-1].split('.')[:-1])
|
|
24
|
-
break
|
|
25
|
-
else:
|
|
26
|
-
print('输入有误,请重新输入')
|
|
27
|
-
cmdList: list[str] = [
|
|
28
|
-
f'apt update',
|
|
29
|
-
f'apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libsqlite3-dev libreadline-dev libffi-dev libbz2-dev -y',
|
|
30
|
-
f'tar -xf {pythonZipFile}',
|
|
31
|
-
f'cd {pythonName}',
|
|
32
|
-
f'./configure --enable-optimizations', # 配置编译选项
|
|
33
|
-
f'make -j `nproc`', # 编译源代码,`nproc` 会利用所有可用的 CPU 核心加快编译速度
|
|
34
|
-
f'make altinstall', # 安装 Python,altinstall 避免替换默认的 python 命令
|
|
35
|
-
f'cd ..',
|
|
36
|
-
f'rm -rf {pythonName}',
|
|
37
|
-
f'rm -rf /usr/local/bin/python',
|
|
38
|
-
f'ln -s /usr/local/bin/python{pythonVersion} /usr/local/bin/python',
|
|
39
|
-
f'rm -rf /usr/local/bin/pip',
|
|
40
|
-
f'ln -s /usr/local/bin/pip{pythonVersion} /usr/local/bin/pip',
|
|
41
|
-
f'python --version',
|
|
42
|
-
f'pip --version',
|
|
43
|
-
f'pip install pipx',
|
|
44
|
-
f'pipx install bcmd',
|
|
45
|
-
]
|
|
46
|
-
shFile = bpath.desktop(f'install-python-{pythonName}.sh')
|
|
47
|
-
await bfile.writeText(shFile, '\n'.join(cmdList))
|
|
48
|
-
bcolor.printGreen(f'将以下两个文件拷贝到服务器上,然后执行 sh {shFile.name} 即可安装 python')
|
|
49
|
-
print(pythonZipFile)
|
|
50
|
-
print(shFile)
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
@app.command()
|
|
54
|
-
@syncCall
|
|
55
|
-
async def install_software():
|
|
56
|
-
'安装常用软件'
|
|
57
|
-
await binput.confirm('即将安装这些软件(7z nginx mariadb),是否确认?')
|
|
58
|
-
cmdList: list[str] = [
|
|
59
|
-
f'echo 更新软件包列表',
|
|
60
|
-
f'apt update',
|
|
61
|
-
f'echo 安装 7z',
|
|
62
|
-
f'apt install p7zip-full -y',
|
|
63
|
-
f'echo 安装 nginx',
|
|
64
|
-
f'apt install nginx -y',
|
|
65
|
-
f'systemctl start nginx',
|
|
66
|
-
f'systemctl enable nginx',
|
|
67
|
-
f'systemctl status nginx',
|
|
68
|
-
f'echo 安装 MariaDB',
|
|
69
|
-
f'apt install mariadb-server -y',
|
|
70
|
-
f'systemctl start mariadb',
|
|
71
|
-
f'systemctl enable mariadb',
|
|
72
|
-
f"sed -i 's/bind-address/# bind-address/' /etc/mysql/mariadb.conf.d/50-server.cnf"
|
|
73
|
-
f'systemctl restart mariadb',
|
|
74
|
-
f'systemctl status mariadb',
|
|
75
|
-
|
|
76
|
-
]
|
|
77
|
-
for cmd in cmdList:
|
|
78
|
-
os.system(cmd)
|
|
1
|
+
import os
|
|
2
|
+
from typing import Final
|
|
3
|
+
|
|
4
|
+
from beni import bcolor, bfile, bpath, btask, binput
|
|
5
|
+
from beni.bfunc import syncCall
|
|
6
|
+
|
|
7
|
+
app: Final = btask.newSubApp('Debian 系统管理')
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@app.command()
|
|
11
|
+
@syncCall
|
|
12
|
+
async def install_python():
|
|
13
|
+
'安装python脚本'
|
|
14
|
+
pythonZipFile = ''
|
|
15
|
+
pythonName = ''
|
|
16
|
+
pythonVersion = ''
|
|
17
|
+
bcolor.printYellow(f'官网地址:https://www.python.org/downloads/source/')
|
|
18
|
+
bcolor.printYellow(f'先从官网上下载 python 源码压缩包(.tar.xz)')
|
|
19
|
+
while True:
|
|
20
|
+
pythonZipFile = input('输入python压缩文件名(如:Python-3.12.1.tar.xz):').strip()
|
|
21
|
+
if pythonZipFile.endswith('.tar.xz'):
|
|
22
|
+
pythonName = pythonZipFile.replace('.tar.xz', '')
|
|
23
|
+
pythonVersion = '.'.join(pythonName.split('-')[-1].split('.')[:-1])
|
|
24
|
+
break
|
|
25
|
+
else:
|
|
26
|
+
print('输入有误,请重新输入')
|
|
27
|
+
cmdList: list[str] = [
|
|
28
|
+
f'apt update',
|
|
29
|
+
f'apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libsqlite3-dev libreadline-dev libffi-dev libbz2-dev -y',
|
|
30
|
+
f'tar -xf {pythonZipFile}',
|
|
31
|
+
f'cd {pythonName}',
|
|
32
|
+
f'./configure --enable-optimizations', # 配置编译选项
|
|
33
|
+
f'make -j `nproc`', # 编译源代码,`nproc` 会利用所有可用的 CPU 核心加快编译速度
|
|
34
|
+
f'make altinstall', # 安装 Python,altinstall 避免替换默认的 python 命令
|
|
35
|
+
f'cd ..',
|
|
36
|
+
f'rm -rf {pythonName}',
|
|
37
|
+
f'rm -rf /usr/local/bin/python',
|
|
38
|
+
f'ln -s /usr/local/bin/python{pythonVersion} /usr/local/bin/python',
|
|
39
|
+
f'rm -rf /usr/local/bin/pip',
|
|
40
|
+
f'ln -s /usr/local/bin/pip{pythonVersion} /usr/local/bin/pip',
|
|
41
|
+
f'python --version',
|
|
42
|
+
f'pip --version',
|
|
43
|
+
f'pip install pipx',
|
|
44
|
+
f'pipx install bcmd',
|
|
45
|
+
]
|
|
46
|
+
shFile = bpath.desktop(f'install-python-{pythonName}.sh')
|
|
47
|
+
await bfile.writeText(shFile, '\n'.join(cmdList))
|
|
48
|
+
bcolor.printGreen(f'将以下两个文件拷贝到服务器上,然后执行 sh {shFile.name} 即可安装 python')
|
|
49
|
+
print(pythonZipFile)
|
|
50
|
+
print(shFile)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
@app.command()
|
|
54
|
+
@syncCall
|
|
55
|
+
async def install_software():
|
|
56
|
+
'安装常用软件'
|
|
57
|
+
await binput.confirm('即将安装这些软件(7z nginx mariadb),是否确认?')
|
|
58
|
+
cmdList: list[str] = [
|
|
59
|
+
f'echo 更新软件包列表',
|
|
60
|
+
f'apt update',
|
|
61
|
+
f'echo 安装 7z',
|
|
62
|
+
f'apt install p7zip-full -y',
|
|
63
|
+
f'echo 安装 nginx',
|
|
64
|
+
f'apt install nginx -y',
|
|
65
|
+
f'systemctl start nginx',
|
|
66
|
+
f'systemctl enable nginx',
|
|
67
|
+
f'systemctl status nginx',
|
|
68
|
+
f'echo 安装 MariaDB',
|
|
69
|
+
f'apt install mariadb-server -y',
|
|
70
|
+
f'systemctl start mariadb',
|
|
71
|
+
f'systemctl enable mariadb',
|
|
72
|
+
f"sed -i 's/bind-address/# bind-address/' /etc/mysql/mariadb.conf.d/50-server.cnf"
|
|
73
|
+
f'systemctl restart mariadb',
|
|
74
|
+
f'systemctl status mariadb',
|
|
75
|
+
|
|
76
|
+
]
|
|
77
|
+
for cmd in cmdList:
|
|
78
|
+
os.system(cmd)
|