bcmd 0.6.4__py3-none-any.whl → 0.6.6__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.

bcmdx/tasks/time.py DELETED
@@ -1,81 +0,0 @@
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}')
bcmdx/tasks/upgrade.py DELETED
@@ -1,22 +0,0 @@
1
- from typing import Final
2
-
3
- import pyperclip
4
- import typer
5
- from beni import bcolor, btask
6
- from beni.bfunc import syncCall
7
-
8
- app: Final = btask.app
9
-
10
-
11
- @app.command()
12
- @syncCall
13
- async def upgrade(
14
- name: str = typer.Argument('bcmdx', help='要更新的包名'),
15
- ):
16
- '使用 pipx 官方源更新指定包到最新版本'
17
-
18
- cmd = f'pipx upgrade {name} -i https://pypi.org/simple'
19
- pyperclip.copy(cmd + '\n')
20
- bcolor.printGreen(cmd)
21
- bcolor.printGreen('已复制到剪贴板(需要手动执行)')
22
- bcolor.printGreen('OK')
bcmdx/tasks/wasabi.py DELETED
@@ -1,94 +0,0 @@
1
- import getpass
2
- import stat
3
- from pathlib import Path
4
- from typing import Final
5
-
6
- import typer
7
- from beni import bcolor, bcrypto, bfile, bpath, btask, bzip
8
- from beni.bfunc import shuffleSequence, syncCall
9
- from beni.binput import genPassword
10
-
11
- app: Final = btask.newSubApp('Wasabi 工具')
12
-
13
- SEP = f'{chr(852)}{chr(322)}{chr(470)}'.encode()
14
- MAX_ENCRYPT_SIZE = 199 * 1024
15
-
16
-
17
- @app.command()
18
- @syncCall
19
- async def unzip(
20
- target: Path = typer.Argument(Path.cwd(), help='加密文件'),
21
- password: str = typer.Option('', '--password', '-p', help='密码'),
22
- ):
23
- '解压缩加密文件成目录'
24
- assert target.is_file(), f'不是文件 {target}'
25
- password = password or getpass.getpass('请输入密码: ')
26
- with bpath.useTempFile() as tempFile:
27
- data = await bfile.readBytes(target)
28
- if SEP not in data:
29
- data = bcrypto.decrypt(data, password)
30
- else:
31
- partA, partB = data.split(SEP)
32
- partA = bcrypto.decrypt(partA, password)
33
- data = partA + partB
34
- data = shuffleSequence(data)
35
- await bfile.writeBytes(tempFile, data)
36
- tempPath = target.with_suffix('.tmp')
37
- await bzip.sevenUnzip(tempFile, tempPath)
38
-
39
- # 调整文件权限,完全擦除
40
- target.chmod(stat.S_IWRITE)
41
- await bpath.removeSecure(target)
42
-
43
- bpath.move(tempPath, target)
44
- bcolor.printGreen('OK')
45
-
46
-
47
- @app.command()
48
- @syncCall
49
- async def zip(
50
- target: Path = typer.Argument(Path.cwd(), help='输出目录'),
51
- password: str = typer.Option('', '--password', '-p', help='密码'),
52
- ):
53
- '将目录压缩成加密文件'
54
- target = target.absolute()
55
- assert target.is_dir(), f'不是目录 {target}'
56
- password = password or genPassword()
57
- with bpath.useTempFile() as tempFile:
58
- await bzip.sevenZipFolder(tempFile, target)
59
- data = await bfile.readBytes(tempFile)
60
- bpath.remove(tempFile) # 为了安全所以立即删除
61
- data = shuffleSequence(data)
62
- if len(data) < MAX_ENCRYPT_SIZE:
63
- data = bcrypto.encrypt(data, password)
64
- else:
65
- partA, partB = data[:MAX_ENCRYPT_SIZE], data[MAX_ENCRYPT_SIZE:]
66
- partA = bcrypto.encrypt(partA, password)
67
- data = partA + SEP + partB
68
- tempZipFile = target.with_suffix('.tmp')
69
- await bfile.writeBytes(tempZipFile, data)
70
-
71
- # 调整目录权限,完全擦除
72
- target.chmod(stat.S_IWRITE)
73
- for file in target.glob('**/*'):
74
- file.chmod(stat.S_IWRITE)
75
- await bpath.removeSecure(target)
76
-
77
- bpath.move(tempZipFile, target)
78
-
79
- bcolor.printGreen('OK')
80
-
81
-
82
- @app.command()
83
- @syncCall
84
- async def change_pass(
85
- file: Path = typer.Argument(Path.cwd(), help='加密文件'),
86
- password: str = typer.Option('', '--password', '-p', help='密码'),
87
- new_password: str = typer.Option('', '--new-password', '-n', help='新密码'),
88
- ):
89
- with bpath.useTempPath() as tempPath:
90
- target = tempPath / file.name
91
- bpath.copy(file, target)
92
- unzip(target, password)
93
- zip(target, new_password)
94
- bpath.copy(target, file)
File without changes
File without changes