添加日志
This commit is contained in:
parent
18981da857
commit
25a651c1e8
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -2,6 +2,7 @@ build/
|
||||||
dist/
|
dist/
|
||||||
|
|
||||||
pmpt.egg-info/
|
pmpt.egg-info/
|
||||||
*.tar.gz
|
*.tar.g
|
||||||
*.pyc
|
*.pyc
|
||||||
|
*.whl
|
||||||
__pycache__/
|
__pycache__/
|
|
@ -4,6 +4,7 @@ from . import util
|
||||||
from moyanlib import jsons
|
from moyanlib import jsons
|
||||||
from rich.table import Table
|
from rich.table import Table
|
||||||
from . import source as sou
|
from . import source as sou
|
||||||
|
from . import environment as environ
|
||||||
from . import install as installs
|
from . import install as installs
|
||||||
from . import search as searchs
|
from . import search as searchs
|
||||||
|
|
||||||
|
@ -12,6 +13,7 @@ def cli():
|
||||||
try:
|
try:
|
||||||
import pip
|
import pip
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
util.logger.critical('没有pip')
|
||||||
util.console.print('❌ [red]pip module not found![/red]')
|
util.console.print('❌ [red]pip module not found![/red]')
|
||||||
exit(1)
|
exit(1)
|
||||||
util.init() # 初始化
|
util.init() # 初始化
|
||||||
|
@ -92,5 +94,9 @@ def removes(*args,**kwargs):
|
||||||
def modifys(*args,**kwargs):
|
def modifys(*args,**kwargs):
|
||||||
sou.modify(*args,**kwargs)
|
sou.modify(*args,**kwargs)
|
||||||
|
|
||||||
|
@cli.command()
|
||||||
|
def version():
|
||||||
|
environ.main()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
cli()
|
cli()
|
|
@ -1,5 +1,7 @@
|
||||||
import subprocess
|
import subprocess
|
||||||
import re
|
import re
|
||||||
|
from . import util
|
||||||
|
import moyanlib
|
||||||
|
|
||||||
def get_version(command):
|
def get_version(command):
|
||||||
try:
|
try:
|
||||||
|
@ -10,9 +12,9 @@ def get_version(command):
|
||||||
if version_match:
|
if version_match:
|
||||||
return version_match.group(1)
|
return version_match.group(1)
|
||||||
else:
|
else:
|
||||||
return False
|
return '[red]False[/red]'
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
return False
|
return '[red]False[/red]'
|
||||||
|
|
||||||
def getGCCver():
|
def getGCCver():
|
||||||
# 检查是否能执行 gcc 命令
|
# 检查是否能执行 gcc 命令
|
||||||
|
@ -33,9 +35,18 @@ def getRustVer():
|
||||||
rustVer = stdout.decode().split(' ')[1]
|
rustVer = stdout.decode().split(' ')[1]
|
||||||
return rustVer
|
return rustVer
|
||||||
else:
|
else:
|
||||||
return False
|
return '[red]False[/red]'
|
||||||
|
|
||||||
print("GCC 版本:", getGCCver())
|
def getPIPver():
|
||||||
print("Clang 版本:", getClangVer())
|
return get_version('pip -V')
|
||||||
print("MSVC 版本:", getMSVCver())
|
def main():
|
||||||
print('Rust版本:',getRustVer())
|
info = moyanlib.getInfo()
|
||||||
|
printText = f'''[white]PMPT {util.__version__}[/white]
|
||||||
|
{info['OS']['Name']} {info['OS']['Version']}
|
||||||
|
Python Version: {info['Python']['Version']}
|
||||||
|
PIP Version: [green]{getPIPver()}[/green]
|
||||||
|
GCC Version: [green]{getGCCver()}[/green]
|
||||||
|
Clang Version: [green]{getClangVer()}[/green]
|
||||||
|
MSVC Version: [green]{getMSVCver()}[/green]
|
||||||
|
Rust Version: [green]{getRustVer()}[/green]'''
|
||||||
|
util.console.print(printText)
|
|
@ -1,11 +1,21 @@
|
||||||
from . import util
|
from . import util
|
||||||
|
import requests
|
||||||
from rich.table import Table
|
from rich.table import Table
|
||||||
|
from urllib import parse
|
||||||
|
|
||||||
def search(name):
|
def search(name):
|
||||||
util.loadIndex() #加载索引
|
util.loadIndex() #加载索引
|
||||||
for Index in util.IndexList:
|
for Index in util.IndexList:
|
||||||
dt = Index.packageList.get(name,None)
|
dt = Index.packageList.get(name,None)
|
||||||
if dt:
|
if dt:
|
||||||
|
try:
|
||||||
|
rurl = parse.urljoin(Index.IndexURL,name)
|
||||||
|
r = requests.get(rurl)
|
||||||
|
except:
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
if r.status_code != 200:
|
||||||
|
continue
|
||||||
return Index.IndexURL
|
return Index.IndexURL
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,6 +28,7 @@ def main(packlist,upgrade,reads,force_reinstall,ignore_requires_python,yes,comma
|
||||||
|
|
||||||
packsInfo = {}
|
packsInfo = {}
|
||||||
with console.status('🚀🔍 Searching for package information...') as status:
|
with console.status('🚀🔍 Searching for package information...') as status:
|
||||||
|
# 创建表格
|
||||||
table = Table(show_header=True,header_style='bold')
|
table = Table(show_header=True,header_style='bold')
|
||||||
table.add_column("Package Name", width=20,style='bold')
|
table.add_column("Package Name", width=20,style='bold')
|
||||||
table.add_column("Package Source", width=20,style='green')
|
table.add_column("Package Source", width=20,style='green')
|
||||||
|
|
|
@ -4,20 +4,26 @@ import os
|
||||||
from rich.table import Table
|
from rich.table import Table
|
||||||
from . import util
|
from . import util
|
||||||
|
|
||||||
def line_search(li, val):
|
def line_search(li, val,key):
|
||||||
|
# 线性搜索算法
|
||||||
n = 0
|
n = 0
|
||||||
for i in li:
|
for i in li:
|
||||||
print(i)
|
print(i)
|
||||||
if i['id'] == val:
|
if i[key] == val:
|
||||||
return i,n
|
return i,n
|
||||||
n += 1
|
n += 1
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def add(url,priority):
|
def add(url,priority):
|
||||||
sourceList = jsons.load(open(os.path.join(util.dirs.user_config_dir,'Source.json')))
|
'''
|
||||||
if url in sourceList:
|
添加源
|
||||||
|
'''
|
||||||
|
sourceList = jsons.load(open(os.path.join(util.dirs.user_config_dir,'Source.json'))) # 加载source源
|
||||||
|
|
||||||
|
if not line_search(sourceList,url,'url'): # 判断源是否存在
|
||||||
util.console.print('❌ [red]The source already exists[/red]')
|
util.console.print('❌ [red]The source already exists[/red]')
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
sourceList.append({
|
sourceList.append({
|
||||||
'url':url,
|
'url':url,
|
||||||
'id':str(uuid.uuid4())[:8],
|
'id':str(uuid.uuid4())[:8],
|
||||||
|
@ -28,12 +34,17 @@ def add(url,priority):
|
||||||
|
|
||||||
|
|
||||||
def lists():
|
def lists():
|
||||||
|
'''
|
||||||
|
列出所有源
|
||||||
|
'''
|
||||||
sourceList = jsons.load(open(os.path.join(util.dirs.user_config_dir,'Source.json')))
|
sourceList = jsons.load(open(os.path.join(util.dirs.user_config_dir,'Source.json')))
|
||||||
|
# 构建table
|
||||||
table = Table(show_header=True)
|
table = Table(show_header=True)
|
||||||
table.add_column("ID",width=6)
|
table.add_column("ID",width=6)
|
||||||
table.add_column('Priority',width=8)
|
table.add_column('Priority',width=8)
|
||||||
table.add_column('URL',width=25)
|
table.add_column('URL',width=25)
|
||||||
|
|
||||||
|
# 遍历source列表
|
||||||
for i in sourceList:
|
for i in sourceList:
|
||||||
table.add_row(
|
table.add_row(
|
||||||
i['id'],
|
i['id'],
|
||||||
|
@ -43,12 +54,15 @@ def lists():
|
||||||
util.console.print(table)
|
util.console.print(table)
|
||||||
|
|
||||||
def remove(ids,yes):
|
def remove(ids,yes):
|
||||||
|
'''
|
||||||
|
删除
|
||||||
|
'''
|
||||||
if not ids:
|
if not ids:
|
||||||
lists()
|
lists()
|
||||||
ids = util.console.input('Please enter the source sequence number to be deleted:')
|
ids = util.console.input('Please enter the source sequence number to be deleted:')
|
||||||
|
|
||||||
sourceList:list = jsons.load(open(os.path.join(util.dirs.user_config_dir,'Source.json')))
|
sourceList:list = jsons.load(open(os.path.join(util.dirs.user_config_dir,'Source.json')))
|
||||||
source,n = line_search(sourceList,ids)
|
source,n = line_search(sourceList,ids,'id')
|
||||||
|
|
||||||
if not source:
|
if not source:
|
||||||
util.console.print('❌ [red]The source for this ID does not exist[/red]')
|
util.console.print('❌ [red]The source for this ID does not exist[/red]')
|
||||||
|
@ -71,11 +85,18 @@ def remove(ids,yes):
|
||||||
jsons.dump(sourceList,open(os.path.join(util.dirs.user_config_dir,'Source.json'),'w'))
|
jsons.dump(sourceList,open(os.path.join(util.dirs.user_config_dir,'Source.json'),'w'))
|
||||||
|
|
||||||
def modify(ids,key,val):
|
def modify(ids,key,val):
|
||||||
|
'''
|
||||||
|
修改
|
||||||
|
'''
|
||||||
sourceList:list = jsons.load(open(os.path.join(util.dirs.user_config_dir,'Source.json')))
|
sourceList:list = jsons.load(open(os.path.join(util.dirs.user_config_dir,'Source.json')))
|
||||||
source,n = line_search(sourceList,ids)
|
source,n = line_search(sourceList,ids,'id')
|
||||||
|
|
||||||
if not source:
|
if not source:
|
||||||
util.console.print('❌ [red]The source for this ID does not exist[/red]')
|
util.console.print('❌ [red]The source for this ID does not exist[/red]')
|
||||||
|
|
||||||
if key not in ['url','priority']:
|
if key not in ['url','priority']:
|
||||||
util.console.print('❌ [red]The item is not allowed to be modified or does not exist.[/red]')
|
util.console.print('❌ [red]The item is not allowed to be modified or does not exist.[/red]')
|
||||||
|
|
||||||
sourceList[n][key] = val
|
sourceList[n][key] = val
|
||||||
|
|
||||||
jsons.dump(sourceList,open(os.path.join(util.dirs.user_config_dir,'Source.json'),'w'))
|
jsons.dump(sourceList,open(os.path.join(util.dirs.user_config_dir,'Source.json'),'w'))
|
39
pmpt/util.py
39
pmpt/util.py
|
@ -2,10 +2,9 @@
|
||||||
import os
|
import os
|
||||||
from subprocess import Popen
|
from subprocess import Popen
|
||||||
import sys
|
import sys
|
||||||
import pathlib
|
|
||||||
import dill
|
import dill
|
||||||
from rich.console import Console
|
from rich.console import Console
|
||||||
import time
|
from loguru import logger
|
||||||
import subprocess
|
import subprocess
|
||||||
from moyanlib import jsons
|
from moyanlib import jsons
|
||||||
from platformdirs import PlatformDirs
|
from platformdirs import PlatformDirs
|
||||||
|
@ -15,11 +14,35 @@ IndexList = []
|
||||||
console = Console()
|
console = Console()
|
||||||
|
|
||||||
def getVer(baseVar):
|
def getVer(baseVar):
|
||||||
baseVar = baseVar + '.' + os.environ.get('GITHUB_RUN_ID', str(int(time.time()))[:6])
|
baseVar = baseVar # + '.' + os.environ.get('GITHUB_RUN_ID', str(int(time.time()))[:6])
|
||||||
|
logger.info('PMPT '+baseVar)
|
||||||
return baseVar
|
return baseVar
|
||||||
|
|
||||||
__version__ = getVer('1.0.1')
|
def GlobalDecorator(frame, event, arg):
|
||||||
|
if event == 'call':
|
||||||
|
try:
|
||||||
|
func_name = frame.f_code.co_name
|
||||||
|
module_name = frame.f_globals['__name__']
|
||||||
|
package_name = module_name.split('.')[0] # 假设包名为模块名的第一部分
|
||||||
|
if package_name == 'pmpt':
|
||||||
|
logger.trace(f"调用函数 {module_name}.{func_name}")
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
return GlobalDecorator
|
||||||
|
|
||||||
|
sys.settrace(GlobalDecorator)
|
||||||
|
|
||||||
|
logger.remove()
|
||||||
|
logger.add(
|
||||||
|
os.path.join(dirs.user_data_dir,'log.log'),
|
||||||
|
level='TRACE',
|
||||||
|
)
|
||||||
|
|
||||||
|
__version__ = getVer('1.0.3')
|
||||||
|
|
||||||
|
|
||||||
def init():
|
def init():
|
||||||
|
|
||||||
os.makedirs(dirs.user_data_dir,exist_ok=True)
|
os.makedirs(dirs.user_data_dir,exist_ok=True)
|
||||||
os.makedirs(os.path.join(dirs.user_data_dir,'Index'),exist_ok=True)
|
os.makedirs(os.path.join(dirs.user_data_dir,'Index'),exist_ok=True)
|
||||||
os.makedirs(dirs.user_config_dir,exist_ok=True)
|
os.makedirs(dirs.user_config_dir,exist_ok=True)
|
||||||
|
@ -41,17 +64,21 @@ def loadIndex():
|
||||||
sourceList = bubbleSort(sourceList)
|
sourceList = bubbleSort(sourceList)
|
||||||
for source in sourceList:
|
for source in sourceList:
|
||||||
if not os.path.exists(os.path.join(dirs.user_data_dir,'Index',source['id']+'.pidx')):
|
if not os.path.exists(os.path.join(dirs.user_data_dir,'Index',source['id']+'.pidx')):
|
||||||
|
logger.warning(source['url']+'没有索引')
|
||||||
console.print(f'⚠️ [yellow]{source["url"]} did not create an index.[/yellow]')
|
console.print(f'⚠️ [yellow]{source["url"]} did not create an index.[/yellow]')
|
||||||
continue
|
continue
|
||||||
|
logger.debug(source)
|
||||||
IndexFile = dill.load(open(os.path.join(dirs.user_data_dir,'Index',source['id']+'.pidx'),'rb')) # 加载索引
|
IndexFile = dill.load(open(os.path.join(dirs.user_data_dir,'Index',source['id']+'.pidx'),'rb')) # 加载索引
|
||||||
IndexList.append(IndexFile)
|
IndexList.append(IndexFile)
|
||||||
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,out=True) -> Popen:
|
def runpip(command,other=None,dbg=False,out=True) -> Popen:
|
||||||
'''
|
'''
|
||||||
运行pip
|
运行pip
|
||||||
'''
|
'''
|
||||||
|
logger.trace('调用runpip')
|
||||||
if not other:
|
if not other:
|
||||||
other = []
|
other = []
|
||||||
baseCommand = [sys.executable,'-m','pip']
|
baseCommand = [sys.executable,'-m','pip']
|
||||||
|
@ -60,13 +87,15 @@ def runpip(command,other=None,dbg=False,out=True) -> Popen:
|
||||||
Command = baseCommand + other
|
Command = baseCommand + other
|
||||||
if dbg:
|
if dbg:
|
||||||
console.print('Command to be run:',' '.join(Command))
|
console.print('Command to be run:',' '.join(Command))
|
||||||
|
logger.debug(' ',)
|
||||||
runClass = Popen(Command,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
|
runClass = Popen(Command,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
|
||||||
if out:
|
if out:
|
||||||
for line in iter(runClass.stdout.readline, b''):
|
for line in iter(runClass.stdout.readline, b''):
|
||||||
# 在这里你可以对每一行输出进行处理
|
# 在这里你可以对每一行输出进行处理
|
||||||
line = line.decode('utf-8').strip() # 将字节转换为字符串并去除换行符
|
line = line.decode('utf-8').strip() # 将字节转换为字符串并去除换行符
|
||||||
console.print(line)
|
console.print(line)
|
||||||
|
if runClass.returncode != 0:
|
||||||
|
console.print(runClass.stderr.read().decode())
|
||||||
runClass.communicate()
|
runClass.communicate()
|
||||||
else:
|
else:
|
||||||
runClass.wait()
|
runClass.wait()
|
||||||
|
|
|
@ -5,3 +5,4 @@ click
|
||||||
dill
|
dill
|
||||||
tqdm
|
tqdm
|
||||||
rich
|
rich
|
||||||
|
loguru
|
2
setup.py
2
setup.py
|
@ -22,7 +22,7 @@ setup(
|
||||||
author='MoYan', # 作者
|
author='MoYan', # 作者
|
||||||
author_email='moyan@moyanjdc.top', # 作者邮箱
|
author_email='moyan@moyanjdc.top', # 作者邮箱
|
||||||
description='A Python Package Advanced Manager', # 包的简要描述
|
description='A Python Package Advanced Manager', # 包的简要描述
|
||||||
long_description='A longer description of your package', # 包的详细描述
|
long_description=open("readme.md").read(), # 包的详细描述
|
||||||
long_description_content_type='text/markdown', # 描述的内容类型
|
long_description_content_type='text/markdown', # 描述的内容类型
|
||||||
classifiers=[ # 包的分类信息
|
classifiers=[ # 包的分类信息
|
||||||
'Development Status :: 3 - Alpha',
|
'Development Status :: 3 - Alpha',
|
||||||
|
|
Loading…
Reference in New Issue
Block a user