0.1.10 增加软件包升级提示

This commit is contained in:
guanjihuan 2023-11-02 03:34:11 +08:00
parent a2b62a17ec
commit a890823e93
4 changed files with 51 additions and 7 deletions

View File

@ -1,4 +1,4 @@
# API Reference shows all functions in Guan package. The current version is guan-0.1.9 updated on November 02, 2023. # API Reference shows all functions in Guan package. The current version is guan-0.1.10 updated on November 02, 2023.
import guan import guan
@ -996,4 +996,11 @@ mac_address = guan.get_mac_address()
# Guan软件包的使用统计不涉及到用户的个人数据 # Guan软件包的使用统计不涉及到用户的个人数据
guan.statistics_of_guan_package() guan.statistics_of_guan_package()
# 获取Python软件包的最新版本
latest_version = guan.get_latest_version(package_name='guan', timeout=2)
# 获取软件包的本机版本
current_version = guan.get_current_version(package_name='guan')
# Guan软件包升级提示
guan.notification_of_upgrade()

View File

@ -1,7 +1,7 @@
[metadata] [metadata]
# replace with your username: # replace with your username:
name = guan name = guan
version = 0.1.9 version = 0.1.10
author = guanjihuan author = guanjihuan
author_email = guanjihuan@163.com author_email = guanjihuan@163.com
description = An open source python package description = An open source python package

View File

@ -1,6 +1,6 @@
Metadata-Version: 2.1 Metadata-Version: 2.1
Name: guan Name: guan
Version: 0.1.9 Version: 0.1.10
Summary: An open source python package Summary: An open source python package
Home-page: https://py.guanjihuan.com Home-page: https://py.guanjihuan.com
Author: guanjihuan Author: guanjihuan

View File

@ -1,6 +1,6 @@
# Guan is an open-source python package developed and maintained by https://www.guanjihuan.com/about (Ji-Huan Guan, 关济寰). The primary location of this package is on website https://py.guanjihuan.com. GitHub link: https://github.com/guanjihuan/py.guanjihuan.com. # Guan is an open-source python package developed and maintained by https://www.guanjihuan.com/about (Ji-Huan Guan, 关济寰). The primary location of this package is on website https://py.guanjihuan.com. GitHub link: https://github.com/guanjihuan/py.guanjihuan.com.
# The current version is guan-0.1.9, updated on November 02, 2023. # The current version is guan-0.1.10, updated on November 02, 2023.
# Installation: pip install --upgrade guan # Installation: pip install --upgrade guan
@ -4911,15 +4911,52 @@ def statistics_of_guan_package():
client_socket.settimeout(0.5) client_socket.settimeout(0.5)
client_socket.connect(('py.guanjihuan.com', 12345)) client_socket.connect(('py.guanjihuan.com', 12345))
message = guan.get_calling_function_name(layer=2) message = guan.get_calling_function_name(layer=2)
send_message = datetime_date + ' ' + datetime_time + ' version_0.1.9 guan.' + message+'\n' send_message = datetime_date + ' ' + datetime_time + ' version_0.1.10 guan.' + message+'\n'
client_socket.send(send_message.encode()) client_socket.send(send_message.encode())
client_socket.close() client_socket.close()
client_socket2 = socket.socket(socket.AF_INET, socket.SOCK_STREAM) client_socket2 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket2.settimeout(0.5) client_socket2.settimeout(0.5)
client_socket2.connect(('py.guanjihuan.com', 12345)) client_socket2.connect(('py.guanjihuan.com', 12345))
mac_address = get_mac_address() mac_address = get_mac_address()
send_mac_address = 'version_0.1.9 MAC_address: '+mac_address+'\n' send_mac_address = 'version_0.1.10 MAC_address: '+mac_address+'\n'
client_socket2.send(send_mac_address.encode()) client_socket2.send(send_mac_address.encode())
client_socket2.close() client_socket2.close()
except: except:
pass pass
# 获取Python软件包的最新版本
def get_latest_version(package_name='guan', timeout=2):
import requests
url = f"https://pypi.org/pypi/{package_name}/json"
try:
response = requests.get(url, timeout=timeout)
except:
return None
if response.status_code == 200:
data = response.json()
latest_version = data["info"]["version"]
return latest_version
else:
return None
# 获取软件包的本机版本
def get_current_version(package_name='guan'):
import importlib.metadata
try:
current_version = importlib.metadata.version(package_name)
return current_version
except:
return None
# Guan软件包升级提示
def notification_of_upgrade():
try:
latest_version = get_latest_version(package_name='guan', timeout=2)
current_version = get_current_version('guan')
if latest_version != None and current_version != None:
if latest_version != current_version:
print('提示:您当前使用的版本是 guan-'+current_version+',目前已经有最新版本 guan-'+latest_version+'。您可以通过以下命令对软件包进行升级pip install --upgrade guan')
except:
pass
notification_of_upgrade()