def orderCompare(a, b):
            """Compare two addon identifiers.

            @param a Addon identifier.

            @param b Addon identifier.

            @return -1, if a comes before b.  1, if b comes before a.
            """
            # First check if order of these two addons is defined in
            # this profile.
            order = self.getLoadOrder()
            if a in order and b in order:
                # Both of them are in this order.
                return cmp(order.index(a), order.index(b))

            # Check the Defaults profile.
            if self is not profdb.defaults:
                order = profdb.defaults.getLoadOrder()
                if a in order and b in order:
                    # Both of them are in this order.
                    return cmp(order.index(a), order.index(b))

            # Compare the priority classes, then.
            return cmp(aodb.get(a).getPriority(), aodb.get(b).getPriority())
 def dontUseAddon(self, identifier):
     """Higher-level addon detaching.  Takes care of the proper
     handling of defaults."""
     
     if aodb.get(identifier).isOptIn(self):
         self.removeAddon(identifier)
     else:
         self.addAddon(identifier)
Beispiel #3
0
    def loadAll(self, path, role):
        """Load all addons on the given path."""

        if not os.path.exists(path):
            return

        for fileName in os.listdir(path):
            try:
                ident = aodb.load(os.path.join(path, fileName), self)
                role.append(ident)

                # Using any parts of an addon requires that the box
                # itself is marked for loading.
                aodb.get(ident).addKeywords(REQUIRES, [self.getId()])

            except aodb.LoadError, x:
                # Attempted to load a file that is not an addon.
                # Just ignore; boxes can contain all kinds of stuff.
                pass

            except Exception, x:
                # Perhaps it wasn't an addon?
                traceback.print_exc()
    def loadAll(self, path, role):
        """Load all addons on the given path."""

        if not os.path.exists(path):
            return

        for fileName in os.listdir(path):
            try:
                ident = aodb.load(os.path.join(path, fileName), self)
                role.append(ident)

                # Using any parts of an addon requires that the box
                # itself is marked for loading.
                aodb.get(ident).addKeywords(REQUIRES, [self.getId()])

            except aodb.LoadError, x:
                # Attempted to load a file that is not an addon.
                # Just ignore; boxes can contain all kinds of stuff.
                pass

            except Exception, x:
                # Perhaps it wasn't an addon?
                traceback.print_exc()
    def getFinalAddons(self):
        """The final addons of a profile are the ones that will be
        used when a game is launched.  The returned list is sorted
        based on the load order that applies to the profile.

        For the Defaults profile, the final addons include ALL the
        existing addons.

        @return A list of addon identifiers, in the actual load order.
        """
        if self is profdb.defaults:
            # Return all existing addons.
            finalAddons = map(lambda a: a.getId(), aodb.getAddons())

        else:
            usedAddons = self.getUsedAddons()

            finalAddons = []

            # Any boxes?
            for ident in usedAddons:
                addon = aodb.get(ident)

                if addon.getBox():
                    # If the box hasn't been selected by the user, forget it.
                    if addon.getBox().getId() not in usedAddons:
                        continue
                
                if addon.isBox():
                    # Also include the required parts of the addons.
                    finalAddons += addon.getRequiredParts()

                finalAddons.append(ident)

        # Apply load order.
        self.sortByLoadOrder(finalAddons)

        return finalAddons                
    def getUsedAddons(self):
        """Returns the list of all addons that will be used with the
        profile.  This includes the addons that have been attached to
        the Defaults profile.  If a addon is attached to both Defaults
        and this profile, it won't be used (exclusion).

        @return An array of addon identifiers.
        """
        if self is profdb.getDefaults():
            usedAddons = self.getAddons()
        else:
            usedAddons = []

            # Decide which addons are actually used.  The ones that are
            # both in defaultAddons and profileAddons are NOT used.
            # ((P union D) - (P intersection D))
            for a in self.getAddons():
                usedAddons.append(a)

            for d in profdb.getDefaults().getAddons():
                if d in self.getAddons():
                    # This addon is in both the Defaults and this profile,
                    # don't use it.
                    usedAddons.remove(d)
                else:
                    usedAddons.append(d)

        # Any inversed addons that should be used?
        for addon in aodb.getAddons():
            if addon.isInversed():
                if addon.getId() not in usedAddons:
                    usedAddons.append(addon.getId())
                else:
                    usedAddons.remove(addon.getId())
            
        # Filter out the incompatible ones.
        return [a for a in usedAddons if aodb.get(a).isCompatibleWith(self)]