File: QueueNull.py

package info (click to toggle)
python-dirq 1.8-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 336 kB
  • sloc: python: 2,200; makefile: 166
file content (109 lines) | stat: -rw-r--r-- 2,799 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
"""
QueueNull - object oriented interface to a null directory based queue.

A port of Perl module Directory::Queue::Null
http://search.cpan.org/dist/Directory-Queue/
The documentation from Directory::Queue::Null module was
adapted for Python.

=================
QueueNull class
=================

:py:class:`QueueNull` - null directory based queue.

Usage::

    from dirq.QueueNull import QueueNull

    # sample producer

    dirq = QueueNull()
    for count in range(1,101):
        name = dirq.add("element %i\\n" % count)


Description
-----------

    The goal of this module is to offer a "null" queue system using the
    same API as the other directory queue implementations. The queue will
    behave like a black hole: added data will disappear immediately so the
    queue will therefore always appear empty.

    This can be used for testing purposes or to discard data like one
    would do on Unix by redirecting output to */dev/null*.

    Please refer to :py:mod:`dirq.queue` for general information about
    directory queues.


Author
------

Konstantin Skaburskas <konstantin.skaburskas@gmail.com>

License and Copyright
---------------------

ASL 2.0

Copyright (C) CERN 2011-2021
"""

import os
from dirq.QueueBase import QueueBase


class QueueNull(QueueBase):
    """
    QueueNull
    """
    def __init__(self):
        """ Constructor, this does nothing."""
        pass

    def add(self, data):
        """Add data to the queue, this does nothing. """
        return ""

    add_ref = add  # to comply with the Perl Directory::Queue interface

    def add_path(self, path):
        """Add the given file (identified by its path) to the queue,
        this will therefore *remove the file.*
        """
        os.unlink(path)
        return ""

    def get(self, name):
        """ Not supported method. """
        raise NotImplementedError("unsupported method: get()")

    get_ref = get  # to comply with the Perl Directory::Queue interface

    def get_path(self, name):
        """ Not supported method. """
        raise NotImplementedError("unsupported method: get_path()")

    def lock(self, name, permissive=True):
        """ Not supported method. """
        raise NotImplementedError("unsupported method: lock()")

    def unlock(self, name, permissive=False):
        """ Not supported method. """
        raise NotImplementedError("unsupported method: unlock()")

    def remove(self, name):
        """ Not supported method. """
        raise NotImplementedError("unsupported method: remove()")

    def count(self):
        """Return the number of elements in the queue, which means
        it always return 0.
        """
        return 0

    def purge(self, maxtemp=300, maxlock=600):
        """ Purge the queue, this does nothing. """
        pass