You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
4.1 KiB

1 year ago
  1. #coding: utf-8
  2. # +-------------------------------------------------------------------
  3. # | 宝塔Windows面板
  4. # +-------------------------------------------------------------------
  5. # | Copyright (c) 2015-2020 宝塔软件(http://www.bt.cn) All rights reserved.
  6. # +-------------------------------------------------------------------
  7. # | Author: 沐落 <[email protected]>
  8. # | 面板升级安装公共类
  9. # +-------------------------------------------------------------------
  10. import os, sys
  11. panelPath = os.getenv('BT_PANEL')
  12. os.chdir(panelPath)
  13. sys.path.insert(0,panelPath + "/class/")
  14. import public,time,re,shutil,platform
  15. class panel_update:
  16. def __init__(self):
  17. pass
  18. def UpdatePanel(self,version):
  19. """
  20. @version
  21. """
  22. import public
  23. setupPath = os.getenv('BT_SETUP')
  24. loacl_path = setupPath + '/panel.zip'
  25. tmpPath = "{}/temp/panel".format(setupPath)
  26. httpUrl = 'http://www.example.com'
  27. try:
  28. downUrl = httpUrl + '/win/panel/panel_' + version + '.zip';
  29. if os.path.exists(loacl_path): os.remove(loacl_path)
  30. public.downloadFileByWget(downUrl,loacl_path);
  31. if os.path.getsize(loacl_path) < 1048576: return public.returnMsg(False,"PANEL_UPDATE_ERR_DOWN");
  32. except :
  33. print(public.get_error_info())
  34. return public.returnMsg(False,"修复失败,无法连接到下载节点.");
  35. #处理临时文件目录
  36. tcPath = '{}\class'.format(tmpPath)
  37. if os.path.exists(tmpPath): shutil.rmtree(tmpPath,True)
  38. if not os.path.exists(tmpPath): os.makedirs(tmpPath)
  39. import zipfile
  40. zip_file = zipfile.ZipFile(loacl_path)
  41. for names in zip_file.namelist():
  42. zip_file.extract(names,tmpPath)
  43. zip_file.close()
  44. for name in os.listdir(tcPath):
  45. try:
  46. if name.find('win_amd64.pyd') >=0:
  47. oldName = os.path.join(tcPath,name);
  48. lName = name.split('.')[0] + '.pyd'
  49. newName = os.path.join(tcPath,lName)
  50. if not os.path.exists(newName):os.rename(oldName,newName)
  51. except :pass
  52. #过滤文件
  53. file_list = ['config/config.json','config/index.json','data/libList.conf','data/plugin.json']
  54. for ff_path in file_list:
  55. if os.path.exists(tmpPath + '/' + ff_path): os.remove(tmpPath + '/' + ff_path)
  56. public.mod_reload(public)
  57. import public
  58. #兼容不同版本工具箱
  59. public.kill('BtTools.exe')
  60. toolPath = tmpPath + '/script/BtTools.exe'
  61. if os.path.exists(toolPath):os.remove(toolPath)
  62. s_ver = platform.platform()
  63. net_v = '45'
  64. if s_ver.find('2008') >= 0: net_v = '20'
  65. public.writeFile('{}/data/net'.format(panelPath),net_v)
  66. public.downloadFileByWget(httpUrl + '/win/panel/BtTools' + net_v + '.exe',toolPath);
  67. cPath = '{}/panel/class'.format(setupPath)
  68. os.system("del /s {}\*.pyc".format(public.to_path(cPath)))
  69. os.system("del /s {}\*.pyt".format(public.to_path(cPath)))
  70. for name in os.listdir(cPath):
  71. try:
  72. if name.find('.pyd') >=0:
  73. oldName = os.path.join(cPath,name)
  74. newName = os.path.join(cPath,public.GetRandomString(8) + '.pyt')
  75. os.rename(oldName,newName)
  76. if name.find('.dll') >= 0:
  77. oldName = os.path.join(cPath,name)
  78. public.rmdir(oldName)
  79. except : pass
  80. #处理面板程序目录文件
  81. os.system("del /s {}\*.pyc".format(public.to_path(cPath)))
  82. os.system("del /s {}\*.pyt".format(public.to_path(cPath)))
  83. os.system("echo f|xcopy /s /c /e /y /r {} {}".format(public.to_path(tmpPath),public.to_path(panelPath)))
  84. if os.path.exists('C:/update.py'): os.remove('C:/update.py')
  85. os.system('bt restart')
  86. return public.returnMsg(True,"升级面板成功.");