diff --git a/UpdateManager/Core/UpdateList.py b/UpdateManager/Core/UpdateList.py index 186eead..ee57a33 100644 --- a/UpdateManager/Core/UpdateList.py +++ b/UpdateManager/Core/UpdateList.py @@ -491,8 +491,7 @@ class UpdateList(): return app_groups + pkg_groups - def _make_json(self,cache,pkgs_install, pkgs_upgrade, pkgs_remove): - + def _make_json(self,cache,pkgs_install, pkgs_upgrade, pkgs_remove): try: files = os.listdir(self.input_config_path) #获得文件夹中所有文件的名称列表 for file in files: @@ -502,13 +501,14 @@ class UpdateList(): data = json.load(f) output_json = {} + output_config_name = self.output_config_path + '/' + data['package'] + '_output.json' install_pkgs_list = data['install_list'] upgrade_pkgs_list = data['upgrade_list'] hold_pkgs_list = data['hold_list'] remove_pkgs_list = data['remove_list'] - #生成需要升级的包的JSON内容 + #1、生成需要升级的包的JSON内容 #进行交集 查找两个列表同时存在的 upgrade_intersection_pkgs = list(set(pkgs_upgrade) & set(upgrade_pkgs_list)) #在总升级列表中移除这些包 @@ -530,7 +530,7 @@ class UpdateList(): upgrade_pkgs_json.update({"total_size":humanize_size(total_size)}) - #生成安装的软件列表 + #2、生成安装的软件列表 install_pkgs_json = {} total_size = 0 for pkg_name in install_pkgs_list: @@ -540,35 +540,51 @@ class UpdateList(): #如果这个包已经安装则不计算在内 if pkg.is_installed: continue - + # 标记为自动安装 + pkg.mark_auto() + #获取下载大小 size = getattr(pkg.candidate, "size", 0) total_size = total_size + size install_pkgs_json.update({pkg_name:{"size":size}}) except Exception as e: pass - # logging.DEBUG(e) install_pkgs_json.update({"total_size":humanize_size(total_size)}) - #添加一些基础信息 + #3、检索hold_pkgs 将包标记为mark_keep 不进行升级或安装 + for pkg in hold_pkgs_list: + try: + pkg = cache[pkg_name] + + #未安装的话直接跳过 + if not pkg.is_installed: + continue + # 标记为自动安装 + pkg.mark_keep() + except Exception as e: + pass + + #4、添加一些基础信息 output_json.update({"package":data['package']}) output_json.update({"version":data['version']}) output_json.update({"name":data['name']}) output_json.update({"description":data['description']}) output_json.update({"icon":data['icon']}) - #添加升级的内容 + #5、添加升级的内容 output_json.update({"upgrade_list":upgrade_pkgs_json}) output_json.update({"install_list":install_pkgs_json}) output_json.update({"hold_list":hold_pkgs_list}) output_json.update({"remove_list":remove_pkgs_list}) - with open( self.output_config_path + '/' + data['package'] + '_output.json', 'w', encoding='utf-8') as f: + #6 产生JSON文件 + with open(output_config_name, 'w', encoding='utf-8') as f: json.dump(output_json, f, ensure_ascii=False, indent=4) - + logging.info("Generate Jsonfile(%s) to complete... ",output_config_name) else: pass except Exception as e: + logging.warning("Generate Jsonfile(%s) to failed... ",output_config_name) logging.error(e) @@ -581,23 +597,27 @@ class UpdateList(): ''' self.distUpgradeWouldDelete = cache.saveDistUpgrade() - #安装JSON分组配置文件包 安装完毕会重新调start_available --> update --> here + #安装JSON分组配置文件包 安装完毕会重新调start_available --> update --> here 安装失败就直接退出不会进行下面的操作 try: pkg_json = cache[self.GROUPS_JSON_PKG] #是否安装 if pkg_json.is_installed: #是否可升级 if pkg_json.is_upgradable: - logging.info('groups JSON Config start upgrading...') + logging.info("groups JSON ConfigPkgs(%s) start upgrading...",self.GROUPS_JSON_PKG) start_install_alone(pkgs_install = [],pkgs_upgrade = [self.GROUPS_JSON_PKG],pkgs_remove = []) + else: + logging.info("ConfigPkgs(%s) No need to upgrade...",self.GROUPS_JSON_PKG) else: - logging.info('groups JSON Config start new installing...') + logging.info("groups JSON ConfigPkgs(%s) start new installing...",self.GROUPS_JSON_PKG) start_install_alone(pkgs_install = [self.GROUPS_JSON_PKG],pkgs_upgrade = [],pkgs_remove = []) #FIXME: 错误处理未做 except Exception as e: + logging.warning("groups JSON ConfigPkgs(%s) install failed...",self.GROUPS_JSON_PKG) logging.error(e) + return False - # Find all upgradable packages + #查找所有可升级的包 for pkg in cache: try: if pkg.marked_install: @@ -611,14 +631,17 @@ class UpdateList(): self.pkgs_remove.append(pkg.name) except Exception as e: logging.error(e) + return False + logging.info("Find all upgradeable packages finished...") self._make_json(cache,self.pkgs_install,self.pkgs_upgrade,self.pkgs_remove) + return True #FIXME: 目前此功能不使用 但是以此按应用进行分组是更好的展示升级列表的方式 # self.update_groups = self._make_groups(cache, self.pkgs_upgrade, # eventloop_callback) - + # fu = filter.UpdateListFilterCache("/") @@ -635,6 +658,4 @@ class UpdateList(): # #blacklist_filter # blacklist_filter_pkgs = fu.is_pkgname_in_blacklist(whitelist_filter_upgrade_pkgs) - # print("blacklist_filter_pkgs: %s"%" ".join([i.name for i in blacklist_filter_pkgs])) - - + # print("blacklist_filter_pkgs: %s"%" ".join([i.name for i in blacklist_filter_pkgs])) \ No newline at end of file diff --git a/UpdateManager/UpdateManager.py b/UpdateManager/UpdateManager.py index 0d8be77..9ed90d6 100644 --- a/UpdateManager/UpdateManager.py +++ b/UpdateManager/UpdateManager.py @@ -169,7 +169,7 @@ class UpdateManager(): self.update_list = UpdateList(self) try: - self.update_list.update(self.cache,self.start_install_alone) + _success = self.update_list.update(self.cache,self.start_install_alone) except SystemError as e: header = _("Could not calculate the upgrade") desc = _("An unresolvable problem occurred while " diff --git a/UpdateManager/backend/InstallBackendAptdaemon.py b/UpdateManager/backend/InstallBackendAptdaemon.py index b567641..3117281 100644 --- a/UpdateManager/backend/InstallBackendAptdaemon.py +++ b/UpdateManager/backend/InstallBackendAptdaemon.py @@ -101,12 +101,12 @@ class InstallBackendAptdaemon(InstallBackend): @inline_callbacks def _show_transaction(self, trans, action, header, show_details): - trans.connect("status-details-changed", self._on_details_changed) + # trans.connect("status-details-changed", self._on_details_changed) #状态改变的时候的回调函数 trans.connect("status-changed", self._on_status_changed) #update 更新完成的时候的回调 trans.connect("finished", self._on_finished, action) - trans.connect("medium-required", self._on_medium_required) + # trans.connect("medium-required", self._on_medium_required) # trans.connect("progress-changed", self._on_progress_changed) # trans.connect("download-changed", self._on_download_changed)