def startUpdate(self, config): plugin_name = config['name'] plugin_ver = config['version'] update_url = config['repository']['url'] self.plugin_down = os.path.join(self.TEMPDOWN_DIR, plugin_name) self.plugin_path = os.path.join(self.PLUGIN_DIR, plugin_name) new_ver = self.get_new_ver(config) if mylib.versionCompare(plugin_ver, new_ver) > 0: # 下载最新文件 self.down_newfile(plugin_name, update_url) time.sleep(1) return self.move_plugin('升级插件') else: ret_arr = { 'code': 20000, 'message': '当前插件已经是最新版了', 'data': { 'error': '0000', 'version': plugin_ver } } return json.dumps(ret_arr)
def load_allpugin(self): # 远程插件列表 origin_plugin = self.__load_origin_plugin() # 本地已装插件 local_plugin = self.__load_local_pugin() new_json = [] for origin_item in origin_plugin: origin_item['state'] = '一键安装' for local_item in local_plugin: if origin_item['name'] == local_item['name']: origin_item['state'] = '已安装' if mylib.versionCompare(local_item['version'], origin_item['version']) > 0: origin_item['state'] = '一键升级' new_json.append(origin_item) ret_arr = {'code': 20000, 'message': '获取全部插件数据成功', 'data': new_json} return json.dumps(ret_arr)
def checkver_pugin(self, pluginName): config_json = self.__load_pugin_info(pluginName) local_ver = config_json['version'] # 本地版本号 is_update = False message = '当前插件不支持在线更新' data = {'error': '9999', 'version': config_json['version']} if 'repository' in config_json: if 'type' in config_json['repository'] and 'url' in config_json[ 'repository']: if config_json['repository']['type'] == 'git' and config_json[ 'repository']['url'] != '': is_update = True if is_update: message = '获取远程最新版本号失败' data = {'error': '9999', 'newversion': ''} # 获取远程最新版本号 origin_ver = PlugUpdate().get_new_ver(config_json) if origin_ver != '': if mylib.versionCompare(local_ver, origin_ver) > 0: message = '远程版本已更新,可以升级' data = { 'error': '0000', 'upgrade': 1, 'newversion': origin_ver } else: message = '当前版本已经是最新版本,无需升级' data = { 'error': '0000', 'upgrade': 0, 'newversion': origin_ver } ret_arr = {'code': 20000, 'message': message, 'data': data} return json.dumps(ret_arr)
def main(self): self.SYSTEM_DIR = os.path.abspath(os.path.dirname('../')) self.zmprogress = '/tmp/zmprogress' if 'op' in self.query: op = self.query['op'] # 检查升级 if op == 'isupdate': os.system('sudo python3 '+ self.SYSTEM_DIR + '/update.py isupdate &') ret_arr = {'code': 20000,'message': '提交获取最新版本号操作成功', 'data':{'error':'0000'}} return json.dumps(ret_arr) # 获取远程版本号 elif op == 'remotever': file_str = '' data_ver = '' message = '未能获取到' data = {'error':'1001','remotever':''} if os.path.isfile(self.zmprogress): with open(self.zmprogress, 'r') as f: file_str = f.read() try: file_json = json.loads(file_str) if 'remotever' in file_json: data_ver = file_json['remotever'] local_ver = self.config['version'] if mylib.versionCompare(local_ver, data_ver)>0: data = { 'error':'0000', 'upgrade': 1, 'remotever':data_ver } message = '系统版本已经更新,可以升级' else: data = { 'error':'0000', 'upgrade': 0, 'remotever':data_ver } message = '当前系统版本已经是最新的了,不需要升级' except: pass ret_arr = {'code': 20000,'message': message, 'data':data} return json.dumps(ret_arr) # 开始升级 elif op == 'startupdate': os.system('sudo python3 '+ self.SYSTEM_DIR + '/update.py startupdate &') ret_arr = {'code': 20000,'message': '提交获取最新版本号操作成功', 'data':{'error':'0000'}} return json.dumps(ret_arr) # 升级状态 elif op == 'updatestate': data_state = '' message = '未能获取到' data = {'error': '9999'} if os.path.isfile(self.zmprogress): with open(self.zmprogress, 'r') as f: file_str = f.read() try: file_json = json.loads(file_str) if 'progress' in file_json: data_state = file_json['progress'] except: pass if data_state != '': data = { 'error': '0000', 'progress': data_state } message = '获取升级操作状态成功' ret_arr = {'code': 20000, 'message': message, 'data':data} return json.dumps(ret_arr) ret_arr = {'code': 20000,'message': '提交获取最新版本号操作成功', 'data':''} return json.dumps(ret_arr)