def test_runtimedir_empty_tempdir(self, monkeypatch, tmpdir):
     """With an empty tempdir on non-Linux, we should raise."""
     monkeypatch.setattr(standarddir.sys, 'platform', 'nt')
     monkeypatch.setattr(standarddir.QStandardPaths, 'writableLocation',
                         lambda typ: '')
     with pytest.raises(standarddir.EmptyValueError):
         standarddir.runtime()
Beispiel #2
0
 def test_runtimedir(self, tmpdir, monkeypatch):
     """Test runtime dir (which has no args)."""
     monkeypatch.setattr(
         'qutebrowser.utils.standarddir.QStandardPaths.writableLocation',
         lambda _typ: str(tmpdir))
     args = types.SimpleNamespace(confdir=None, cachedir=None, datadir=None)
     standarddir.init(args)
     assert standarddir.runtime() == str(tmpdir)
Beispiel #3
0
    def test_linux_invalid_runtimedir(self, monkeypatch, tmpdir):
        """With invalid XDG_RUNTIME_DIR, fall back to TempLocation."""
        tmpdir_env = tmpdir / 'temp'
        tmpdir_env.ensure(dir=True)
        monkeypatch.setenv('XDG_RUNTIME_DIR', str(tmpdir / 'does-not-exist'))
        monkeypatch.setenv('TMPDIR', str(tmpdir_env))

        standarddir._init_dirs()
        assert standarddir.runtime() == str(tmpdir_env / APPNAME)
Beispiel #4
0
def _path_info():
    """Get info about important path names.

    Return:
        A dictionary of descriptive to actual path names.
    """
    return {
        'config': standarddir.config(),
        'data': standarddir.data(),
        'system_data': standarddir.system_data(),
        'cache': standarddir.cache(),
        'download': standarddir.download(),
        'runtime': standarddir.runtime(),
    }
Beispiel #5
0
def _get_socketname(basedir):
    """Get a socketname to use."""
    if utils.is_windows:  # pragma: no cover
        return _get_socketname_windows(basedir)

    parts_to_hash = [getpass.getuser()]
    if basedir is not None:
        parts_to_hash.append(basedir)

    data_to_hash = '-'.join(parts_to_hash).encode('utf-8')
    md5 = hashlib.md5(data_to_hash).hexdigest()

    prefix = 'i-' if utils.is_mac else 'ipc-'
    filename = '{}{}'.format(prefix, md5)
    return os.path.join(standarddir.runtime(), filename)
Beispiel #6
0
    def run(self, cmd, *args, env=None, verbose=False):
        try:
            # tempfile.mktemp is deprecated and discouraged, but we use it here
            # to create a FIFO since the only other alternative would be to
            # create a directory and place the FIFO there, which sucks. Since
            # os.mkfifo will raise an exception anyways when the path doesn't
            # exist, it shouldn't be a big issue.
            self._filepath = tempfile.mktemp(prefix="qutebrowser-userscript-", dir=standarddir.runtime())
            os.mkfifo(self._filepath)  # pylint: disable=no-member
        except OSError as e:
            message.error(self._win_id, "Error while creating FIFO: {}".format(e))
            return

        self._reader = _QtFIFOReader(self._filepath)
        self._reader.got_line.connect(self.got_cmd)

        self._run_process(cmd, *args, env=env, verbose=verbose)
Beispiel #7
0
def _path_info():
    """Get info about important path names.

    Return:
        A dictionary of descriptive to actual path names.
    """
    info = {
        'config': standarddir.config(),
        'data': standarddir.data(),
        'cache': standarddir.cache(),
        'runtime': standarddir.runtime(),
    }
    if standarddir.config() != standarddir.config(auto=True):
        info['auto config'] = standarddir.config(auto=True)
    if standarddir.data() != standarddir.data(system=True):
        info['system data'] = standarddir.data(system=True)
    return info
Beispiel #8
0
def _get_socketname(basedir, legacy=False):
    """Get a socketname to use."""
    if legacy or os.name == 'nt':
        return _get_socketname_legacy(basedir)

    parts_to_hash = [getpass.getuser()]
    if basedir is not None:
        parts_to_hash.append(basedir)

    data_to_hash = '-'.join(parts_to_hash).encode('utf-8')
    md5 = hashlib.md5(data_to_hash).hexdigest()

    target_dir = standarddir.runtime()

    parts = ['ipc']
    parts.append(md5)
    return os.path.join(target_dir, '-'.join(parts))
Beispiel #9
0
def _path_info():
    """Get info about important path names.

    Return:
        A dictionary of descriptive to actual path names.
    """
    info = {
        'config': standarddir.config(),
        'data': standarddir.data(),
        'cache': standarddir.cache(),
        'runtime': standarddir.runtime(),
    }
    if standarddir.config() != standarddir.config(auto=True):
        info['auto config'] = standarddir.config(auto=True)
    if standarddir.data() != standarddir.data(system=True):
        info['system data'] = standarddir.data(system=True)
    return info
Beispiel #10
0
def _get_socketname(basedir):
    """Get a socketname to use."""
    if utils.is_windows:  # pragma: no cover
        return _get_socketname_windows(basedir)

    parts_to_hash = [getpass.getuser()]
    if basedir is not None:
        parts_to_hash.append(basedir)

    data_to_hash = '-'.join(parts_to_hash).encode('utf-8')
    md5 = hashlib.md5(data_to_hash).hexdigest()

    target_dir = standarddir.runtime()

    parts = ['ipc']
    parts.append(md5)
    return os.path.join(target_dir, '-'.join(parts))
