Completed
Pull Request — master (#2624)
by
unknown
01:43
created

DbusApp   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 46
rs 10
c 0
b 0
f 0
wmc 5
1
import os
2
3
from coalib.output.dbus.DbusDocument import DbusDocument
4
5
6
class DbusApp:
7
    """
8
    Stores data about each client that connects to the DbusServer
9
    """
10
11
    def __init__(self, app_id, name=""):
12
        self.app_id = app_id
13
        self.name = name
14
15
        self.docs = {}
16
        self.__next_doc_id = 0
17
18
    def _next_doc_id(self):
19
        self.__next_doc_id += 1
20
        return self.__next_doc_id
21
22
    def create_document(self, path):
23
        """
24
        Create a new dbus document.
25
26
        :param path:        The path to the document to be created.
27
        :param object_path: The dbus object path to use as the base for the
28
                            document object path.
29
        :param object_path: The connection to which the new ddocument object
30
                            path should be added.
31
        :return:            a DbusDocument object.
32
        """
33
        path = os.path.abspath(os.path.expanduser(path))
34
        doc = DbusDocument(doc_id=self._next_doc_id(), path=path)
35
        self.docs[path] = doc
36
37
        return doc
38
39
    def dispose_document(self, path):
40
        """
41
        Dispose of the document with the given path. It fails silently if the
42
        document does not exist. If there are no more documents in the app,
43
        the app is disposed.
44
45
        :param path: The path to the document.
46
        """
47
        path = os.path.abspath(os.path.expanduser(path))
48
        try:
49
            return self.docs.pop(path)
50
        except KeyError:
51
            return None
52