def isSystemProfile(self):
        """Checks if this profile is a system profile.  System profiles can 
        only be hidden, not removed completely.

        @return True, if this is a system profile.
        """
        locations = [paths.getSystemPath(paths.PROFILES)] + \
                     paths.getBundlePaths(paths.PROFILES)
        for loc in locations:
            if os.path.exists(os.path.join(loc, self.getFileName())):
                return True
        return False
    def getValue(self, id, fallbackToDefaults=True):
        """Returns the Value for the given setting. Falls back to the
        defaults profile.

        @param id Setting identifier.

        @param fallbackToDefaults If True, the value is retrieved from
        the Defaults profile if it isn't defined in this one.
        """
        defaults = profdb.defaults

        # If this is a system setting, let's consult the system
        # configuration.
        if st.isDefined(id):
            return Value(id, st.getSystemString(id))

        # First look in the Values in this profile.
        for v in self.values:
            if v.getId() == id:
                return v
                
        if id == 'game-mode':
            # We can look for the game mode in the system profile.
            sysProfFileName = os.path.join(paths.getSystemPath(paths.PROFILES), self.getFileName())
            if os.path.exists(sysProfFileName):
                try:
                    p = cfparser.FileParser(sysProfFileName)
                    while True:
                        element = p.get()
                        if element.isKey() and element.getName() == 'game-mode':
                            return Value(element.getName(), element.getValue())
                except cfparser.OutOfElements:
                    # The file ended normally.
                    pass           

        # Fall back to the Defaults profile.
        if fallbackToDefaults and self is not defaults:
            return defaults.getValue(id)
        elif self is defaults:
            # See if the setting itself has a default for this.
            try:
                setting = st.getSetting(id)
                if setting.getDefault():
                    return Value(id, str(setting.getDefault()))
            except:
                pass
            # No Value for this setting could be found.
            return None
        else:
            # A normal profile with no value for this setting.
            return None
示例#3
0
def loadAll():
    """Load all addons and manifests."""

    # Load all the installed addons in the system and user addon
    # databases.
    for repository in [paths.ADDONS] + paths.getAddonPaths():
        for name in paths.listFiles(repository):
            # Case insensitive.
            if re.search("(?i)^([^.#].*)\.(" + string.join(ao.EXTENSIONS, "|") + ")$", os.path.basename(name)):
                load(name)

    # Load all the manifests.
    for folder in [paths.getSystemPath(paths.MANIFESTS), paths.getUserPath(paths.MANIFESTS)] + paths.getAddonPaths():
        for name in paths.listFiles(folder):
            # Case insensitive.
            if paths.hasExtension("manifest", name):
                loadManifest(name)
示例#4
0
def loadAll():
    """Load all addons and manifests."""

    # Load all the installed addons in the system and user addon
    # databases.
    for repository in [paths.ADDONS] + paths.getAddonPaths():
        for name in paths.listFiles(repository):
            # Case insensitive.
            if re.search("(?i)^([^.#].*)\.(" + \
                         string.join(ao.EXTENSIONS, '|') + ")$",
                         os.path.basename(name)):
                load(name)

    # Load all the manifests.
    for folder in [paths.getSystemPath(paths.MANIFESTS),
                   paths.getUserPath(paths.MANIFESTS)] + \
                   paths.getAddonPaths():
        for name in paths.listFiles(folder):
            # Case insensitive.
            if paths.hasExtension('manifest', name):
                loadManifest(name)
