示例#1
0
def test_linux_dirs():
    platform.system = lambda: 'Linux'

    os.environ['XDG_CONFIG_HOME'] = '/xdg_config_home'
    os.environ['XDG_CACHE_HOME'] = '/xdg_cache_home'
    os.environ['XDG_DATA_DIR'] = '/xdg_data_dir'
    os.environ['XDG_RUNTIME_DIR'] = '/xdg_runtime_dir'

    assert get_conf_path(create=False) == '/xdg_config_home'
    assert get_cache_path(create=False) == '/xdg_cache_home'
    assert get_data_path(create=False) == '/xdg_data_dir'
    assert get_runtime_path(create=False) == '/xdg_runtime_dir'
    assert get_old_runtime_path(create=False) == '/xdg_runtime_dir'
    assert get_log_path(create=False) == '/xdg_cache_home'
    assert get_autostart_path(create=False) == '/xdg_config_home/autostart'

    del os.environ['XDG_CONFIG_HOME']
    del os.environ['XDG_CACHE_HOME']
    del os.environ['XDG_DATA_DIR']
    del os.environ['XDG_RUNTIME_DIR']

    assert get_conf_path(create=False) == get_home_dir() + '/.config'
    assert get_cache_path(create=False) == get_home_dir() + '/.cache'
    assert get_data_path(create=False) == get_home_dir() + '/.local/share'
    assert get_runtime_path(create=False) == get_home_dir() + '/.cache'
    assert get_old_runtime_path(create=False) == get_home_dir() + '/.cache'
    assert get_log_path(create=False) == get_home_dir() + '/.cache'
    assert get_autostart_path(
        create=False) == get_home_dir() + '/.config/autostart'
示例#2
0
def test_linux_dirs():
    platform.system = lambda: "Linux"

    # test that XDG environment variables for app dirs are respected

    os.environ["XDG_CONFIG_HOME"] = "/xdg_config_home"
    os.environ["XDG_CACHE_HOME"] = "/xdg_cache_home"
    os.environ["XDG_DATA_HOME"] = "/xdg_data_dir"
    os.environ["XDG_RUNTIME_DIR"] = "/xdg_runtime_dir"

    assert get_conf_path(create=False) == "/xdg_config_home"
    assert get_cache_path(create=False) == "/xdg_cache_home"
    assert get_data_path(create=False) == "/xdg_data_dir"
    assert get_runtime_path(create=False) == "/xdg_runtime_dir"
    assert get_log_path(create=False) == "/xdg_cache_home"
    assert get_autostart_path(create=False) == "/xdg_config_home/autostart"

    # test that we have reasonable fallbacks if XDG environment variables are not set

    del os.environ["XDG_CONFIG_HOME"]
    del os.environ["XDG_CACHE_HOME"]
    del os.environ["XDG_DATA_HOME"]
    del os.environ["XDG_RUNTIME_DIR"]

    assert get_conf_path(create=False) == get_home_dir() + "/.config"
    assert get_cache_path(create=False) == get_home_dir() + "/.cache"
    assert get_data_path(create=False) == get_home_dir() + "/.local/share"
    assert get_runtime_path(create=False) == get_home_dir() + "/.cache"
    assert get_log_path(create=False) == get_home_dir() + "/.cache"
    assert get_autostart_path(create=False) == get_home_dir() + "/.config/autostart"
示例#3
0
def test_macos_dirs():
    platform.system = lambda: "Darwin"

    assert (
        get_conf_path(create=False) == get_home_dir() + "/Library/Application Support"
    )
    assert get_cache_path(create=False) == get_conf_path(create=False)
    assert get_data_path(create=False) == get_conf_path(create=False)
    assert get_runtime_path(create=False) == get_conf_path(create=False)
    assert get_log_path(create=False) == get_home_dir() + "/Library/Logs"
    assert get_autostart_path(create=False) == get_home_dir() + "/Library/LaunchAgents"
