bcmd 0.0.25__tar.gz → 0.0.27__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.

Potentially problematic release.


This version of bcmd might be problematic. Click here for more details.

@@ -1,9 +1,8 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: bcmd
3
- Version: 0.0.25
3
+ Version: 0.0.27
4
4
  Summary: Commands for Beni
5
- Author: Beni Mang
6
- Author-email: benimang@126.com
5
+ Author-email: Beni Mang <benimang@126.com>
7
6
  Maintainer-email: Beni Mang <benimang@126.com>
8
7
  Keywords: benimang,beni,bcmd
9
8
  Requires-Python: >=3.10
@@ -0,0 +1,94 @@
1
+ import os
2
+ from datetime import datetime
3
+ from pathlib import Path
4
+ from typing import Final
5
+
6
+ import typer
7
+ from beni import bcolor, bfile, bfunc, bstore, btable, btask
8
+ from beni.bqiniu import QiniuBucket
9
+
10
+ app: Final = btask.newSubApp('bin 工具')
11
+
12
+ _PREFIX = 'bin/'
13
+
14
+
15
+ @app.command()
16
+ @bfunc.syncCall
17
+ async def init(
18
+ ak: str = typer.Argument(..., help="七牛云账号AK"),
19
+ sk: str = typer.Argument(..., help="七牛云账号SK"),
20
+ ):
21
+ '初始化七牛云服务'
22
+ await bstore.set(__file__, (ak, sk))
23
+ bcolor.printGreen('OK')
24
+
25
+
26
+ @app.command()
27
+ @bfunc.syncCall
28
+ async def clear():
29
+ '清空 token'
30
+ await bstore.clear(__file__)
31
+ bcolor.printGreen('OK')
32
+
33
+
34
+ @app.command()
35
+ @bfunc.syncCall
36
+ async def download(
37
+ names: str = typer.Argument(None, help="如果有多个使用,分割"),
38
+ file: Path = typer.Option(None, '--file', '-f', help="文件形式指定参数,行为单位"),
39
+ output: Path = typer.Option(None, '--output', '-o', help="本地保存路径"),
40
+ ):
41
+ '从七牛云下载执行文件'
42
+ bucket = await _getBucket()
43
+ if bucket:
44
+ if output is None:
45
+ output = Path(os.curdir)
46
+ output = output.resolve()
47
+ targetList: list[str] = []
48
+ if names:
49
+ targetList.extend(names.split(','))
50
+ if file:
51
+ content = await bfile.readText(Path(file))
52
+ targetList.extend(content.split('\n'))
53
+ targetList = [x.strip() for x in targetList]
54
+ targetList = [x for x in targetList if x]
55
+ for target in targetList:
56
+ binFile = output / target
57
+ if binFile.exists():
58
+ bcolor.printYellow(f'已存在 {binFile}')
59
+ else:
60
+ key = f'bin/{target}.zip'
61
+ await bucket.downloadPrivateFileUnzip(key, output)
62
+ bcolor.printGreen(f'added {binFile}')
63
+
64
+
65
+ @app.command('list')
66
+ @bfunc.syncCall
67
+ async def getList():
68
+ '列出可下载的文件'
69
+ bucket = await _getBucket()
70
+ if bucket:
71
+ datas = (await bucket.getFileList(_PREFIX, limit=1000))[0]
72
+ datas = [x for x in datas if x.key != _PREFIX and x.key.endswith('.zip')]
73
+ print(
74
+ btable.get(
75
+ datas,
76
+ fields=[
77
+ ('名称<', lambda x: x.key[len(_PREFIX):-len('.zip')]),
78
+ ('时间<', lambda x: datetime.fromtimestamp(x.time / 10000000).strftime('%Y-%m-%d %H:%M:%S')),
79
+ ]
80
+ )
81
+ )
82
+
83
+
84
+ async def _getBucket():
85
+ try:
86
+ (ak, sk) = await bstore.get(__file__)
87
+ return QiniuBucket(
88
+ 'pytask',
89
+ 'http://qiniu-cdn.pytask.com',
90
+ ak,
91
+ sk,
92
+ )
93
+ except:
94
+ bcolor.printRed('请先执行 beni bin init 进行初始化')
@@ -11,13 +11,13 @@ app: Final = btask.newSubApp('lib 工具')
11
11
  @app.command()