def restore():
    """Reads all the profiles from disk.  Restores the currently active
    profile as well.  This function has to be called after starting
    the program before any profiles are accessed.

    System profiles that aren't present in the user's profile
    directory are copied to the user's profile directory.
    """
    global defaults
    global profiles
    global restoredActiveId

    # By default, restore selection to the Defaults profile.
    restoredActiveId = 'defaults'

    # Clear the current profile list.
    profiles = []

    systemProfilePaths = [paths.getSystemPath(paths.PROFILES)] + \
                          paths.getBundlePaths(paths.PROFILES)
    userProfilePath = paths.getUserPath(paths.PROFILES)

    # List all the system and user profiles.
    availSystem = _listProfilesIn(systemProfilePaths)
    availUser = _listProfilesIn([userProfilePath])

    # We are going to load only the profiles in the user's direcory,
    # but before that make sure that the user has an instance of each
    # system profile.
    for sysFile in availSystem:
        identifier = paths.getBase(sysFile)

        # Does this exist in the user's directory?
        gotIt = False
        for userFile in availUser:
            if paths.getBase(userFile) == identifier:
                gotIt = True
                break

        if not gotIt:
            # Since the system profile does not exist on the user,
            # copy it to the user profile directory.
            shutil.copyfile(
                sysFile,
                os.path.join(userProfilePath, os.path.basename(sysFile)))

    # Find every profile in system's and user's profile directories.
    # Files in the user's directory augment the files in the system
    # directory.
    for name in _listProfilesIn([userProfilePath]):
        load(os.path.join(userProfilePath, name), False)
    logger.show()

    defaults = get('defaults')

    if defaults is None:
        # Recreate the Defaults profile.
        load(os.path.join(systemProfilePath, "defaults.prof"), False)
        defaults = get('defaults')
        logger.show()

    # Set the default language.
    lang = defaults.getValue('language')
    if lang:
        language.change(lang.getValue())

    # Send profile-loaded notifications.
    for p in profiles:
        if not p.isHidden():
            events.send(events.ProfileNotify(p))

    # Restore the previously active profile.
    prof = get(restoredActiveId)
    if prof:
        setActive(prof)
    else:
        setActive(defaults)
示例#6
0
def restore():
    """Reads all the profiles from disk.  Restores the currently active
    profile as well.  This function has to be called after starting
    the program before any profiles are accessed.

    System profiles that aren't present in the user's profile
    directory are copied to the user's profile directory.
    """
    global defaults
    global profiles
    global restoredActiveId

    # By default, restore selection to the Defaults profile.
    restoredActiveId = 'defaults'

    # Clear the current profile list.
    profiles = []

    systemProfilePaths = [paths.getSystemPath(paths.PROFILES)] + \
                          paths.getBundlePaths(paths.PROFILES)
    userProfilePath = paths.getUserPath(paths.PROFILES)

    # List all the system and user profiles.
    availSystem = _listProfilesIn(systemProfilePaths)
    availUser = _listProfilesIn([userProfilePath])

    # We are going to load only the profiles in the user's direcory,
    # but before that make sure that the user has an instance of each
    # system profile.
    for sysFile in availSystem:
        identifier = paths.getBase(sysFile)

        # Does this exist in the user's directory?
        gotIt = False
        for userFile in availUser:
            if paths.getBase(userFile) == identifier:
                gotIt = True
                break

        if not gotIt:
            # Since the system profile does not exist on the user,
            # copy it to the user profile directory.
            shutil.copyfile(sysFile,
                            os.path.join(userProfilePath,
                                         os.path.basename(sysFile)))

    # Find every profile in system's and user's profile directories.
    # Files in the user's directory augment the files in the system
    # directory.
    for name in _listProfilesIn([userProfilePath]):
        load(os.path.join(userProfilePath, name), False)
    logger.show()

    defaults = get('defaults')

    if defaults is None:
        # Recreate the Defaults profile.
        load(os.path.join(systemProfilePath, "defaults.prof"), False)
        defaults = get('defaults')
        logger.show()

    # Set the default language.
    lang = defaults.getValue('language')
    if lang:
        language.change(lang.getValue())

    # Send profile-loaded notifications.
    for p in profiles:
        if not p.isHidden():
            events.send(events.ProfileNotify(p))

    # Restore the previously active profile.
    prof = get(restoredActiveId)
    if prof:
        setActive(prof)
    else:
        setActive(defaults)