From 28456b4121fbf308ea816c556c03bfbaf0d0b0df Mon Sep 17 00:00:00 2001 From: Fabio Erculiani Date: Mon, 7 Feb 2011 14:07:42 +0100 Subject: [PATCH] [entropy.client] drop FileUpdates attribute, replace with Client.PackageFileUpdates() loader --- client/text_configuration.py | 54 +++++++++---------- client/text_ui.py | 4 +- libraries/entropy/client/interfaces/client.py | 4 -- .../entropy/client/interfaces/loaders.py | 12 +++++ .../entropy/client/interfaces/package.py | 3 +- libraries/entropy/server/interfaces/main.py | 3 +- sulfur/src/sulfur/__init__.py | 14 +++-- sulfur/src/sulfur/events.py | 33 +++++++----- 8 files changed, 75 insertions(+), 52 deletions(-) diff --git a/client/text_configuration.py b/client/text_configuration.py index cad4135b0..57e1e68a3 100644 --- a/client/text_configuration.py +++ b/client/text_configuration.py @@ -71,10 +71,11 @@ def update(entropy_client, cmd = None): if cmd != None: docmd = True + file_updates = entropy_client.PackageFileUpdates() while True: print_info(brown(" @@ ") + \ darkgreen("%s ..." % (_("Scanning filesystem"),))) - scandata = entropy_client.FileUpdates.scan(dcache = cache_status) + scandata = file_updates.scan(dcache = cache_status) if cache_status: for x in scandata: print_info("("+blue(str(x))+") "+red(" %s: " % (_("file"),) ) + \ @@ -104,8 +105,8 @@ def update(entropy_client, cmd = None): # automerge files asking one by one for key in keys: if not os.path.isfile(etpConst['systemroot']+scandata[key]['source']): - entropy_client.FileUpdates.ignore(key) - scandata = entropy_client.FileUpdates.scan() + file_updates.ignore(key) + scandata = file_updates.scan() continue print_info(darkred("%s: " % (_("Configuration file"),) ) + \ darkgreen(etpConst['systemroot']+scandata[key]['destination'])) @@ -121,8 +122,8 @@ def update(entropy_client, cmd = None): brown(etpConst['systemroot'] + \ scandata[key]['destination'])) - entropy_client.FileUpdates.merge(key) - scandata = entropy_client.FileUpdates.scan() + file_updates.merge(key) + scandata = file_updates.scan() break @@ -130,11 +131,10 @@ def update(entropy_client, cmd = None): for key in keys: if not os.path.isfile(etpConst['systemroot']+scandata[key]['source']): - - entropy_client.FileUpdates.ignore(key) - scandata = entropy_client.FileUpdates.scan() - + file_updates.ignore(key) + scandata = file_updates.scan() continue + print_info(darkred("%s: " % (_("Configuration file"),) ) + \ darkgreen(etpConst['systemroot']+scandata[key]['destination'])) if cmd == -7: @@ -145,8 +145,8 @@ def update(entropy_client, cmd = None): print_info(darkred("%s " % (_("Discarding"),) ) + \ darkgreen(etpConst['systemroot']+scandata[key]['source'])) - entropy_client.FileUpdates.remove(key) - scandata = entropy_client.FileUpdates.scan() + file_updates.remove(key) + scandata = file_updates.scan() break @@ -156,18 +156,18 @@ def update(entropy_client, cmd = None): # do files exist? if not os.path.isfile(etpConst['systemroot']+scandata[cmd]['source']): - entropy_client.FileUpdates.ignore(cmd) - scandata = entropy_client.FileUpdates.scan() + file_updates.ignore(cmd) + scandata = file_updates.scan() continue if not os.path.isfile(etpConst['systemroot']+scandata[cmd]['destination']): print_info(darkred("%s: " % (_("Automerging file"),) ) + \ darkgreen(etpConst['systemroot']+scandata[cmd]['source'])) - entropy_client.FileUpdates.merge(cmd) - scandata = entropy_client.FileUpdates.scan() - + file_updates.merge(cmd) + scandata = file_updates.scan() continue + # end check diff = showdiff(etpConst['systemroot']+scandata[cmd]['destination'], @@ -176,8 +176,8 @@ def update(entropy_client, cmd = None): print_info(darkred("%s " % (_("Automerging file"),) ) + \ darkgreen(etpConst['systemroot']+scandata[cmd]['source'])) - entropy_client.FileUpdates.merge(cmd) - scandata = entropy_client.FileUpdates.scan() + file_updates.merge(cmd) + scandata = file_updates.scan() continue @@ -205,8 +205,8 @@ def update(entropy_client, cmd = None): scandata[cmd]['destination']) + darkred(" %s " % (_("with"),) ) + \ darkgreen(etpConst['systemroot'] + scandata[cmd]['source'])) - entropy_client.FileUpdates.merge(cmd) - scandata = entropy_client.FileUpdates.scan() + file_updates.merge(cmd) + scandata = file_updates.scan() comeback = True break @@ -217,8 +217,8 @@ def update(entropy_client, cmd = None): scandata[cmd]['source']) ) - entropy_client.FileUpdates.remove(cmd) - scandata = entropy_client.FileUpdates.scan() + file_updates.remove(cmd) + scandata = file_updates.scan() comeback = True break @@ -246,8 +246,8 @@ def update(entropy_client, cmd = None): print_info(darkred("%s " % (_("Automerging file"),) ) + \ darkgreen(scandata[cmd]['source'])) - entropy_client.FileUpdates.merge(cmd) - scandata = entropy_client.FileUpdates.scan() + file_updates.merge(cmd) + scandata = file_updates.scan() comeback = True break @@ -270,8 +270,8 @@ def update(entropy_client, cmd = None): os.rename(merge_outcome_path, source) except OSError: shutil.move(merge_outcome_path, source) - entropy_client.FileUpdates.merge(cmd) - scandata = entropy_client.FileUpdates.scan() + file_updates.merge(cmd) + scandata = file_updates.scan() comeback = True break @@ -380,7 +380,7 @@ def interactive_merge(source, destination): ''' def confinfo(entropy_client): print_info(brown(" @@ ")+darkgreen(_("These are the files that would be updated:"))) - data = entropy_client.FileUpdates.scan(dcache = False) + data = entropy_client.PackageFileUpdates().scan(dcache = False) counter = 0 for item in data: counter += 1 diff --git a/client/text_ui.py b/client/text_ui.py index f02fac696..23161b9a0 100644 --- a/client/text_ui.py +++ b/client/text_ui.py @@ -289,10 +289,10 @@ def show_config_files_to_update(entropy_client): blue(_("Scanning configuration files to update")), back = True) try: + file_updates = entropy_client.PackageFileUpdates() while True: try: - scandata = entropy_client.FileUpdates.scan( - dcache = True, quiet = True) + scandata = file_updates.scan(dcache = True, quiet = True) break except KeyboardInterrupt: continue diff --git a/libraries/entropy/client/interfaces/client.py b/libraries/entropy/client/interfaces/client.py index 9a4596fa8..4bc3f041d 100644 --- a/libraries/entropy/client/interfaces/client.py +++ b/libraries/entropy/client/interfaces/client.py @@ -616,7 +616,6 @@ class Client(Singleton, TextInterface, LoadersMixin, CacheMixin, CalculatorsMixi self.sys_settings_client_plugin_id = \ etpConst['system_settings_plugins_ids']['client_plugin'] - self.FileUpdates = None self._enabled_repos = [] self.UGC = None self.safe_mode = 0 @@ -647,9 +646,6 @@ class Client(Singleton, TextInterface, LoadersMixin, CacheMixin, CalculatorsMixi self._cacher = EntropyCacher() - from entropy.client.misc import FileUpdates - self.FileUpdates = FileUpdates(self) - if noclientdb in (False, 0): self.noclientdb = False elif noclientdb in (True, 1): diff --git a/libraries/entropy/client/interfaces/loaders.py b/libraries/entropy/client/interfaces/loaders.py index d81695d9d..21c4c61b2 100644 --- a/libraries/entropy/client/interfaces/loaders.py +++ b/libraries/entropy/client/interfaces/loaders.py @@ -26,10 +26,12 @@ class LoadersMixin: from entropy.client.interfaces.repository import Repository from entropy.client.interfaces.package import Package from entropy.client.interfaces.sets import Sets + from entropy.client.misc import FileUpdates self.__package_loader = Package self.__repository_loader = Repository self.__trigger_loader = Trigger self.__sets_loader = Sets + self.__package_files_loader = FileUpdates def Sets(self): """ @@ -117,6 +119,16 @@ class LoadersMixin: """ return self.__package_loader(self) + def PackageFileUpdates(self): + """ + Load Entropy Package Files instance object. Through this interface, + you can scan for package files updates (usually configuration files) + and let user merge, remove them interactively. + + @rtype: entropy.client.misc.FileUpdates + """ + return self.__package_files_loader(self) + def Settings(self): """ Return SystemSettings instance object diff --git a/libraries/entropy/client/interfaces/package.py b/libraries/entropy/client/interfaces/package.py index 6647626b6..aa4de499a 100644 --- a/libraries/entropy/client/interfaces/package.py +++ b/libraries/entropy/client/interfaces/package.py @@ -2482,7 +2482,8 @@ class Package: if protected: # add to disk cache - self._entropy.FileUpdates.add(tofile, quiet = True) + file_updates = self._entropy.PackageFileUpdates() + file_updates.add(tofile, quiet = True) return 0 diff --git a/libraries/entropy/server/interfaces/main.py b/libraries/entropy/server/interfaces/main.py index 039df7f01..398ec3060 100644 --- a/libraries/entropy/server/interfaces/main.py +++ b/libraries/entropy/server/interfaces/main.py @@ -4824,7 +4824,8 @@ class Server(Client): back = True ) # scanning for config files not updated - scandata = self.FileUpdates.scan(dcache = False) + file_updates = self.PackageFileUpdates() + scandata = file_updates.scan(dcache = False) if scandata: self.output( "[%s] %s" % ( diff --git a/sulfur/src/sulfur/__init__.py b/sulfur/src/sulfur/__init__.py index 25a8a8e18..fc5e21f61 100644 --- a/sulfur/src/sulfur/__init__.py +++ b/sulfur/src/sulfur/__init__.py @@ -226,6 +226,12 @@ class SulfurApplication(Controller, SulfurApplicationEventsMixin): self.gtk_loop() gobject.idle_add(_pkg_install) + def _get_file_updates(self): + # delayed loading, use cache. + if not hasattr(self, "_file_updates"): + self._file_updates = self._entropy.PackageFileUpdates() + return self._file_updates + def quit(self, widget = None, event = None, sysexit = 0): def do_kill(pid): @@ -1384,7 +1390,8 @@ class SulfurApplication(Controller, SulfurApplicationEventsMixin): def _populate_files_update(self): # load filesUpdate interface and fill self.filesView with self._privileges: - cached = self._entropy.FileUpdates.scan(quiet = True) + file_updates = self._get_file_updates() + cached = file_updates.scan(quiet = True) if cached: self.filesView.populate(cached) @@ -2105,10 +2112,11 @@ class SulfurApplication(Controller, SulfurApplicationEventsMixin): if direct_install_matches is None: direct_install_matches = [] self.show_progress_bars() + file_updates = self._get_file_updates() def do_file_updates_check(): - self._entropy.FileUpdates.scan(dcache = False, quiet = True) - fs_data = self._entropy.FileUpdates.scan() + file_updates.scan(dcache = False, quiet = True) + fs_data = file_updates.scan() if fs_data: if len(fs_data) > 0: switch_back_page = 'filesconf' diff --git a/sulfur/src/sulfur/events.py b/sulfur/src/sulfur/events.py index 4c4195e22..2a8b394af 100644 --- a/sulfur/src/sulfur/events.py +++ b/sulfur/src/sulfur/events.py @@ -175,46 +175,50 @@ class SulfurApplicationEventsMixin: if not identifier: return True with self._privileges: + file_updates = self._get_file_updates() try: - self._entropy.FileUpdates.remove(identifier) + file_updates.remove(identifier) except KeyError: pass # cope with multithreading requests - self.filesView.populate(self._entropy.FileUpdates.scan()) + self.filesView.populate(file_updates.scan()) def on_filesMerge_clicked( self, widget ): identifier, source, dest = self._get_Edit_filename() if not identifier: return True with self._privileges: + file_updates = self._get_file_updates() try: - self._entropy.FileUpdates.merge(identifier) + file_updates.merge(identifier) except KeyError: pass # code with multithreaded requests - self.filesView.populate(self._entropy.FileUpdates.scan()) + self.filesView.populate(file_updates.scan()) def on_mergeFiles_clicked( self, widget ): with self._privileges: - self._entropy.FileUpdates.scan(dcache = True) - keys = list(self._entropy.FileUpdates.scan().keys()) + file_updates = self._get_file_updates() + file_updates.scan(dcache = True) + keys = list(file_updates.scan().keys()) for key in keys: try: - self._entropy.FileUpdates.merge(key) + file_updates.merge(key) # it's cool watching it runtime except KeyError: pass - self.filesView.populate(self._entropy.FileUpdates.scan()) + self.filesView.populate(file_updates.scan()) def on_deleteFiles_clicked( self, widget ): with self._privileges: - self._entropy.FileUpdates.scan(dcache = True) - keys = list(self._entropy.FileUpdates.scan().keys()) + file_updates = self._get_file_updates() + file_updates.scan(dcache = True) + keys = list(file_updates.scan().keys()) for key in keys: try: - self._entropy.FileUpdates.remove(key) + file_updates.remove(key) # it's cool watching it runtime except KeyError: pass - self.filesView.populate(self._entropy.FileUpdates.scan()) + self.filesView.populate(file_updates.scan()) def on_filesEdit_clicked( self, widget ): identifier, source, dest = self._get_Edit_filename() @@ -257,8 +261,9 @@ class SulfurApplicationEventsMixin: def on_filesViewRefresh_clicked( self, widget ): with self._privileges: - self._entropy.FileUpdates.scan(dcache = False) - self.filesView.populate(self._entropy.FileUpdates.scan()) + file_updates = self._get_file_updates() + file_updates.scan(dcache = False) + self.filesView.populate(file_updates.scan()) def on_shiftUp_clicked( self, widget ): idx, repoid, iterdata = self._get_selected_repo_index()