def __check_last_refresh(self): """Reads the cache if possible; if it isn't stale or corrupt or out of date, return whether updates are available. Otherwise return 'undetermined'.""" cache_dir = nongui_misc.get_cache_dir(self.api_obj) if not cache_dir: return enumerations.UPDATES_UNDETERMINED try: info = nongui_misc.read_cache_file(os.path.join( cache_dir, CACHE_NAME + '.cpl')) if len(info) == 0: logger.debug("No cache") return enumerations.UPDATES_UNDETERMINED # Non-portable API used; pylint: disable=E0901 utsname = os.uname() # pylint: disable=E1103 if info.get("version") != CACHE_VERSION: logger.debug("Cache version mismatch: %s" % (info.get("version") + " " + CACHE_VERSION)) return enumerations.UPDATES_UNDETERMINED if info.get("os_release") != utsname[2]: logger.debug("OS release mismatch: %s" % (info.get("os_release") + " " + utsname[2])) return enumerations.UPDATES_UNDETERMINED if info.get("os_version") != utsname[3]: logger.debug("OS version mismatch: %s" % (info.get("os_version") + " " + utsname[3])) return enumerations.UPDATES_UNDETERMINED old_publishers = info.get("publishers") count = 0 for p in self.api_obj.get_publishers(): if p.disabled: continue if old_publishers.get(p.prefix, -1) != \ p.last_refreshed: return enumerations.UPDATES_UNDETERMINED count += 1 if count != len(old_publishers): return enumerations.UPDATES_UNDETERMINED n_updates = n_installs = n_removes = 0 if info.get("updates_available"): n_updates = info.get("updates") n_installs = info.get("installs") n_removes = info.get("removes") # pylint: enable=E1103 if self.check_cache_only: print "n_updates: %d" % n_updates print "n_installs: %d" % n_installs print "n_removes: %d" % n_removes if (n_updates + n_installs + n_removes) > 0: return enumerations.UPDATES_AVAILABLE else: return enumerations.NO_UPDATES_AVAILABLE except (UnpicklingError, IOError): return enumerations.UPDATES_UNDETERMINED
def __dump_updates_available(self, stuff_to_do): cache_dir = nongui_misc.get_cache_dir(self.api_obj) if not cache_dir: return publisher_list = {} for p in self.api_obj.get_publishers(): if p.disabled: continue publisher_list[p.prefix] = p.last_refreshed n_installs = 0 n_removes = 0 n_updates = 0 plan_desc = self.api_obj.describe() if plan_desc: plan = plan_desc.get_changes() for pkg_plan in plan: orig = pkg_plan[0] dest = pkg_plan[1] if orig and dest: n_updates += 1 elif not orig and dest: n_installs += 1 elif orig and not dest: n_removes += 1 dump_info = {} dump_info["version"] = CACHE_VERSION dump_info["os_release"] = os.uname()[2] dump_info["os_version"] = os.uname()[3] dump_info["updates_available"] = stuff_to_do dump_info["publishers"] = publisher_list dump_info["updates"] = n_updates dump_info["installs"] = n_installs dump_info["removes"] = n_removes try: nongui_misc.dump_cache_file( os.path.join(cache_dir, CACHE_NAME + '.cpl'), dump_info) except IOError, e: err = str(e) if debug: print >> sys.stderr, "Failed to dump cache: %s" % err logger.error(err)
def __dump_updates_available(self, stuff_to_do): """Record update information to the cache file.""" cache_dir = nongui_misc.get_cache_dir(self.api_obj) if not cache_dir: return publisher_list = {} for p in self.api_obj.get_publishers(): if p.disabled: continue publisher_list[p.prefix] = p.last_refreshed n_installs = 0 n_removes = 0 n_updates = 0 plan_desc = self.api_obj.describe() if plan_desc: plan = plan_desc.get_changes() for (orig, dest) in plan: if orig and dest: n_updates += 1 elif not orig and dest: n_installs += 1 elif orig and not dest: n_removes += 1 dump_info = {} dump_info["version"] = CACHE_VERSION # Non-portable API used; pylint: disable=E0901 dump_info["os_release"] = os.uname()[2] dump_info["os_version"] = os.uname()[3] dump_info["updates_available"] = stuff_to_do dump_info["publishers"] = publisher_list dump_info["updates"] = n_updates dump_info["installs"] = n_installs dump_info["removes"] = n_removes try: nongui_misc.dump_cache_file(os.path.join( cache_dir, CACHE_NAME + '.cpl'), dump_info) except IOError, e: logger.error("Failed to dump cache: %s" % e)
def __get_cache_dir(self): return nongui_misc.get_cache_dir(self.api_o)
def __check_last_refresh(self): cache_dir = nongui_misc.get_cache_dir(self.api_obj) if not cache_dir: return enumerations.UPDATES_UNDETERMINED try: info = nongui_misc.read_cache_file( os.path.join(cache_dir, CACHE_NAME + '.cpl')) if len(info) == 0: if debug: print >> sys.stderr, "No cache" return enumerations.UPDATES_UNDETERMINED # pylint: disable-msg=E1103 if info.get("version") != CACHE_VERSION: if debug: print >> sys.stderr, "Cache version mismatch: %s"\ % (info.get("version") + " " + CACHE_VERSION) return enumerations.UPDATES_UNDETERMINED if info.get("os_release") != os.uname()[2]: if debug: print >> sys.stderr, "OS release mismatch: %s"\ % (info.get("os_release") + " " + \ os.uname()[2]) return enumerations.UPDATES_UNDETERMINED if info.get("os_version") != os.uname()[3]: if debug: print >> sys.stderr, "OS version mismatch: %s"\ % (info.get("os_version") + " " + \ os.uname()[3]) return enumerations.UPDATES_UNDETERMINED old_publishers = info.get("publishers") count = 0 for p in self.api_obj.get_publishers(): if p.disabled: continue try: if old_publishers[p.prefix] != p.last_refreshed: return enumerations.UPDATES_UNDETERMINED except KeyError: return enumerations.UPDATES_UNDETERMINED count += 1 if count != len(old_publishers): return enumerations.UPDATES_UNDETERMINED n_updates = 0 n_installs = 0 n_removes = 0 if info.get("updates_available"): n_updates = info.get("updates") n_installs = info.get("installs") n_removes = info.get("removes") # pylint: enable-msg=E1103 if self.check_cache_only: print "n_updates: %d\nn_installs: %d\nn_removes: %d" % \ (n_updates, n_installs, n_removes) if (n_updates + n_installs + n_removes) > 0: return enumerations.UPDATES_AVAILABLE else: return enumerations.NO_UPDATES_AVAILABLE except (UnpicklingError, IOError): return enumerations.UPDATES_UNDETERMINED