Example #1
0
        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
Example #2
0
 def __load_categories_expanded_dict(self, cat_exp_dict):
     cache_dir = self.__get_cache_dir()
     if not cache_dir:
         return
     catexs = nongui_misc.read_cache_file(
         os.path.join(cache_dir, "pm_cat_exp.cpl"))
     for catex in catexs:
         name = catex.get("name")
         path1 = catex.get("path1")
         if path1 != -1:
             cat_exp_dict[name, (path1, )] = True
Example #3
0
 def __load_categories_expanded_dict(self, cat_exp_dict):
         cache_dir = self.__get_cache_dir()
         if not cache_dir:
                 return
         catexs = nongui_misc.read_cache_file(
             os.path.join(cache_dir, "pm_cat_exp.cpl"))
         for catex in catexs:
                 name = catex.get("name")
                 path1 = catex.get("path1")
                 if path1 != -1:
                         cat_exp_dict[name, (path1,)] = True
Example #4
0
 def __load_categories_active_dict(self, cat_ac_dict):
     cache_dir = self.__get_cache_dir()
     if not cache_dir:
         return
     catacs = nongui_misc.read_cache_file(
         os.path.join(cache_dir, "pm_cat_ac.cpl"))
     for catac in catacs:
         name = catac.get("name")
         path1 = catac.get("path1")
         path2 = catac.get("path2")
         if path1 != -1 and path2 != -1:
             cat_ac_dict[name] = (path1, path2)
         elif path1 != -1:
             cat_ac_dict[name] = (path1, )
Example #5
0
 def __load_categories_active_dict(self, cat_ac_dict):
         cache_dir = self.__get_cache_dir()
         if not cache_dir:
                 return
         catacs = nongui_misc.read_cache_file(
             os.path.join(cache_dir, "pm_cat_ac.cpl"))
         for catac in catacs:
                 name = catac.get("name")
                 path1 = catac.get("path1")
                 path2 = catac.get("path2")
                 if path1 != -1 and path2 != -1:
                         cat_ac_dict[name] = (path1, path2)
                 elif path1 != -1:
                         cat_ac_dict[name] = (path1,)
Example #6
0
    def __load_search_completion_info(self, completion_list):
        cache_dir = self.__get_cache_dir()
        if not cache_dir:
            return
        texts = []
        try:
            texts = nongui_misc.read_cache_file(
                os.path.join(cache_dir, ".__search__completion.cpl"))
        except IOError:
            return gtk.ListStore(str)

        txt_count = 0
        for txt in texts:
            txt_val = txt.get("text")
            text = [txt_val]
            completion_list.insert(txt_count, text)
            txt_count += 1
Example #7
0
        def __load_search_completion_info(self, completion_list):
                cache_dir = self.__get_cache_dir()
                if not cache_dir:
                        return
                texts = []
                try:
                        texts = nongui_misc.read_cache_file(
                            os.path.join(cache_dir, ".__search__completion.cpl"))
                except IOError:
                        return gtk.ListStore(str)

                txt_count = 0
                for txt in texts:
                        txt_val = txt.get("text")
                        text = [ txt_val ]
                        completion_list.insert(txt_count, text)
                        txt_count += 1
Example #8
0
    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