bcmd 0.5.2__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.2.dist-info → bcmd-0.5.4.dist-info}/METADATA +1 -1
- bcmd-0.5.4.dist-info/RECORD +30 -0
- bcmd-0.5.2.dist-info/RECORD +0 -30
- {bcmd-0.5.2.dist-info → bcmd-0.5.4.dist-info}/WHEEL +0 -0
- {bcmd-0.5.2.dist-info → bcmd-0.5.4.dist-info}/entry_points.txt +0 -0
- {bcmd-0.5.2.dist-info → bcmd-0.5.4.dist-info}/top_level.txt +0 -0
bcmd/tasks/proxy.py
CHANGED
|
@@ -1,54 +1,55 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
from typing import Final
|
|
4
|
-
|
|
5
|
-
import psutil
|
|
6
|
-
import pyperclip
|
|
7
|
-
import typer
|
|
8
|
-
from beni import bcolor, btask
|
|
9
|
-
from beni.bfunc import syncCall, textToAry
|
|
10
|
-
|
|
11
|
-
app: Final = btask.app
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
@app.command()
|
|
15
|
-
@syncCall
|
|
16
|
-
async def proxy(
|
|
17
|
-
port: int = typer.Argument(15236, help="代理服务器端口"),
|
|
18
|
-
):
|
|
19
|
-
'生成终端设置代理服务器的命令'
|
|
20
|
-
processNameAry: list[str] = []
|
|
21
|
-
process = psutil.Process().parent()
|
|
22
|
-
while process:
|
|
23
|
-
processNameAry.append(process.name())
|
|
24
|
-
process = process.parent()
|
|
25
|
-
template = ''
|
|
26
|
-
|
|
27
|
-
# 针对不同的终端使用不同的模板
|
|
28
|
-
if 'cmd.exe' in processNameAry:
|
|
29
|
-
template = cmdTemplate
|
|
30
|
-
elif set(['powershell.exe', 'pwsh.exe']) & set(processNameAry):
|
|
31
|
-
template = powerShellTemplate
|
|
32
|
-
|
|
33
|
-
btask.assertTrue(template, '不支持当前终端({processNameAry})')
|
|
34
|
-
lineAry = textToAry(template.format(port))
|
|
35
|
-
msg = '\n'.join(lineAry)
|
|
36
|
-
bcolor.printMagenta('\r\n' + msg)
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
set
|
|
47
|
-
set
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
$env:
|
|
53
|
-
$env:
|
|
54
|
-
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Final
|
|
4
|
+
|
|
5
|
+
import psutil
|
|
6
|
+
import pyperclip
|
|
7
|
+
import typer
|
|
8
|
+
from beni import bcolor, btask
|
|
9
|
+
from beni.bfunc import syncCall, textToAry
|
|
10
|
+
|
|
11
|
+
app: Final = btask.app
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@app.command()
|
|
15
|
+
@syncCall
|
|
16
|
+
async def proxy(
|
|
17
|
+
port: int = typer.Argument(15236, help="代理服务器端口"),
|
|
18
|
+
):
|
|
19
|
+
'生成终端设置代理服务器的命令'
|
|
20
|
+
processNameAry: list[str] = []
|
|
21
|
+
process = psutil.Process().parent()
|
|
22
|
+
while process:
|
|
23
|
+
processNameAry.append(process.name())
|
|
24
|
+
process = process.parent()
|
|
25
|
+
template = ''
|
|
26
|
+
|
|
27
|
+
# 针对不同的终端使用不同的模板
|
|
28
|
+
if 'cmd.exe' in processNameAry:
|
|
29
|
+
template = cmdTemplate
|
|
30
|
+
elif set(['powershell.exe', 'pwsh.exe']) & set(processNameAry):
|
|
31
|
+
template = powerShellTemplate
|
|
32
|
+
|
|
33
|
+
btask.assertTrue(template, '不支持当前终端({processNameAry})')
|
|
34
|
+
lineAry = textToAry(template.format(port))
|
|
35
|
+
msg = '\n'.join(lineAry)
|
|
36
|
+
bcolor.printMagenta('\r\n' + msg)
|
|
37
|
+
msg += '\n' # 多增加一个换行,直接粘贴的时候相当于最后一行也执行完
|
|
38
|
+
pyperclip.copy(msg)
|
|
39
|
+
bcolor.printYellow('已复制,可直接粘贴使用')
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
# ------------------------------------------------------------------------------------
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
cmdTemplate = '''
|
|
46
|
+
set http_proxy=http://localhost:{0}
|
|
47
|
+
set https_proxy=http://localhost:{0}
|
|
48
|
+
set all_proxy=http://localhost:{0}
|
|
49
|
+
'''
|
|
50
|
+
|
|
51
|
+
powerShellTemplate = '''
|
|
52
|
+
$env:http_proxy="http://localhost:{0}"
|
|
53
|
+
$env:https_proxy="http://localhost:{0}"
|
|
54
|
+
$env:all_proxy="http://localhost:{0}"
|
|
55
|
+
'''
|
bcmd/tasks/time.py
CHANGED
|
@@ -1,81 +1,81 @@
|
|
|
1
|
-
import time
|
|
2
|
-
from datetime import datetime as Datetime
|
|
3
|
-
from datetime import timezone
|
|
4
|
-
from typing import Final
|
|
5
|
-
from zoneinfo import ZoneInfo
|
|
6
|
-
|
|
7
|
-
import typer
|
|
8
|
-
from beni import bcolor, btask
|
|
9
|
-
from beni.bfunc import syncCall, textToAry
|
|
10
|
-
from beni.btype import Null
|
|
11
|
-
|
|
12
|
-
app: Final = btask.app
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
@app.command('time')
|
|
16
|
-
@syncCall
|
|
17
|
-
async def showtime(
|
|
18
|
-
args: list[str] = typer.Argument(None),
|
|
19
|
-
):
|
|
20
|
-
'''
|
|
21
|
-
格式化时间戳\n
|
|
22
|
-
beni time\n
|
|
23
|
-
beni time 1632412740\n
|
|
24
|
-
beni time 1632412740.1234\n
|
|
25
|
-
beni time 2021-9-23\n
|
|
26
|
-
beni time 2021-9-23 09:47:00\n
|
|
27
|
-
'''
|
|
28
|
-
args = args or []
|
|
29
|
-
btask.assertTrue(len(args) <= 2, '参数过多')
|
|
30
|
-
value1: str | None = args[0] if len(args) >= 1 else None
|
|
31
|
-
value2: str | None = args[1] if len(args) >= 2 else None
|
|
32
|
-
timestamp: float = Null
|
|
33
|
-
if not value1:
|
|
34
|
-
timestamp = time.time()
|
|
35
|
-
else:
|
|
36
|
-
try:
|
|
37
|
-
timestamp = float(value1)
|
|
38
|
-
except:
|
|
39
|
-
try:
|
|
40
|
-
if value2:
|
|
41
|
-
timestamp = Datetime.strptime(f'{value1} {value2}', '%Y-%m-%d %H:%M:%S').timestamp()
|
|
42
|
-
else:
|
|
43
|
-
timestamp = Datetime.strptime(f'{value1}', '%Y-%m-%d').timestamp()
|
|
44
|
-
except:
|
|
45
|
-
pass
|
|
46
|
-
if not timestamp:
|
|
47
|
-
bcolor.printRed('参数无效\n')
|
|
48
|
-
bcolor.printRed('使用示例:')
|
|
49
|
-
msgAry = textToAry(str(showtime.__doc__))[1:]
|
|
50
|
-
bcolor.printRed('\n'.join(msgAry))
|
|
51
|
-
return
|
|
52
|
-
print()
|
|
53
|
-
bcolor.printMagenta(timestamp)
|
|
54
|
-
print()
|
|
55
|
-
# localtime = time.localtime(timestamp)
|
|
56
|
-
# tzname = time.tzname[(time.daylight and localtime.tm_isdst) and 1 or 0]
|
|
57
|
-
# bcolor.printx(time.strftime('%Y-%m-%d %H:%M:%S %z', localtime), tzname, colors=[Fore.YELLOW])
|
|
58
|
-
# print()
|
|
59
|
-
datetime_utc = Datetime.fromtimestamp(timestamp, tz=timezone.utc)
|
|
60
|
-
tzname_list = [
|
|
61
|
-
'Australia/Sydney',
|
|
62
|
-
'Asia/Tokyo',
|
|
63
|
-
'Asia/Shanghai',
|
|
64
|
-
'Asia/Kolkata',
|
|
65
|
-
'Africa/Cairo',
|
|
66
|
-
'Europe/London',
|
|
67
|
-
'America/Sao_Paulo',
|
|
68
|
-
'America/New_York',
|
|
69
|
-
'America/Chicago',
|
|
70
|
-
'America/Los_Angeles',
|
|
71
|
-
]
|
|
72
|
-
for tzname in tzname_list:
|
|
73
|
-
datetime_tz = datetime_utc.astimezone(ZoneInfo(tzname))
|
|
74
|
-
dstStr = ''
|
|
75
|
-
dst = datetime_tz.dst()
|
|
76
|
-
if dst:
|
|
77
|
-
dstStr = f'(DST+{dst})'
|
|
78
|
-
if tzname == 'Asia/Shanghai':
|
|
79
|
-
bcolor.printYellow(f'{datetime_tz} {tzname} {dstStr}')
|
|
80
|
-
else:
|
|
81
|
-
print(f'{datetime_tz} {tzname} {dstStr}')
|
|
1
|
+
import time
|
|
2
|
+
from datetime import datetime as Datetime
|
|
3
|
+
from datetime import timezone
|
|
4
|
+
from typing import Final
|
|
5
|
+
from zoneinfo import ZoneInfo
|
|
6
|
+
|
|
7
|
+
import typer
|
|
8
|
+
from beni import bcolor, btask
|
|
9
|
+
from beni.bfunc import syncCall, textToAry
|
|
10
|
+
from beni.btype import Null
|
|
11
|
+
|
|
12
|
+
app: Final = btask.app
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@app.command('time')
|
|
16
|
+
@syncCall
|
|
17
|
+
async def showtime(
|
|
18
|
+
args: list[str] = typer.Argument(None),
|
|
19
|
+
):
|
|
20
|
+
'''
|
|
21
|
+
格式化时间戳\n
|
|
22
|
+
beni time\n
|
|
23
|
+
beni time 1632412740\n
|
|
24
|
+
beni time 1632412740.1234\n
|
|
25
|
+
beni time 2021-9-23\n
|
|
26
|
+
beni time 2021-9-23 09:47:00\n
|
|
27
|
+
'''
|
|
28
|
+
args = args or []
|
|
29
|
+
btask.assertTrue(len(args) <= 2, '参数过多')
|
|
30
|
+
value1: str | None = args[0] if len(args) >= 1 else None
|
|
31
|
+
value2: str | None = args[1] if len(args) >= 2 else None
|
|
32
|
+
timestamp: float = Null
|
|
33
|
+
if not value1:
|
|
34
|
+
timestamp = time.time()
|
|
35
|
+
else:
|
|
36
|
+
try:
|
|
37
|
+
timestamp = float(value1)
|
|
38
|
+
except:
|
|
39
|
+
try:
|
|
40
|
+
if value2:
|
|
41
|
+
timestamp = Datetime.strptime(f'{value1} {value2}', '%Y-%m-%d %H:%M:%S').timestamp()
|
|
42
|
+
else:
|
|
43
|
+
timestamp = Datetime.strptime(f'{value1}', '%Y-%m-%d').timestamp()
|
|
44
|
+
except:
|
|
45
|
+
pass
|
|
46
|
+
if not timestamp:
|
|
47
|
+
bcolor.printRed('参数无效\n')
|
|
48
|
+
bcolor.printRed('使用示例:')
|
|
49
|
+
msgAry = textToAry(str(showtime.__doc__))[1:]
|
|
50
|
+
bcolor.printRed('\n'.join(msgAry))
|
|
51
|
+
return
|
|
52
|
+
print()
|
|
53
|
+
bcolor.printMagenta(timestamp)
|
|
54
|
+
print()
|
|
55
|
+
# localtime = time.localtime(timestamp)
|
|
56
|
+
# tzname = time.tzname[(time.daylight and localtime.tm_isdst) and 1 or 0]
|
|
57
|
+
# bcolor.printx(time.strftime('%Y-%m-%d %H:%M:%S %z', localtime), tzname, colors=[Fore.YELLOW])
|
|
58
|
+
# print()
|
|
59
|
+
datetime_utc = Datetime.fromtimestamp(timestamp, tz=timezone.utc)
|
|
60
|
+
tzname_list = [
|
|
61
|
+
'Australia/Sydney',
|
|
62
|
+
'Asia/Tokyo',
|
|
63
|
+
'Asia/Shanghai',
|
|
64
|
+
'Asia/Kolkata',
|
|
65
|
+
'Africa/Cairo',
|
|
66
|
+
'Europe/London',
|
|
67
|
+
'America/Sao_Paulo',
|
|
68
|
+
'America/New_York',
|
|
69
|
+
'America/Chicago',
|
|
70
|
+
'America/Los_Angeles',
|
|
71
|
+
]
|
|
72
|
+
for tzname in tzname_list:
|
|
73
|
+
datetime_tz = datetime_utc.astimezone(ZoneInfo(tzname))
|
|
74
|
+
dstStr = ''
|
|
75
|
+
dst = datetime_tz.dst()
|
|
76
|
+
if dst:
|
|
77
|
+
dstStr = f'(DST+{dst})'
|
|
78
|
+
if tzname == 'Asia/Shanghai':
|
|
79
|
+
bcolor.printYellow(f'{datetime_tz} {tzname} {dstStr}')
|
|
80
|
+
else:
|
|
81
|
+
print(f'{datetime_tz} {tzname} {dstStr}')
|