コード例 #1
0
ファイル: test_api.py プロジェクト: lazka/senf
def test_test_mkstemp():
    fd, fsn = mkstemp()
    os.close(fd)
    assert isinstance(fsn, fsnative)
    os.remove(fsn)

    fd, fsn = mkstemp(suffix="foo")
    os.close(fd)
    fsn.endswith("foo")
    assert isinstance(fsn, fsnative)
    os.remove(fsn)
コード例 #2
0
 def setUp(self):
     config.RATINGS = config.HardCodedRatingsPrefs()
     fd, filename = mkstemp()
     os.close(fd)
     self.quux = AudioFile({
         "~filename": normalize_path(filename, True),
         "album": u"Quuxly"
     })
コード例 #3
0
 def setUp(self):
     config.RATINGS = config.HardCodedRatingsPrefs()
     fd, filename = mkstemp()
     os.close(fd)
     self.quux = AudioFile({
         "~filename": normalize_path(filename, True),
         "album": u"Quuxly"
     })
コード例 #4
0
 def setUp(self):
     # Need the playlists library now
     init_fake_app()
     config.RATINGS = config.HardCodedRatingsPrefs()
     fd, filename = mkstemp()
     os.close(fd)
     self.quux = AudioFile({
         "~filename": normalize_path(filename, True),
         "album": u"Quuxly"
     })
コード例 #5
0
    def test_rename(self):
        old_fn = self.quux["~filename"]

        fd, new_fn = mkstemp()
        os.close(fd)
        os.unlink(new_fn)

        assert self.quux.exists()
        self.quux.rename(new_fn)
        assert not os.path.exists(old_fn)
        assert self.quux.exists()
        self.quux.rename(old_fn)
        assert not os.path.exists(new_fn)
        assert self.quux.exists()
コード例 #6
0
    def test_rename(self):
        old_fn = self.quux["~filename"]

        fd, new_fn = mkstemp()
        os.close(fd)
        os.unlink(new_fn)

        assert self.quux.exists()
        self.quux.rename(new_fn)
        assert not os.path.exists(old_fn)
        assert self.quux.exists()
        self.quux.rename(old_fn)
        assert not os.path.exists(new_fn)
        assert self.quux.exists()
コード例 #7
0
def write_fifo(fifo_path, data):
    """Writes the data to the FIFO and returns a response.

    Args:
        fifo_path (pathlike)
        data (bytes)
    Returns:
        bytes
    Raises:
        FIFOError
    """

    assert isinstance(data, bytes)

    fd, filename = mkstemp()
    try:
        os.close(fd)
        os.unlink(filename)
        # mkfifo fails if the file exists, so this is safe.
        os.mkfifo(filename, 0o600)

        _write_fifo(fifo_path,
                    b"\x00".join([b"", data,
                                  fsn2bytes(filename, None), b""]))

        try:
            signal.signal(signal.SIGALRM, _sigalrm_timeout)
            signal.alarm(FIFO_TIMEOUT)
            with open(filename, "rb") as h:
                signal.signal(signal.SIGALRM, signal.SIG_IGN)
                return h.read()
        except TimeoutError:
            # In case the main instance deadlocks we can write to it, but
            # reading will time out. Assume it is broken and delete the
            # fifo.
            try:
                os.unlink(fifo_path)
            except OSError:
                pass
            raise FIFOError("Timeout reached")
    except OSError as e:
        raise FIFOError(*e.args)
    finally:
        try:
            os.unlink(filename)
        except OSError:
            pass
コード例 #8
0
ファイル: fifo.py プロジェクト: azarmadr/quodlibet
def write_fifo(fifo_path, data):
    """Writes the data to the FIFO and returns a response.

    Args:
        fifo_path (pathlike)
        data (bytes)
    Returns:
        bytes
    Raises:
        EnvironmentError: In case of timeout and other errors
    """

    assert isinstance(data, bytes)

    fd, filename = mkstemp()
    try:
        os.close(fd)
        os.unlink(filename)
        # mkfifo fails if the file exists, so this is safe.
        os.mkfifo(filename, 0o600)

        _write_fifo(
            fifo_path,
            b"\x00" + data + b"\x00" + fsn2bytes(filename, None) + b"\x00")

        try:
            signal.signal(signal.SIGALRM, lambda: "" + 2)
            signal.alarm(FIFO_TIMEOUT)
            with open(filename, "rb") as h:
                signal.signal(signal.SIGALRM, signal.SIG_IGN)
                return h.read()
        except TypeError:
            # In case the main instance deadlocks we can write to it, but
            # reading will time out. Assume it is broken and delete the
            # fifo.
            try:
                os.unlink(fifo_path)
            except OSError:
                pass
            raise EnvironmentError("timeout")
    finally:
        try:
            os.unlink(filename)
        except EnvironmentError:
            pass
コード例 #9
0
ファイル: fifo.py プロジェクト: LudoBike/quodlibet
def write_fifo(fifo_path, data):
    """Writes the data to the FIFO and returns a response.

    Args:
        fifo_path (pathlike)
        data (bytes)
    Returns:
        bytes
    Raises:
        EnvironmentError: In case of timeout and other errors
    """

    assert isinstance(data, bytes)

    fd, filename = mkstemp()
    try:
        os.close(fd)
        os.unlink(filename)
        # mkfifo fails if the file exists, so this is safe.
        os.mkfifo(filename, 0o600)

        _write_fifo(
            fifo_path,
            b"\x00" + data + b"\x00" + fsn2bytes(filename, None) + b"\x00")

        try:
            signal.signal(signal.SIGALRM, lambda: "" + 2)
            signal.alarm(FIFO_TIMEOUT)
            with open(filename, "rb") as h:
                signal.signal(signal.SIGALRM, signal.SIG_IGN)
                return h.read()
        except TypeError:
            # In case the main instance deadlocks we can write to it, but
            # reading will time out. Assume it is broken and delete the
            # fifo.
            try:
                os.unlink(fifo_path)
            except OSError:
                pass
            raise EnvironmentError("timeout")
    finally:
        try:
            os.unlink(filename)
        except EnvironmentError:
            pass
コード例 #10
0
 def setUp(self):
     init_fake_app()
     fd, self.filename = mkstemp()
     os.close(fd)
     self.info = SongInfo(SongLibrary(), NullPlayer(), self.filename)
コード例 #11
0
ファイル: test_qltk_info.py プロジェクト: LudoBike/quodlibet
 def setUp(self):
     init_fake_app()
     fd, self.filename = mkstemp()
     os.close(fd)
     self.info = SongInfo(SongLibrary(), NullPlayer(), self.filename)