更新list命令

This commit is contained in:
root 2024-04-02 00:59:54 +08:00
parent b49781cbb5
commit 18981da857
2 changed files with 24 additions and 8 deletions

View File

@ -2,6 +2,7 @@ import click
from . import update as updates from . import update as updates
from . import util from . import util
from moyanlib import jsons from moyanlib import jsons
from rich.table import Table
from . import source as sou from . import source as sou
from . import install as installs from . import install as installs
from . import search as searchs from . import search as searchs
@ -33,7 +34,19 @@ def install(*args,**kwargs):
@cli.command(name='list',short_help='List all Python packages') @cli.command(name='list',short_help='List all Python packages')
def listp(): def listp():
util.runpip('list') table = Table(show_header=True)
table.add_column('Name')
table.add_column('Version')
listv = util.runpip('freeze',out=False)
for line in iter(listv.stdout.readline, b''):
# 在这里你可以对每一行输出进行处理
line = line.decode('utf-8').strip() # 将字节转换为字符串并去除换行符
if '==' not in line or line[0]=='#':
continue
lineList = line.split('==')
table.add_row(lineList[0],lineList[1])
util.console.print(table)
@cli.command() @cli.command()
@click.argument('name') @click.argument('name')

View File

@ -48,7 +48,7 @@ def loadIndex():
if len(IndexList) == 0: if len(IndexList) == 0:
raise FileNotFoundError('No index. Run "pmpt update" first to update the index') raise FileNotFoundError('No index. Run "pmpt update" first to update the index')
def runpip(command,other=None,dbg=False) -> Popen: def runpip(command,other=None,dbg=False,out=True) -> Popen:
''' '''
运行pip 运行pip
''' '''
@ -62,11 +62,14 @@ def runpip(command,other=None,dbg=False) -> Popen:
console.print('Command to be run:',' '.join(Command)) console.print('Command to be run:',' '.join(Command))
runClass = Popen(Command,stdout=subprocess.PIPE,stderr=subprocess.PIPE) runClass = Popen(Command,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
for line in iter(runClass.stdout.readline, b''): if out:
# 在这里你可以对每一行输出进行处理 for line in iter(runClass.stdout.readline, b''):
line = line.decode('utf-8').strip() # 将字节转换为字符串并去除换行符 # 在这里你可以对每一行输出进行处理
console.print(line) line = line.decode('utf-8').strip() # 将字节转换为字符串并去除换行符
runClass.communicate() console.print(line)
runClass.communicate()
else:
runClass.wait()
return runClass return runClass