12
12
  @bfunc.syncCall
13
13
  async def version(
14
- workspacePath: Path = typer.Argument(None, help='workspace 路径'),
15
- disabledCommit: bool = typer.Option(False, '--disabled-commit', '-d', help='是否提交git'),
14
+ workspace_path: Path = typer.Argument(None, help='workspace 路径'),
15
+ disabled_commit: bool = typer.Option(False, '--disabled-commit', '-d', help='是否提交git'),
16
16
  ):
17
17
  '修改 pyproject.toml 版本号'
18
- if workspacePath is None:
19
- workspacePath = Path.cwd()
20
- file = workspacePath / 'pyproject.toml'
18
+ if workspace_path is None:
19
+ workspace_path = Path.cwd()
20
+ file = workspace_path / 'pyproject.toml'
21
21
  assert file.is_file(), f'文件不存在 {file}'
22
22
  data = await bfile.readToml(file)
23
23
  version = data['project']['version']
@@ -32,7 +32,7 @@ async def version(
32
32
  else:
33
33
  raise Exception('版本号修改失败,先检查文件中定义的版本号格式是否正常')
34
34
  await bfile.writeText(file, content)
35
- if not disabledCommit:
35
+ if not disabled_commit:
36
36
  os.system(
37
37
  rf'TortoiseGitProc.exe /command:commit /path:{file} /logmsg:"更新版本号 {newVersion}"'
38
38
  )
@@ -41,28 +41,28 @@ async def version(
41
41
  @app.command()
42
42
  @bfunc.syncCall
43
43
  async def publish(
44
- workspacePath: Path = typer.Argument(None, help='workspace 路径'),
45
- keepBuildFiles: bool = typer.Option(False, '--keep-build-files', '-k', help='是否保留构建文件'),
44
+ workspace_path: Path = typer.Argument(None, help='workspace 路径'),
45
+ keep_build_files: bool = typer.Option(False, '--keep-build-files', '-k', help='是否保留构建文件'),
46
46
  ):
47
47
  '发布项目'
48
- if workspacePath is None:
49
- workspacePath = Path.cwd()
50
- workspacePath = workspacePath.resolve()
48
+ if workspace_path is None:
49
+ workspace_path = Path.cwd()
50
+ workspace_path = workspace_path.resolve()
51
51
 
52
52
  async def removeUnusedPath():
53
- await bpath.remove(workspacePath / 'dist')
54
- paths = await bpath.listDir(workspacePath)
53
+ await bpath.remove(workspace_path / 'dist')
54
+ paths = await bpath.listDir(workspace_path)
55
55
  for x in paths:
56
56
  if x.name.endswith('.egg-info'):
57
57
  await bpath.remove(x)
58
58
 
59
59
  try:
60
- async with bpath.usePath(workspacePath):
60
+ async with bpath.usePath(workspace_path):
61
61
  await removeUnusedPath()
62
- scriptPath = (workspacePath / './../venv/Scripts').resolve()
62
+ scriptPath = (workspace_path / './../venv/Scripts').resolve()
63
63
  os.system(f'{scriptPath / "pip.exe"} install setuptools -U -i https://mirrors.aliyun.com/pypi/simple')
64
64
  os.system(f'{scriptPath / "python.exe"} -m build')
65
65
  os.system(f'{scriptPath / "twine.exe"} upload dist/* -u benimang')
66
66
  finally:
67
- if not keepBuildFiles:
67
+ if not keep_build_files:
68
68
  await removeUnusedPath()
@@ -15,52 +15,52 @@ app: Final = btask.newSubApp('BTask 工具')
15
15
  @app.command()
16
16
  @bfunc.syncCall
17
17
  async def create(
18
- projectPath: Path = typer.Argument(None, help="项目路径"),
18
+ project_path: Path = typer.Argument(None, help="项目路径"),
19
19
  ):
20
20
  '创建 BTask 项目'
21
- if projectPath is None:
22
- projectPath = Path.cwd()
23
- if projectPath.exists():
24
- await binput.confirm(f'项目路径 {projectPath} 已存在,是否覆盖?')
25
- await bfile.makeFiles(_files, projectPath)
26
- init(projectPath)
21
+ if project_path is None:
22
+ project_path = Path.cwd()
23
+ if project_path.exists():
24
+ await binput.confirm(f'项目路径 {project_path} 已存在,是否覆盖?')
25
+ await bfile.makeFiles(_files, project_path)
26
+ init(project_path)
27
27
 
28
28
 
29
29
  @app.command()
30
30
  @bfunc.syncCall
31
31
  async def init(
32
- projectPath: Path = typer.Argument(None, help="项目路径"),
32
+ project_path: Path = typer.Argument(None, help="项目路径"),
33
33
  ):
34
34
  '初始化 BTask 项目,包括 venv 和 bin 操作'
35
- if projectPath is None:
36
- projectPath = Path.cwd()
35
+ if project_path is None:
36
+ project_path = Path.cwd()
37
37
  venv.venv(
38
38
  packages=Null,
39
- path=projectPath,
40
- disabledMirror=False,
39
+ path=project_path,
40
+ disabled_mirror=False,
41
41
  quiet=True,
42
42
  )
43
43
  bin.download(
44
44
  names=Null,
45
- file=projectPath / 'bin.list',
46
- output=projectPath / 'bin',
45
+ file=project_path / 'bin.list',
46
+ output=project_path / 'bin',
47
47
  )
48
48
 
49
49
 
50
50
  @app.command()
51
51
  @bfunc.syncCall
52
52
  async def export(
53
- projectPath: Path = typer.Argument(None, help="项目路径"),
53
+ project_path: Path = typer.Argument(None, help="项目路径"),
54
54
  ):
55
55
  '导出文件内容到剪贴板'
56
- if projectPath is None:
57
- projectPath = Path.cwd()
56
+ if project_path is None:
57
+ project_path = Path.cwd()
58
58
  ignores = [
59
- projectPath / 'bin',
60
- projectPath / 'venv',
61
- projectPath / 'venv.lock',
59
+ project_path / 'bin',
60
+ project_path / 'venv',
61
+ project_path / 'venv.lock',
62
62
  ]
63
- files = await bpath.listFile(projectPath, True)
63
+ files = await bpath.listFile(project_path, True)
64
64
  files = [x for x in files if '__pycache__' not in x.parts]
65
65
  contents: list[str] = []
66
66
  for file in files:
@@ -68,7 +68,7 @@ async def export(
68
68
  if file.is_relative_to(ignore):
69
69
  break
70
70
  else:
71
- contents.append(f'>>> {str(file.relative_to(projectPath)).replace(os.path.sep, "/")}\n{await bfile.readText(file)}')
71
+ contents.append(f'>>> {str(file.relative_to(project_path)).replace(os.path.sep, "/")}\n{await bfile.readText(file)}')
72
72
  contents.sort()
73
73
  content = '_files = \'\'\'\n' + '\n\n\n'.join(contents) + '\n\'\'\''
74
74
  pyperclip.copy(content)
@@ -78,18 +78,22 @@ async def export(
78
78
  @app.command()
79
79
  @bfunc.syncCall
80
80
  async def tidy(
81
- tasksPath: Path = typer.Argument(None, help="tasks 路径"),
81
+ tasks_path: Path = typer.Argument(None, help="tasks 路径"),
82
82
  ):
83
83
  '整理 tasks 文件'
84
- files = await bpath.listFile(tasksPath)
84
+ initFile = tasks_path / '__init__.py'
85
+ assert initFile.is_file(), f'文件不存在 {initFile}'
86
+ files = await bpath.listFile(tasks_path)
85
87
  files = [x for x in files if not x.name.startswith('_')]
86
88
  contents = [f'from . import {x.stem}' for x in files]
87
89
  contents.insert(0, '# type: ignore')
88
90
  contents.append('')
91
+ content = '\n'.join(contents)
89
92
  await bfile.writeText(
90
- tasksPath / '__init__.py',
91
- '\n'.join(contents),
93
+ initFile,
94
+ content,
92
95
  )
96
+ print(content)
93
97
 
94
98
 
95
99
  _files = '''
@@ -203,70 +207,61 @@ venv/
203
207
  ],
204
208
  },
205
209
  {
206
- "label": "update version",
210
+ "label": "tasks tidy",
207
211
  "type": "shell",
208
212
  "problemMatcher": [],
209
213
  "command": "beni",
210
214
  "args": [
211
- "lib",
212
- "version",
213
- "${workspaceFolder}"
215
+ "task",
216
+ "tidy",
217
+ "${workspaceFolder}/tasks"
214
218
  ],
215
219
  },
216
220
  ],
217
221
  }
218
222
 
219
223
 
220
- >>> src/dev.py
221
- import main
222
- from beni import btask
223
-
224
- main.init()
225
-
226
- btask.dev('sub.haha')
227
-
228
-
229
224
  >>> src/main.py
230
- from beni import btask, bpath
231
-
232
-
233
- def init():
234
- btask.options.tasksPath = bpath.get(__file__, '../tasks')
235
- btask.options.lock = 'xxxxxx'
225
+ import asyncio
236
226
 
227
+ from beni import btask
237
228
 
238
- def run():
239
- init()
240
- btask.main()
229
+ from tasks import *
241
230
 
231
+ btask.options.lock = 'bcmd'
232
+ asyncio.run(btask.main())
242
233
 
243
- if __name__ == '__main__':
244
- run()
245
234
 
246
235
 
247
236
  >>> src/tasks/__init__.py
237
+ # type: ignore
238
+ from . import hello
239
+ from . import sub
248
240
 
249
241
 
250
242
 
251
243
  >>> src/tasks/hello.py
244
+ from typing import Final
245
+
252
246
  from beni import bfunc, btask
253
247
 
248
+ app: Final = btask.app
249
+
254
250
 
255
- @btask.app.command()
251
+ @app.command()
256
252
  @bfunc.syncCall
257
253
  async def hello():
258
254
  '打印 hello'
259
255
  print('hello')
260
256
 
261
257
 
258
+
262
259
  >>> src/tasks/sub.py
263
260
  from typing import Final
264
261
 
265
- import typer
266
- from beni import bfunc
267
-
262
+ from beni import bfunc, btask
268
263
 
269
- app: Final = typer.Typer(help='子工具集')
264
+ app: Final = btask.newSubApp('子工具集')
270
265
 
271
266
 
272
267
  @app.command()
@@ -283,13 +278,14 @@ async def bye():
283
278
  print('bye')
284
279
 
285
280
 
281
+
286
282
  >>> venv.list
287
283
  aioconsole
288
284
  aiofiles
289
285
  aiohttp
290
286
  aiosqlite
291
287
  autopep8
292
- benimang==0.4.10
288
+ benimang==0.4.13
293
289
  nest-asyncio
294
290
  orjson
295
291
  portalocker
@@ -300,4 +296,4 @@ pyinstaller
300
296
  pyyaml
301
297
  qiniu
302
298
  typer
303
- '''
299
+ '''
@@ -13,14 +13,14 @@ app: Final = btask.app
13
13
  async def venv(
14
14
  packages: list[str] = typer.Argument(None),
15
15
  path: Path = typer.Option(None, '--path', '-p', help='指定路径,默认当前目录'),
16
- disabledMirror: bool = typer.Option(False, '--disabled-mirror', '-d', help='是否禁用镜像'),
16
+ disabled_mirror: bool = typer.Option(False, '--disabled-mirror', '-d', help='是否禁用镜像'),
17
17
  quiet: bool = typer.Option(False, '--quiet', '-q', help='是否安静模式'),
18
18
  ):
19
19
  'python 虚拟环境配置'
20
20
  packages = packages or []
21
21
  async with bpath.useTempFile() as tempFile:
22
22
  pipIniFile = bpath.user('pip/pip.ini')
23
- if disabledMirror and pipIniFile.is_file():
23
+ if disabled_mirror and pipIniFile.is_file():
24
24
  await bpath.move(pipIniFile, tempFile)
25
25
  try:
26
26
  path = path or Path(os.getcwd())
@@ -1,9 +1,8 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: bcmd
3
- Version: 0.0.25
3
+ Version: 0.0.27
4
4
  Summary: Commands for Beni
5
- Author: Beni Mang
6
- Author-email: benimang@126.com
5
+ Author-email: Beni Mang <benimang@126.com>
7
6
  Maintainer-email: Beni Mang <benimang@126.com>
8
7
  Keywords: benimang,beni,bcmd
9
8
  Requires-Python: >=3.10
@@ -2,7 +2,7 @@ aioconsole
2
2
  aiofiles
3
3
  aiohttp
4
4
  autopep8
5
- benimang>=0.4.13
5
+ benimang<0.5
6
6
  build
7
7
  colorama
8
8
  nest-asyncio
@@ -3,24 +3,19 @@
3
3
 
4
4
  [project]
5
5
  name = 'bcmd'
6
- version = '0.0.25'
6
+ version = '0.0.27'
7
7
  description = 'Commands for Beni'
8
8
  requires-python = '>=3.10'
9
9
  keywords = ['benimang', 'beni', 'bcmd']
10
- authors = [
11
- {email = 'benimang@126.com'},
12
- {name = 'Beni Mang'},
13
- ]
14
- maintainers = [
15
- {name = 'Beni Mang', email = 'benimang@126.com'},
16
- ]
10
+ authors = [{ name = 'Beni Mang', email = 'benimang@126.com' }]
11
+ maintainers = [{ name = 'Beni Mang', email = 'benimang@126.com' }]
17
12
 
18
13
  dependencies = [
19
14
  'aioconsole',
20
15
  'aiofiles',
21
16
  'aiohttp',
22
17
  'autopep8',
23
- 'benimang>=0.4.13',
18
+ 'benimang<0.5',
24
19
  'build',
25
20
  'colorama',
26
21
  'nest-asyncio',
@@ -35,4 +30,4 @@ dependencies = [
35
30
  ]
36
31
 
37
32
  [project.scripts]
38
- beni = 'bcmd.main:run'
33
+ beni = 'bcmd.main:run'
@@ -1,56 +0,0 @@
1
- import os
2
- from pathlib import Path
3
- from typing import Final
4
-
5
- import typer
6
- from beni import bcolor, bfile, bfunc, bstore, btask
7
- from beni.bqiniu import QiniuBucket
8
-
9
-
10
- app: Final = btask.newSubApp('bin 工具')
11
-
12
-
13
- @app.command()
14
- @bfunc.syncCall
15
- async def init(
16
- ak: str = typer.Argument(..., help="七牛云账号AK"),
17
- sk: str = typer.Argument(..., help="七牛云账号SK"),
18
- ):
19
- '初始化七牛云服务'
20
- await bstore.set(__file__, (ak, sk))
21
-
22
-
23
- @app.command()
24
- @bfunc.syncCall
25
- async def download(
26
- names: str = typer.Argument(None, help="如果有多个使用,分割"),
27
- file: Path = typer.Option(None, '--file', '-f', help="文件形式指定参数,行为单位"),
28
- output: Path = typer.Option(None, '--output', '-o', help="本地保存路径"),
29
- ):
30
- '从七牛云下载执行文件'
31
- try:
32
- (ak, sk) = await bstore.get(__file__)
33
- except:
34
- return bcolor.printRed('请先执行 beni bin init 进行初始化')
35
- bucketName = 'pytask'
36
- bucketUrl = 'http://qiniu-cdn.pytask.com'
37
- if output is None:
38
- output = Path(os.curdir)
39
- output = output.resolve()
40
- bucket = QiniuBucket(bucketName, bucketUrl, ak, sk)
41
- targetList: list[str] = []
42
- if names:
43
- targetList.extend(names.split(','))
44
- if file:
45
- content = await bfile.readText(Path(file))
46
- targetList.extend(content.split('\n'))
47
- targetList = [x.strip() for x in targetList]
48
- targetList = [x for x in targetList if x]
49
- for target in targetList:
50
- binFile = output / target
51
- if binFile.exists():
52
- bcolor.printYellow(f'已存在 {binFile}')
53
- else:
54
- key = f'bin/{target}.zip'
55
- await bucket.downloadPrivateFileUnzip(key, output)
56
- bcolor.printGreen(f'added {binFile}')
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes