Ejemplo n.º 1
0
    def toggle_portable_config(*args):
        """ Create or remove a configuration file for portable installs.

        The portable install file will be used by default, and deleting it causes the config
        to fall back to the user profile location.

        No need to populate the new config file, this will be done on pympress exit.
        """
        if Config.using_portable_config():
            os.remove(util.get_portable_config())
        else:
            with open(util.get_portable_config(), 'w'):
                pass
Ejemplo n.º 2
0
    def using_portable_config():
        """ Checks which configuration file location is in use.

        Returns:
            `bool`: `True` iff we are using the portable (i.e. in install dir) location
        """
        return util.get_portable_config() == Config.path_to_config()
Ejemplo n.º 3
0
    def path_to_config(search_legacy_locations = False):
        """ Return the path to the currently used configuration file.

        Args:
            search_legacy_locations (`bool`): whether to look in previously used locations
        """
        portable_config = util.get_portable_config()
        if os.path.exists(portable_config):
            return portable_config

        user_config = util.get_user_config()

        # migrate old configuration files from previously-used erroneous locations
        if search_legacy_locations and (util.IS_POSIX or util.IS_MAC_OS) and not os.path.exists(user_config):
            for legacy_location in [os.path.expanduser('~/.pympress'), os.path.expanduser('~/.config/pympress')]:
                if os.path.exists(legacy_location):
                    shutil.move(legacy_location, user_config)

        return user_config