Beispiel #11
0
def _get_socketname(basedir):
    """Get a socketname to use."""
    if os.name == 'nt':  # pragma: no cover
        return _get_socketname_windows(basedir)

    parts_to_hash = [getpass.getuser()]
    if basedir is not None:
        parts_to_hash.append(basedir)

    data_to_hash = '-'.join(parts_to_hash).encode('utf-8')
    md5 = hashlib.md5(data_to_hash).hexdigest()

    target_dir = standarddir.runtime()

    parts = ['ipc']
    parts.append(md5)
    return os.path.join(target_dir, '-'.join(parts))
Beispiel #12
0
def _get_socketname(basedir, legacy=False):
    """Get a socketname to use."""
    if legacy or os.name == "nt":
        return _get_socketname_legacy(basedir)

    parts_to_hash = [getpass.getuser()]
    if basedir is not None:
        parts_to_hash.append(basedir)

    data_to_hash = "-".join(parts_to_hash).encode("utf-8")
    md5 = hashlib.md5(data_to_hash).hexdigest()

    target_dir = standarddir.runtime()

    parts = ["ipc"]
    parts.append(md5)
    return os.path.join(target_dir, "-".join(parts))
Beispiel #13
0
    def run(self, cmd, *args, env=None):
        try:
            # tempfile.mktemp is deprecated and discouraged, but we use it here
            # to create a FIFO since the only other alternative would be to
            # create a directory and place the FIFO there, which sucks. Since
            # os.mkfifo will raise an exception anyways when the path doesn't
            # exist, it shouldn't be a big issue.
            self._filepath = tempfile.mktemp(prefix='qutebrowser-userscript-',
                                             dir=standarddir.runtime())
            os.mkfifo(self._filepath)  # pylint: disable=no-member
        except OSError as e:
            message.error(self._win_id,
                          "Error while creating FIFO: {}".format(e))
            return

        self._reader = _QtFIFOReader(self._filepath)
        self._reader.got_line.connect(self.got_cmd)

        self._run_process(cmd, *args, env=env)
    def test_flatpak_runtimedir(self, monkeypatch, tmp_path, args_basedir):
        runtime_path = tmp_path / 'runtime'
        runtime_path.mkdir()
        runtime_path.chmod(0o0700)

        app_id = 'org.qutebrowser.qutebrowser'

        monkeypatch.setattr(standarddir.version, 'is_flatpak', lambda: True)
        monkeypatch.setenv('XDG_RUNTIME_DIR', str(runtime_path))
        monkeypatch.setenv('FLATPAK_ID', app_id)

        if args_basedir:
            init_args = types.SimpleNamespace(basedir=str(tmp_path))
            expected = tmp_path / 'runtime'
        else:
            init_args = None
            expected = runtime_path / 'app' / app_id

        standarddir._init_runtime(args=init_args)
        assert standarddir.runtime() == str(expected)
    def prepare_run(self, *args, **kwargs):
        self._args = args
        self._kwargs = kwargs

        try:
            # tempfile.mktemp is deprecated and discouraged, but we use it here
            # to create a FIFO since the only other alternative would be to
            # create a directory and place the FIFO there, which sucks. Since
            # os.mkfifo will raise an exception anyways when the path doesn't
            # exist, it shouldn't be a big issue.
            self._filepath = tempfile.mktemp(prefix='qutebrowser-userscript-',
                                             dir=standarddir.runtime())
            # pylint: disable=no-member,useless-suppression
            os.mkfifo(self._filepath)
        except OSError as e:
            message.error("Error while creating FIFO: {}".format(e))
            return

        self._reader = _QtFIFOReader(self._filepath)
        self._reader.got_line.connect(self.got_cmd)
    def prepare_run(self, *args, **kwargs):
        self._args = args
        self._kwargs = kwargs

        try:
            # tempfile.mktemp is deprecated and discouraged, but we use it here
            # to create a FIFO since the only other alternative would be to
            # create a directory and place the FIFO there, which sucks. Since
            # os.mkfifo will raise an exception anyways when the path doesn't
            # exist, it shouldn't be a big issue.
            self._filepath = tempfile.mktemp(prefix='qutebrowser-userscript-',
                                             dir=standarddir.runtime())
            # pylint: disable=no-member,useless-suppression
            os.mkfifo(self._filepath)
            # pylint: enable=no-member,useless-suppression
        except OSError as e:
            message.error("Error while creating FIFO: {}".format(e))
            return

        self._reader = _QtFIFOReader(self._filepath)
        self._reader.got_line.connect(self.got_cmd)  # type: ignore
Beispiel #17
0
 def test_linux_invalid_runtimedir(self, monkeypatch, tmpdir):
     """With invalid XDG_RUNTIME_DIR, fall back to TempLocation."""
     monkeypatch.setenv('XDG_RUNTIME_DIR', str(tmpdir / 'does-not-exist'))
     monkeypatch.setenv('TMPDIR', str(tmpdir / 'temp'))
     standarddir._init_dirs()
     assert standarddir.runtime() == str(tmpdir / 'temp' / APPNAME)
 def test_linux_invalid_runtimedir(self, monkeypatch, tmpdir):
     """With invalid XDG_RUNTIME_DIR, fall back to TempLocation."""
     monkeypatch.setenv('XDG_RUNTIME_DIR', str(tmpdir / 'does-not-exist'))
     monkeypatch.setenv('TMPDIR', str(tmpdir / 'temp'))
     assert standarddir.runtime() == str(tmpdir / 'temp' / 'qute_test')