|
|
|
|
@ -11,19 +11,50 @@ import config
@@ -11,19 +11,50 @@ import config
|
|
|
|
|
import requests |
|
|
|
|
from PIL import Image |
|
|
|
|
from io import BytesIO |
|
|
|
|
import zipfile |
|
|
|
|
import os,time,shutil |
|
|
|
|
|
|
|
|
|
url = "https://mp.api.suwa3d.com" |
|
|
|
|
|
|
|
|
|
def transToIco(pngPath,icoPath): |
|
|
|
|
image = Image.open(pngPath) |
|
|
|
|
image.save(icoPath,format="ICO",sizes=[(48,48)]) |
|
|
|
|
|
|
|
|
|
def delete_exe_files_in_dir(directory): |
|
|
|
|
# 遍历目录中的所有文件和目录条目 |
|
|
|
|
for filename in os.listdir(directory): |
|
|
|
|
file_path = os.path.join(directory, filename) |
|
|
|
|
# 检查当前条目是否为文件且扩展名为.exe |
|
|
|
|
if os.path.isfile(file_path) and filename.endswith('.exe'): |
|
|
|
|
try: |
|
|
|
|
os.remove(file_path) # 删除文件 |
|
|
|
|
print(f"Deleted: {file_path}") |
|
|
|
|
except Exception as e: |
|
|
|
|
print(f"Error deleting {file_path}: {e}") |
|
|
|
|
|
|
|
|
|
def zip_dir(path, output=None): |
|
|
|
|
"""压缩指定目录""" |
|
|
|
|
output = output or os.path.basename(path) + '.zip' # 压缩文件的名字 |
|
|
|
|
zip = zipfile.ZipFile(output, 'w', zipfile.ZIP_DEFLATED) |
|
|
|
|
for root, dirs, files in os.walk(path): |
|
|
|
|
relative_root = '' if root == path else root.replace(path, '') + os.sep # 计算文件相对路径 |
|
|
|
|
for filename in files: |
|
|
|
|
zip.write(os.path.join(root, filename), relative_root + filename) # 文件路径 压缩文件路径(相对路径) |
|
|
|
|
zip.close() |
|
|
|
|
|
|
|
|
|
def main(): |
|
|
|
|
#连接mp 的redis |
|
|
|
|
r = redis.Redis(host="106.14.158.208",password="kcV2000",port=6379,db=1) |
|
|
|
|
#本地测试环境 |
|
|
|
|
#r = redis.Redis(host="172.31.1.254",port=6379,db=1) |
|
|
|
|
#取出数据 |
|
|
|
|
oemId = r.lpop('setup') |
|
|
|
|
oemId = 21 |
|
|
|
|
if oemId is None: |
|
|
|
|
print("没有从redis中获取到oemId的数据") |
|
|
|
|
return |
|
|
|
|
print("oemId",oemId) |
|
|
|
|
#请求mp的接口,获取对应的oem的数据 |
|
|
|
|
res = requests.get("http://172.16.20.7:8199/api/oem/infoById",params={"id":oemId}) |
|
|
|
|
res = requests.get(url+"/api/oem/infoById",params={"id":oemId}) |
|
|
|
|
#获取数据解析数据 |
|
|
|
|
# print(res.text) |
|
|
|
|
#解析数据 |
|
|
|
|
@ -45,17 +76,35 @@ def main():
@@ -45,17 +76,35 @@ def main():
|
|
|
|
|
|
|
|
|
|
# #将图片下载到本地 |
|
|
|
|
getExeImg(data['data']['logo'], "D:\\oemProject\\build\\appicon.png") |
|
|
|
|
#删除 D:\\oemProject\\build\\bin 目录下的所有exe 文件,不包含子目录 |
|
|
|
|
delete_exe_files_in_dir("D:\\oemProject\\build\\bin") |
|
|
|
|
|
|
|
|
|
# #重命名文件 |
|
|
|
|
# os.system(f"cd D:\\oemProject && ren build\\bin\\{data['data']['brand_name']}amd64-installer.exe "+str(data['data']['id'])+".exe") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#写入成功后在 E:\\wails\\oemProject\\ 目录下执行 wails build 命令 |
|
|
|
|
os.system("cd D:\\oemProject && wails build") |
|
|
|
|
#写入成功后在 E:\\wails\\oemProject\\ 目录下执行 wails build 命令 -debug |
|
|
|
|
os.system("cd D:\\oemProject && wails build -nsis") |
|
|
|
|
time.sleep(35) |
|
|
|
|
#删除指定目录下的多余产生的文件 |
|
|
|
|
os.system("cd D:\\oemProject && del /s/q/f build\\bin\\"+str(data['data']['id'])+".exe") |
|
|
|
|
|
|
|
|
|
# #执行 wails build 命令后,将 E:\wails\oemProject\build\bin ,在上传到 oss 中 |
|
|
|
|
config.oss_bucket.put_object_from_file(f'exe/'+str(data['data']['id'])+".exe", "D:\\oemProject\\build\\bin\\"+str(data['data']['id'])+".exe") |
|
|
|
|
print("上传成功") |
|
|
|
|
# #上传成功后,调用接口,告诉mp,已经生成exe及上传成功 |
|
|
|
|
requests.get("http://172.16.20.7:8199/api/oem/infoSetupUpdate",params={"id":oemId}) |
|
|
|
|
#打包压缩指定文件夹 |
|
|
|
|
# 指定要打包的文件夹路径 |
|
|
|
|
folder_to_zip = 'D:\\oemProject\\build\\bin' |
|
|
|
|
|
|
|
|
|
# 指定生成的压缩包名称和路径 |
|
|
|
|
zip_filename = f"{str(data['data']['id'])}.zip" |
|
|
|
|
|
|
|
|
|
zip_dir(folder_to_zip,zip_filename) |
|
|
|
|
|
|
|
|
|
#执行 wails build 命令后,将 E:\wails\oemProject\build\bin ,在上传到 oss 中 |
|
|
|
|
config.oss_bucket.put_object_from_file(f'exe/'+str(data['data']['id'])+".zip", str(data['data']['id'])+".zip") |
|
|
|
|
print("打包程序已上传完成-"+str(data['data']['id'])+".zip") |
|
|
|
|
#上传成功后,调用接口,告诉mp,已经生成exe及上传成功 |
|
|
|
|
requests.get(url+"/api/oem/infoSetupUpdate",params={"id":oemId}) |
|
|
|
|
# |
|
|
|
|
os.system("cd D:\\make2 && del /s/q/f timer\\"+str(data['data']['id'])+".zip") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def getExeImg(image_url, output_path): |
|
|
|
|
@ -68,9 +117,19 @@ def getExeImg(image_url, output_path):
@@ -68,9 +117,19 @@ def getExeImg(image_url, output_path):
|
|
|
|
|
resized_image = image.resize((1024, 1024)) |
|
|
|
|
# 保存图片为PNG格式 |
|
|
|
|
resized_image.save(output_path, 'PNG') |
|
|
|
|
#转换格式 |
|
|
|
|
transToIco(output_path,"D:\\oemProject\\build\\windows\\icon.ico") |
|
|
|
|
#复制图片到指定目录 |
|
|
|
|
time.sleep(3) |
|
|
|
|
shutil.copy("D:\\oemProject\\build\\windows\\icon.ico","D:\\oemProject\\build\\bin\\icon.ico",) |
|
|
|
|
|
|
|
|
|
else: |
|
|
|
|
print(f"Failed to download image. Status code: {response.status_code}") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
|
|
#开启定时循环模式 |
|
|
|
|
print("开启定时任务,检测是否打包") |
|
|
|
|
while True: |
|
|
|
|
main() |
|
|
|
|
time.sleep(10) |