Пример #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 remove_configuration(config_name):
    """
    Removes all config and state files associated with the given configuration.

    :param str config_name: The configuration to remove.
    """

    MaestralConfig(config_name).cleanup()
    MaestralState(config_name).cleanup()
    index_file = get_data_path('maestral', f'{config_name}.index')
    delete(index_file)
Пример #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_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():
    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'
Пример #6
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"
Пример #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,
        service_name: str,
        start_cmd: str,
        unit_dict: Optional[Dict[str, str]] = None,
        service_dict: Optional[Dict[str, str]] = None,
        install_dict: Optional[Dict[str, str]] = None,
    ) -> None:
        super().__init__()

        # strip any instance specifiers from template service name
        filename = re.sub(r'@[^"]*\.service', "@.service", service_name)

        self.service_name = service_name
        self.destination = get_data_path(osp.join("systemd", "user"), filename)

        self.service_config = configparser.ConfigParser(interpolation=None)
        # set to preserve key casing
        self.service_config.optionxform = str  # type: ignore

        self.service_config.add_section("Unit")
        self.service_config.add_section("Service")
        self.service_config.add_section("Install")

        # fill out some default values for a minimum systemd unit
        self.service_config["Service"]["Type"] = "exec"
        self.service_config["Service"]["ExecStart"] = start_cmd
        self.service_config["Install"]["WantedBy"] = "default.target"

        # update with user-specified dicts
        if unit_dict:
            self.service_config["Unit"].update(unit_dict)
        if service_dict:
            self.service_config["Service"].update(service_dict)
        if install_dict:
            self.service_config["Install"].update(install_dict)

        # write to file in ~/.local/share/systemd/user
        with open(self.destination, "w") as f:
            self.service_config.write(f)
Пример #10
0
    def __init__(self, config_name, gui):
        super().__init__(config_name, gui)

        if self.gui:
            raise ValueError('Systemd launching is not supported for the GUI. '
                             'This may change in a future release.')

        service_type = 'gui' if self.gui else 'daemon'
        self.service_name = f'maestral-{service_type}@{self.config_name}.service'

        with open(osp.join(_resources, '[email protected]'), 'r') as f:
            unit_template = f.read()

        filename = 'maestral-{}@.service'.format('gui' if self.gui else 'daemon')
        self.destination = get_data_path(osp.join('systemd', 'user'), filename)
        self.contents = unit_template.format(
            start_cmd=f'{self.maestral_path} start -f',
            stop_cmd=f'{self.maestral_path} stop',
        )

        with open(self.destination, 'w') as f:
            f.write(self.contents)