nonebot-plugin-l4d2-server 0.5.0__py3-none-any.whl → 0.5.2__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.
- LICENSE +674 -674
- README.md +365 -349
- nonebot_plugin_l4d2_server/__init__.py +1 -1
- nonebot_plugin_l4d2_server/chrome.py +45 -0
- nonebot_plugin_l4d2_server/command.py +232 -233
- nonebot_plugin_l4d2_server/config.py +210 -318
- nonebot_plugin_l4d2_server/data/L4D2/image/template/anne.html +60 -60
- nonebot_plugin_l4d2_server/data/L4D2/image/template/fingerprint.svg +15 -15
- nonebot_plugin_l4d2_server/data/L4D2/image/template/help.html +233 -233
- nonebot_plugin_l4d2_server/data/L4D2/image/template/help_dack.html +231 -231
- nonebot_plugin_l4d2_server/data/L4D2/image/template/ip.html +48 -48
- nonebot_plugin_l4d2_server/data/L4D2/image/template/l.svg +9 -9
- nonebot_plugin_l4d2_server/data/L4D2/image/template/vue.css +530 -530
- nonebot_plugin_l4d2_server/l4d2_anne/__init__.py +251 -251
- nonebot_plugin_l4d2_server/l4d2_anne/analysis.py +51 -51
- nonebot_plugin_l4d2_server/l4d2_anne/anne_telecom.py +75 -75
- nonebot_plugin_l4d2_server/l4d2_anne/server.py +65 -65
- nonebot_plugin_l4d2_server/l4d2_anne/startand.py +17 -17
- nonebot_plugin_l4d2_server/l4d2_data/__init__.py +91 -91
- nonebot_plugin_l4d2_server/l4d2_data/config.py +17 -17
- nonebot_plugin_l4d2_server/l4d2_data/players.py +87 -87
- nonebot_plugin_l4d2_server/l4d2_data/serverip.py +32 -32
- nonebot_plugin_l4d2_server/l4d2_file/__init__.py +122 -122
- nonebot_plugin_l4d2_server/l4d2_file/ayromote.py +56 -56
- nonebot_plugin_l4d2_server/l4d2_file/remote.py +63 -66
- nonebot_plugin_l4d2_server/l4d2_image/__init__.py +103 -103
- nonebot_plugin_l4d2_server/l4d2_image/download.py +101 -101
- nonebot_plugin_l4d2_server/l4d2_image/htmlimg.py +32 -32
- nonebot_plugin_l4d2_server/l4d2_image/send_image_tool.py +32 -32
- nonebot_plugin_l4d2_server/l4d2_image/steam.py +83 -83
- nonebot_plugin_l4d2_server/l4d2_image/vtfs.py +40 -40
- nonebot_plugin_l4d2_server/l4d2_queries/__init__.py +114 -114
- nonebot_plugin_l4d2_server/l4d2_queries/api.py +43 -43
- nonebot_plugin_l4d2_server/l4d2_queries/ohter.py +35 -25
- nonebot_plugin_l4d2_server/l4d2_queries/qqgroup.py +288 -288
- nonebot_plugin_l4d2_server/l4d2_server/__init__.py +61 -61
- nonebot_plugin_l4d2_server/l4d2_server/rcon.py +28 -28
- nonebot_plugin_l4d2_server/l4d2_server/workshop.py +50 -50
- nonebot_plugin_l4d2_server/l4d2_web/web.py +234 -234
- nonebot_plugin_l4d2_server/l4d2_web/webUI.py +241 -241
- nonebot_plugin_l4d2_server/message.py +58 -58
- nonebot_plugin_l4d2_server/seach.py +33 -33
- nonebot_plugin_l4d2_server/txt_to_img.py +64 -64
- nonebot_plugin_l4d2_server/utils.py +272 -272
- {nonebot_plugin_l4d2_server-0.5.0.dist-info → nonebot_plugin_l4d2_server-0.5.2.dist-info}/LICENSE +674 -674
- {nonebot_plugin_l4d2_server-0.5.0.dist-info → nonebot_plugin_l4d2_server-0.5.2.dist-info}/METADATA +47 -32
- nonebot_plugin_l4d2_server-0.5.2.dist-info/RECORD +54 -0
- nonebot_plugin_l4d2_server-0.5.0.dist-info/RECORD +0 -53
- {nonebot_plugin_l4d2_server-0.5.0.dist-info → nonebot_plugin_l4d2_server-0.5.2.dist-info}/WHEEL +0 -0
@@ -1,87 +1,87 @@
|
|
1
|
-
from ..config import DATASQLITE
|
2
|
-
import sqlite3
|
3
|
-
from typing import Union,Tuple
|
4
|
-
|
5
|
-
|
6
|
-
class L4D2Player:
|
7
|
-
"""数据库L4D2_Player表的操作"""
|
8
|
-
def __init__(self):
|
9
|
-
"""连接数据库"""
|
10
|
-
self.datasqlite_path = DATASQLITE
|
11
|
-
self.conn = sqlite3.connect(self.datasqlite_path / 'L4D2.db')
|
12
|
-
self.c = self.conn.cursor()
|
13
|
-
|
14
|
-
async def _add_player_nickname(self, qq, nickname):
|
15
|
-
"""绑定昵称"""
|
16
|
-
# try:
|
17
|
-
self.c.execute("INSERT INTO L4d2_players (qq, nickname, steamid) VALUES (?,?,NULL)", (qq, nickname))
|
18
|
-
self.conn.commit()
|
19
|
-
# return True
|
20
|
-
# except sqlite3.IntegrityError:
|
21
|
-
# return False
|
22
|
-
|
23
|
-
async def _add_player_steamid(self, qq, steamid):
|
24
|
-
"""绑定steamid"""
|
25
|
-
self.c.execute("INSERT INTO L4d2_players (qq, nickname, steamid) VALUES (?,NULL,?)", (qq, steamid))
|
26
|
-
self.conn.commit()
|
27
|
-
|
28
|
-
|
29
|
-
async def _add_player_all(self, qq, nickname,steamid):
|
30
|
-
"""用新数据覆盖旧数据"""
|
31
|
-
# try:
|
32
|
-
self.c.execute("INSERT OR REPLACE INTO L4d2_players (qq, nickname, steamid) VALUES (?,?,?)", (qq, nickname,steamid))
|
33
|
-
self.conn.commit()
|
34
|
-
return True
|
35
|
-
# except sqlite3.IntegrityError:
|
36
|
-
# return False
|
37
|
-
|
38
|
-
def _delete_player(self, qq):
|
39
|
-
"""解除绑定"""
|
40
|
-
self.c.execute(f"DELETE FROM L4d2_players WHERE qq = {qq}")
|
41
|
-
self.conn.commit()
|
42
|
-
return True
|
43
|
-
|
44
|
-
def _query_player_qq(self, qq) -> Union[tuple,None]:
|
45
|
-
"""通过qq获取数据"""
|
46
|
-
self.c.execute(f"SELECT * FROM L4d2_players WHERE qq = '{qq}'")
|
47
|
-
return self.c.fetchone()
|
48
|
-
|
49
|
-
async def _query_player_nickname(self, nickname:str) -> Union[tuple,None]:
|
50
|
-
"""通过nickname获取数据"""
|
51
|
-
self.c.execute(f"SELECT * FROM L4d2_players WHERE nickname = '{nickname}'")
|
52
|
-
return self.c.fetchone()
|
53
|
-
|
54
|
-
async def _query_player_steamid(self, steamid:str):
|
55
|
-
"""通过steamid获取数据"""
|
56
|
-
self.c.execute(f"SELECT * FROM L4d2_players WHERE steamid = '{steamid}'")
|
57
|
-
data_tuple = self.c.fetchone()
|
58
|
-
return data_tuple
|
59
|
-
|
60
|
-
async def search_data(self, qq, nickname, steamid) -> Union[tuple,None]:
|
61
|
-
"""
|
62
|
-
输入元组查询,优先qq其次steamid最后nickname,不需要值可以为None
|
63
|
-
输出为元组,如果为空输出None
|
64
|
-
data = (qq , nickname , steamid )
|
65
|
-
"""
|
66
|
-
if qq:
|
67
|
-
self.c.execute("SELECT * FROM L4d2_players WHERE qq=?", (qq,))
|
68
|
-
result = self.c.fetchone()
|
69
|
-
if result:
|
70
|
-
return result
|
71
|
-
if steamid:
|
72
|
-
self.c.execute("SELECT * FROM L4d2_players WHERE steamid=?", (steamid,))
|
73
|
-
result = self.c.fetchone()
|
74
|
-
if result:
|
75
|
-
return result
|
76
|
-
if nickname:
|
77
|
-
self.c.execute("SELECT * FROM L4d2_players WHERE nickname=?", (nickname,))
|
78
|
-
result = self.c.fetchone()
|
79
|
-
if result:
|
80
|
-
return result
|
81
|
-
return None
|
82
|
-
|
83
|
-
def _query_all_player(self) -> Tuple[tuple]:
|
84
|
-
"""获取所有玩家信息"""
|
85
|
-
self.c.execute("SELECT * FROM L4d2_players")
|
86
|
-
return self.c.fetchall()
|
87
|
-
|
1
|
+
from ..config import DATASQLITE
|
2
|
+
import sqlite3
|
3
|
+
from typing import Union,Tuple
|
4
|
+
|
5
|
+
|
6
|
+
class L4D2Player:
|
7
|
+
"""数据库L4D2_Player表的操作"""
|
8
|
+
def __init__(self):
|
9
|
+
"""连接数据库"""
|
10
|
+
self.datasqlite_path = DATASQLITE
|
11
|
+
self.conn = sqlite3.connect(self.datasqlite_path / 'L4D2.db')
|
12
|
+
self.c = self.conn.cursor()
|
13
|
+
|
14
|
+
async def _add_player_nickname(self, qq, nickname):
|
15
|
+
"""绑定昵称"""
|
16
|
+
# try:
|
17
|
+
self.c.execute("INSERT INTO L4d2_players (qq, nickname, steamid) VALUES (?,?,NULL)", (qq, nickname))
|
18
|
+
self.conn.commit()
|
19
|
+
# return True
|
20
|
+
# except sqlite3.IntegrityError:
|
21
|
+
# return False
|
22
|
+
|
23
|
+
async def _add_player_steamid(self, qq, steamid):
|
24
|
+
"""绑定steamid"""
|
25
|
+
self.c.execute("INSERT INTO L4d2_players (qq, nickname, steamid) VALUES (?,NULL,?)", (qq, steamid))
|
26
|
+
self.conn.commit()
|
27
|
+
|
28
|
+
|
29
|
+
async def _add_player_all(self, qq, nickname,steamid):
|
30
|
+
"""用新数据覆盖旧数据"""
|
31
|
+
# try:
|
32
|
+
self.c.execute("INSERT OR REPLACE INTO L4d2_players (qq, nickname, steamid) VALUES (?,?,?)", (qq, nickname,steamid))
|
33
|
+
self.conn.commit()
|
34
|
+
return True
|
35
|
+
# except sqlite3.IntegrityError:
|
36
|
+
# return False
|
37
|
+
|
38
|
+
def _delete_player(self, qq):
|
39
|
+
"""解除绑定"""
|
40
|
+
self.c.execute(f"DELETE FROM L4d2_players WHERE qq = {qq}")
|
41
|
+
self.conn.commit()
|
42
|
+
return True
|
43
|
+
|
44
|
+
def _query_player_qq(self, qq) -> Union[tuple,None]:
|
45
|
+
"""通过qq获取数据"""
|
46
|
+
self.c.execute(f"SELECT * FROM L4d2_players WHERE qq = '{qq}'")
|
47
|
+
return self.c.fetchone()
|
48
|
+
|
49
|
+
async def _query_player_nickname(self, nickname:str) -> Union[tuple,None]:
|
50
|
+
"""通过nickname获取数据"""
|
51
|
+
self.c.execute(f"SELECT * FROM L4d2_players WHERE nickname = '{nickname}'")
|
52
|
+
return self.c.fetchone()
|
53
|
+
|
54
|
+
async def _query_player_steamid(self, steamid:str):
|
55
|
+
"""通过steamid获取数据"""
|
56
|
+
self.c.execute(f"SELECT * FROM L4d2_players WHERE steamid = '{steamid}'")
|
57
|
+
data_tuple = self.c.fetchone()
|
58
|
+
return data_tuple
|
59
|
+
|
60
|
+
async def search_data(self, qq, nickname, steamid) -> Union[tuple,None]:
|
61
|
+
"""
|
62
|
+
输入元组查询,优先qq其次steamid最后nickname,不需要值可以为None
|
63
|
+
输出为元组,如果为空输出None
|
64
|
+
data = (qq , nickname , steamid )
|
65
|
+
"""
|
66
|
+
if qq:
|
67
|
+
self.c.execute("SELECT * FROM L4d2_players WHERE qq=?", (qq,))
|
68
|
+
result = self.c.fetchone()
|
69
|
+
if result:
|
70
|
+
return result
|
71
|
+
if steamid:
|
72
|
+
self.c.execute("SELECT * FROM L4d2_players WHERE steamid=?", (steamid,))
|
73
|
+
result = self.c.fetchone()
|
74
|
+
if result:
|
75
|
+
return result
|
76
|
+
if nickname:
|
77
|
+
self.c.execute("SELECT * FROM L4d2_players WHERE nickname=?", (nickname,))
|
78
|
+
result = self.c.fetchone()
|
79
|
+
if result:
|
80
|
+
return result
|
81
|
+
return None
|
82
|
+
|
83
|
+
def _query_all_player(self) -> Tuple[tuple]:
|
84
|
+
"""获取所有玩家信息"""
|
85
|
+
self.c.execute("SELECT * FROM L4d2_players")
|
86
|
+
return self.c.fetchall()
|
87
|
+
|
@@ -1,33 +1,33 @@
|
|
1
|
-
from ..config import DATASQLITE
|
2
|
-
import sqlite3
|
3
|
-
|
4
|
-
|
5
|
-
class L4D2Server():
|
6
|
-
"""数据库L4D2_server表的操作"""
|
7
|
-
def __init__(self):
|
8
|
-
"""连接数据库"""
|
9
|
-
self.datasqlite_path = DATASQLITE
|
10
|
-
self.conn = sqlite3.connect(self.datasqlite_path / 'L4D2.db')
|
11
|
-
self.c = self.conn.cursor()
|
12
|
-
|
13
|
-
async def bind_server_ip(self,qqgroup,host,port):
|
14
|
-
"""绑定群订阅ip"""
|
15
|
-
self.c.execute("INSERT OR REPLACE INTO L4D2_server (qqgroup, host, port) VALUES (?,?,?)", (qqgroup, host,port))
|
16
|
-
self.conn.commit()
|
17
|
-
|
18
|
-
async def query_server_ip(self,qqgroup) :
|
19
|
-
"""输入群号,返回数据库里订阅ip元组列表"""
|
20
|
-
self.c.execute(f"SELECT number, qqgroup ,host ,port FROM L4D2_server WHERE qqgroup = {qqgroup}")
|
21
|
-
msg_list = self.c.fetchall()
|
22
|
-
return msg_list
|
23
|
-
|
24
|
-
async def del_server_ip(self,id:int):
|
25
|
-
"""删除指定id的ip"""
|
26
|
-
self.c.execute(f"DELETE FROM L4D2_server WHERE number = {id}")
|
27
|
-
self.conn.commit()
|
28
|
-
|
29
|
-
async def query_number(self,number:int):
|
30
|
-
"""通过序号找服务器"""
|
31
|
-
self.c.execute(f"SELECT qqgroup , host ,port FROM L4D2_server WHERE number = {number}")
|
32
|
-
msg_list = self.c.fetchone()
|
1
|
+
from ..config import DATASQLITE
|
2
|
+
import sqlite3
|
3
|
+
|
4
|
+
|
5
|
+
class L4D2Server():
|
6
|
+
"""数据库L4D2_server表的操作"""
|
7
|
+
def __init__(self):
|
8
|
+
"""连接数据库"""
|
9
|
+
self.datasqlite_path = DATASQLITE
|
10
|
+
self.conn = sqlite3.connect(self.datasqlite_path / 'L4D2.db')
|
11
|
+
self.c = self.conn.cursor()
|
12
|
+
|
13
|
+
async def bind_server_ip(self,qqgroup,host,port):
|
14
|
+
"""绑定群订阅ip"""
|
15
|
+
self.c.execute("INSERT OR REPLACE INTO L4D2_server (qqgroup, host, port) VALUES (?,?,?)", (qqgroup, host,port))
|
16
|
+
self.conn.commit()
|
17
|
+
|
18
|
+
async def query_server_ip(self,qqgroup) :
|
19
|
+
"""输入群号,返回数据库里订阅ip元组列表"""
|
20
|
+
self.c.execute(f"SELECT number, qqgroup ,host ,port FROM L4D2_server WHERE qqgroup = {qqgroup}")
|
21
|
+
msg_list = self.c.fetchall()
|
22
|
+
return msg_list
|
23
|
+
|
24
|
+
async def del_server_ip(self,id:int):
|
25
|
+
"""删除指定id的ip"""
|
26
|
+
self.c.execute(f"DELETE FROM L4D2_server WHERE number = {id}")
|
27
|
+
self.conn.commit()
|
28
|
+
|
29
|
+
async def query_number(self,number:int):
|
30
|
+
"""通过序号找服务器"""
|
31
|
+
self.c.execute(f"SELECT qqgroup , host ,port FROM L4D2_server WHERE number = {number}")
|
32
|
+
msg_list = self.c.fetchone()
|
33
33
|
return msg_list
|
@@ -1,122 +1,122 @@
|
|
1
|
-
from pathlib import Path
|
2
|
-
from zipfile import ZipFile
|
3
|
-
from time import sleep
|
4
|
-
import sys
|
5
|
-
import os
|
6
|
-
import io
|
7
|
-
from typing import List
|
8
|
-
|
9
|
-
from ..utils import get_file,get_vpk
|
10
|
-
from ..config import systems
|
11
|
-
from nonebot.log import logger
|
12
|
-
from rarfile import RarFile
|
13
|
-
import rarfile
|
14
|
-
from pyunpack import Archive
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
async def updown_l4d2_vpk(map_paths,name,url):
|
19
|
-
"""从url下载压缩包并解压到位置"""
|
20
|
-
original_vpk_files = []
|
21
|
-
original_vpk_files = get_vpk(original_vpk_files,map_paths)
|
22
|
-
down_file = Path(map_paths,name)
|
23
|
-
if await get_file(url,down_file) == None:
|
24
|
-
return None
|
25
|
-
sleep(1)
|
26
|
-
msg = open_packet(name,down_file)
|
27
|
-
logger.info(msg)
|
28
|
-
|
29
|
-
sleep(1)
|
30
|
-
extracted_vpk_files = []
|
31
|
-
extracted_vpk_files = get_vpk(extracted_vpk_files,map_paths)
|
32
|
-
# 获取新增vpk文件的list
|
33
|
-
vpk_files = list(set(extracted_vpk_files) - set(original_vpk_files))
|
34
|
-
return vpk_files
|
35
|
-
|
36
|
-
def open_packet(name:str,down_file:Path):
|
37
|
-
"""解压压缩包"""
|
38
|
-
down_path = os.path.dirname(down_file)
|
39
|
-
logger.info('文件名为:' + name)
|
40
|
-
logger.info(f'系统为{systems}')
|
41
|
-
if systems == 'win':
|
42
|
-
if name.endswith('.zip'):
|
43
|
-
mes = 'zip文件已下载,正在解压'
|
44
|
-
try:
|
45
|
-
with support_gbk(ZipFile(down_file, 'r')) as z:
|
46
|
-
z.extractall(down_path)
|
47
|
-
except UnicodeEncodeError:
|
48
|
-
with ZipFile(down_file, 'r') as z:
|
49
|
-
z.extractall(down_path)
|
50
|
-
os.remove(down_file)
|
51
|
-
elif name.endswith('.7z'):
|
52
|
-
mes ='7z文件已下载,正在解压'
|
53
|
-
Archive(down_file).extractall(down_path)
|
54
|
-
# with SevenZipFile(down_file, 'r') as z:
|
55
|
-
# z.extractall(down_path)
|
56
|
-
os.remove(down_file)
|
57
|
-
elif name.endswith('rar'):
|
58
|
-
mes = 'rar文件已下载,正在解压'
|
59
|
-
with RarFile(down_file,'r') as z:
|
60
|
-
z.extractall(down_path)
|
61
|
-
os.remove(down_file)
|
62
|
-
elif name.endswith('.vpk'):
|
63
|
-
mes ='vpk文件已下载'
|
64
|
-
else:
|
65
|
-
if name.endswith('.zip'):
|
66
|
-
mes = 'zip文件已下载,正在解压'
|
67
|
-
with support_gbk(ZipFile(down_file, 'r')) as z:
|
68
|
-
z.extractall(down_path)
|
69
|
-
os.remove(down_file)
|
70
|
-
elif name.endswith('.7z'):
|
71
|
-
mes ='7z文件已下载,正在解压'
|
72
|
-
Archive(down_file).extractall(down_path)
|
73
|
-
# with SevenZipFile(down_file, 'r') as z:
|
74
|
-
# z.extractall(down_path)
|
75
|
-
os.remove(down_file)
|
76
|
-
elif name.endswith('rar'):
|
77
|
-
mes = 'rar文件已下载,正在解压'
|
78
|
-
with rarfile.RarFile(down_file,'r') as z:
|
79
|
-
z.extractall(down_path)
|
80
|
-
os.remove(down_file)
|
81
|
-
else:
|
82
|
-
mes ='vpk文件已下载'
|
83
|
-
return mes
|
84
|
-
|
85
|
-
def support_gbk(zip_file:ZipFile):
|
86
|
-
'''
|
87
|
-
压缩包中文恢复
|
88
|
-
'''
|
89
|
-
if type(zip_file) == ZipFile:
|
90
|
-
name_to_info = zip_file.NameToInfo
|
91
|
-
# copy map first
|
92
|
-
for name, info in name_to_info.copy().items():
|
93
|
-
real_name = name.encode('cp437').decode('gbk')
|
94
|
-
if real_name != name:
|
95
|
-
info.filename = real_name
|
96
|
-
del name_to_info[name]
|
97
|
-
name_to_info[real_name] = info
|
98
|
-
return zip_file
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
async def all_zip_to_one(data_list:List[bytes]):
|
104
|
-
"""多压缩包文件合并"""
|
105
|
-
file_list = []
|
106
|
-
for data in data_list:
|
107
|
-
# 将每个bytes对象解压缩成文件对象
|
108
|
-
# 将文件对象存储在一个列表中
|
109
|
-
file_list.append(io.BytesIO(data))
|
110
|
-
|
111
|
-
# 创建一个新的BytesIO对象
|
112
|
-
data_file = io.BytesIO()
|
113
|
-
|
114
|
-
# 使用zipfile将列表中的文件对象添加到zipfile中
|
115
|
-
with ZipFile(data_file, mode='w') as zf:
|
116
|
-
for i, file in enumerate(file_list):
|
117
|
-
# 将文件名设置为"file{i}.zip",i为文件在列表中的索引
|
118
|
-
filename = f"file{i}.zip"
|
119
|
-
zf.writestr(filename, file.getvalue())
|
120
|
-
|
121
|
-
# 获取zipfile的bytes对象
|
122
|
-
return data_file.getvalue()
|
1
|
+
from pathlib import Path
|
2
|
+
from zipfile import ZipFile
|
3
|
+
from time import sleep
|
4
|
+
import sys
|
5
|
+
import os
|
6
|
+
import io
|
7
|
+
from typing import List
|
8
|
+
|
9
|
+
from ..utils import get_file,get_vpk
|
10
|
+
from ..config import systems
|
11
|
+
from nonebot.log import logger
|
12
|
+
from rarfile import RarFile
|
13
|
+
import rarfile
|
14
|
+
from pyunpack import Archive
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
async def updown_l4d2_vpk(map_paths,name,url):
|
19
|
+
"""从url下载压缩包并解压到位置"""
|
20
|
+
original_vpk_files = []
|
21
|
+
original_vpk_files = get_vpk(original_vpk_files,map_paths)
|
22
|
+
down_file = Path(map_paths,name)
|
23
|
+
if await get_file(url,down_file) == None:
|
24
|
+
return None
|
25
|
+
sleep(1)
|
26
|
+
msg = open_packet(name,down_file)
|
27
|
+
logger.info(msg)
|
28
|
+
|
29
|
+
sleep(1)
|
30
|
+
extracted_vpk_files = []
|
31
|
+
extracted_vpk_files = get_vpk(extracted_vpk_files,map_paths)
|
32
|
+
# 获取新增vpk文件的list
|
33
|
+
vpk_files = list(set(extracted_vpk_files) - set(original_vpk_files))
|
34
|
+
return vpk_files
|
35
|
+
|
36
|
+
def open_packet(name:str,down_file:Path):
|
37
|
+
"""解压压缩包"""
|
38
|
+
down_path = os.path.dirname(down_file)
|
39
|
+
logger.info('文件名为:' + name)
|
40
|
+
logger.info(f'系统为{systems}')
|
41
|
+
if systems == 'win':
|
42
|
+
if name.endswith('.zip'):
|
43
|
+
mes = 'zip文件已下载,正在解压'
|
44
|
+
try:
|
45
|
+
with support_gbk(ZipFile(down_file, 'r')) as z:
|
46
|
+
z.extractall(down_path)
|
47
|
+
except UnicodeEncodeError:
|
48
|
+
with ZipFile(down_file, 'r') as z:
|
49
|
+
z.extractall(down_path)
|
50
|
+
os.remove(down_file)
|
51
|
+
elif name.endswith('.7z'):
|
52
|
+
mes ='7z文件已下载,正在解压'
|
53
|
+
Archive(down_file).extractall(down_path)
|
54
|
+
# with SevenZipFile(down_file, 'r') as z:
|
55
|
+
# z.extractall(down_path)
|
56
|
+
os.remove(down_file)
|
57
|
+
elif name.endswith('rar'):
|
58
|
+
mes = 'rar文件已下载,正在解压'
|
59
|
+
with RarFile(down_file,'r') as z:
|
60
|
+
z.extractall(down_path)
|
61
|
+
os.remove(down_file)
|
62
|
+
elif name.endswith('.vpk'):
|
63
|
+
mes ='vpk文件已下载'
|
64
|
+
else:
|
65
|
+
if name.endswith('.zip'):
|
66
|
+
mes = 'zip文件已下载,正在解压'
|
67
|
+
with support_gbk(ZipFile(down_file, 'r')) as z:
|
68
|
+
z.extractall(down_path)
|
69
|
+
os.remove(down_file)
|
70
|
+
elif name.endswith('.7z'):
|
71
|
+
mes ='7z文件已下载,正在解压'
|
72
|
+
Archive(down_file).extractall(down_path)
|
73
|
+
# with SevenZipFile(down_file, 'r') as z:
|
74
|
+
# z.extractall(down_path)
|
75
|
+
os.remove(down_file)
|
76
|
+
elif name.endswith('rar'):
|
77
|
+
mes = 'rar文件已下载,正在解压'
|
78
|
+
with rarfile.RarFile(down_file,'r') as z:
|
79
|
+
z.extractall(down_path)
|
80
|
+
os.remove(down_file)
|
81
|
+
else:
|
82
|
+
mes ='vpk文件已下载'
|
83
|
+
return mes
|
84
|
+
|
85
|
+
def support_gbk(zip_file:ZipFile):
|
86
|
+
'''
|
87
|
+
压缩包中文恢复
|
88
|
+
'''
|
89
|
+
if type(zip_file) == ZipFile:
|
90
|
+
name_to_info = zip_file.NameToInfo
|
91
|
+
# copy map first
|
92
|
+
for name, info in name_to_info.copy().items():
|
93
|
+
real_name = name.encode('cp437').decode('gbk')
|
94
|
+
if real_name != name:
|
95
|
+
info.filename = real_name
|
96
|
+
del name_to_info[name]
|
97
|
+
name_to_info[real_name] = info
|
98
|
+
return zip_file
|
99
|
+
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
async def all_zip_to_one(data_list:List[bytes]):
|
104
|
+
"""多压缩包文件合并"""
|
105
|
+
file_list = []
|
106
|
+
for data in data_list:
|
107
|
+
# 将每个bytes对象解压缩成文件对象
|
108
|
+
# 将文件对象存储在一个列表中
|
109
|
+
file_list.append(io.BytesIO(data))
|
110
|
+
|
111
|
+
# 创建一个新的BytesIO对象
|
112
|
+
data_file = io.BytesIO()
|
113
|
+
|
114
|
+
# 使用zipfile将列表中的文件对象添加到zipfile中
|
115
|
+
with ZipFile(data_file, mode='w') as zf:
|
116
|
+
for i, file in enumerate(file_list):
|
117
|
+
# 将文件名设置为"file{i}.zip",i为文件在列表中的索引
|
118
|
+
filename = f"file{i}.zip"
|
119
|
+
zf.writestr(filename, file.getvalue())
|
120
|
+
|
121
|
+
# 获取zipfile的bytes对象
|
122
|
+
return data_file.getvalue()
|
@@ -1,56 +1,56 @@
|
|
1
|
-
import asyncio
|
2
|
-
import asyncssh
|
3
|
-
|
4
|
-
class AsyncSSHClient:
|
5
|
-
def __init__(self, host, port, username, password=None, private_key=None):
|
6
|
-
self.host = host
|
7
|
-
self.port = port
|
8
|
-
self.username = username
|
9
|
-
self.password = password
|
10
|
-
self.private_key = private_key
|
11
|
-
|
12
|
-
async def connect(self):
|
13
|
-
if self.private_key is not None:
|
14
|
-
try:
|
15
|
-
key = asyncssh.read_private_key(self.private_key)
|
16
|
-
except asyncssh.Error as exc:
|
17
|
-
raise ValueError(f"Unable to read private key: {exc}")
|
18
|
-
else:
|
19
|
-
key = None
|
20
|
-
|
21
|
-
self.conn = await asyncssh.connect(
|
22
|
-
self.host, self.port,
|
23
|
-
username = self.username,
|
24
|
-
password=self.password,
|
25
|
-
client_keys=key
|
26
|
-
)
|
27
|
-
|
28
|
-
async def upload(self, local_path, remote_path):
|
29
|
-
async with self.conn.sftp() as sftp:
|
30
|
-
await sftp.put(local_path, remote_path)
|
31
|
-
|
32
|
-
async def delete(self, remote_path):
|
33
|
-
async with self.conn.sftp() as sftp:
|
34
|
-
await sftp.remove(remote_path)
|
35
|
-
|
36
|
-
async def listdir(self, remote_path):
|
37
|
-
async with self.conn.sftp() as sftp:
|
38
|
-
return await sftp.listdir(remote_path)
|
39
|
-
|
40
|
-
async def close(self):
|
41
|
-
self.conn.close()
|
42
|
-
|
43
|
-
async def remote(mode:str,host:str,user:str,password:str,local_path = '',port=22, remote_path = ''):
|
44
|
-
"""mode:upload、read、del"""
|
45
|
-
client = AsyncSSHClient(host, port,user, password)
|
46
|
-
await client.connect()
|
47
|
-
if mode == 'upload':
|
48
|
-
await client.upload(local_path, remote_path)
|
49
|
-
elif mode == 'read':
|
50
|
-
file = await client.read(remote_path)
|
51
|
-
return file
|
52
|
-
elif mode == 'del':
|
53
|
-
await client.delete(remote_path)
|
54
|
-
|
55
|
-
if __name__ == '__main__':
|
56
|
-
asyncio.run(remote(mode='upload',host='106.13.207.45',user='root',password='Taojie@114514',local_path='E:\\zhang\\文件\\login_info.txt',remote_path='/home/'))
|
1
|
+
import asyncio
|
2
|
+
import asyncssh
|
3
|
+
|
4
|
+
class AsyncSSHClient:
|
5
|
+
def __init__(self, host, port, username, password=None, private_key=None):
|
6
|
+
self.host = host
|
7
|
+
self.port = port
|
8
|
+
self.username = username
|
9
|
+
self.password = password
|
10
|
+
self.private_key = private_key
|
11
|
+
|
12
|
+
async def connect(self):
|
13
|
+
if self.private_key is not None:
|
14
|
+
try:
|
15
|
+
key = asyncssh.read_private_key(self.private_key)
|
16
|
+
except asyncssh.Error as exc:
|
17
|
+
raise ValueError(f"Unable to read private key: {exc}")
|
18
|
+
else:
|
19
|
+
key = None
|
20
|
+
|
21
|
+
self.conn = await asyncssh.connect(
|
22
|
+
self.host, self.port,
|
23
|
+
username = self.username,
|
24
|
+
password=self.password,
|
25
|
+
client_keys=key
|
26
|
+
)
|
27
|
+
|
28
|
+
async def upload(self, local_path, remote_path):
|
29
|
+
async with self.conn.sftp() as sftp:
|
30
|
+
await sftp.put(local_path, remote_path)
|
31
|
+
|
32
|
+
async def delete(self, remote_path):
|
33
|
+
async with self.conn.sftp() as sftp:
|
34
|
+
await sftp.remove(remote_path)
|
35
|
+
|
36
|
+
async def listdir(self, remote_path):
|
37
|
+
async with self.conn.sftp() as sftp:
|
38
|
+
return await sftp.listdir(remote_path)
|
39
|
+
|
40
|
+
async def close(self):
|
41
|
+
self.conn.close()
|
42
|
+
|
43
|
+
async def remote(mode:str,host:str,user:str,password:str,local_path = '',port=22, remote_path = ''):
|
44
|
+
"""mode:upload、read、del"""
|
45
|
+
client = AsyncSSHClient(host, port,user, password)
|
46
|
+
await client.connect()
|
47
|
+
if mode == 'upload':
|
48
|
+
await client.upload(local_path, remote_path)
|
49
|
+
elif mode == 'read':
|
50
|
+
file = await client.read(remote_path)
|
51
|
+
return file
|
52
|
+
elif mode == 'del':
|
53
|
+
await client.delete(remote_path)
|
54
|
+
|
55
|
+
if __name__ == '__main__':
|
56
|
+
asyncio.run(remote(mode='upload',host='106.13.207.45',user='root',password='Taojie@114514',local_path='E:\\zhang\\文件\\login_info.txt',remote_path='/home/'))
|