示例#4
0
def test_macos_dirs():
    platform.system = lambda: 'Darwin'

    assert get_conf_path(
        create=False) == get_home_dir() + '/Library/Application Support'
    assert get_cache_path(create=False) == get_conf_path(create=False)
    assert get_data_path(create=False) == get_conf_path(create=False)
    assert get_runtime_path(create=False) == get_conf_path(create=False)
    assert get_old_runtime_path(create=False) == tempfile.gettempdir()
    assert get_log_path(create=False) == get_home_dir() + '/Library/Logs'
    assert get_autostart_path(
        create=False) == get_home_dir() + '/Library/LaunchAgents'
示例#5
0
def test_macos_dirs(monkeypatch):
    # test appdirs on macOS

    monkeypatch.setattr(platform, "system", lambda: "Darwin")

    home = get_home_dir()

    assert get_conf_path(create=False) == home + "/Library/Application Support"
    assert get_cache_path(create=False) == get_conf_path(create=False)
    assert get_data_path(create=False) == get_conf_path(create=False)
    assert get_runtime_path(create=False) == get_conf_path(create=False)
    assert get_log_path(create=False) == home + "/Library/Logs"
    assert get_autostart_path(create=False) == home + "/Library/LaunchAgents"
示例#6
0
    def __init__(self, config_name, gui):
        super().__init__(config_name, gui)

        if not gui:
            raise ValueError(
                'XDG Desktop entries are only supported to launch the GUI')

        filename = f'maestral-{config_name}.desktop'

        with open(osp.join(_resources, 'maestral.desktop'), 'r') as f:
            desktop_entry_template = f.read()

        self.destination = get_conf_path('autostart', filename)
        self.contents = desktop_entry_template.format(version=__version__,
                                                      start_cmd=self.start_cmd)
示例#7
0
def test_xdg_dirs(monkeypatch):
    # test that XDG environment variables for app dirs are respected

    monkeypatch.setattr(platform, "system", lambda: "Linux")

    monkeypatch.setenv("XDG_CONFIG_HOME", "/xdg_config_home")
    monkeypatch.setenv("XDG_CACHE_HOME", "/xdg_cache_home")
    monkeypatch.setenv("XDG_DATA_HOME", "/xdg_data_dir")
    monkeypatch.setenv("XDG_RUNTIME_DIR", "/xdg_runtime_dir")

    assert get_conf_path(create=False) == "/xdg_config_home"
    assert get_cache_path(create=False) == "/xdg_cache_home"
    assert get_data_path(create=False) == "/xdg_data_dir"
    assert get_runtime_path(create=False) == "/xdg_runtime_dir"
    assert get_log_path(create=False) == "/xdg_cache_home"
    assert get_autostart_path(create=False) == "/xdg_config_home/autostart"
示例#8
0
def test_xdg_fallback_dirs(monkeypatch):
    # test that we have reasonable fallbacks if XDG environment variables are not set

    monkeypatch.setattr(platform, "system", lambda: "Linux")

    monkeypatch.delenv("XDG_CONFIG_HOME", raising=False)
    monkeypatch.delenv("XDG_CACHE_HOME", raising=False)
    monkeypatch.delenv("XDG_DATA_HOME", raising=False)
    monkeypatch.delenv("XDG_RUNTIME_DIR", raising=False)

    home = get_home_dir()

    assert get_conf_path(create=False) == home + "/.config"
    assert get_cache_path(create=False) == home + "/.cache"
    assert get_data_path(create=False) == home + "/.local/share"
    assert get_runtime_path(create=False) == home + "/.cache"
    assert get_log_path(create=False) == home + "/.cache"
    assert get_autostart_path(create=False) == home + "/.config/autostart"
示例#9
0
    def __init__(self, app_name: str, start_cmd: str, filename: Optional[str],
                 **kwargs: str) -> None:
        super().__init__()

        # create desktop file content
        self.config = configparser.ConfigParser(interpolation=None)
        # set to preserve key casing
        self.config.optionxform = str  # type: ignore

        self.config["Desktop Entry"] = {
            "Version": "1.0",
            "Type": "Application",
            "Name": app_name,
            "Exec": start_cmd,
        }
        self.config["Desktop Entry"].update(kwargs)

        filename = filename or f"{app_name}.desktop"
        self.destination = get_conf_path("autostart", filename)