mine.models.application   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Test Coverage

Coverage 93.75%

Importance

Changes 0
Metric Value
eloc 39
dl 0
loc 62
ccs 30
cts 32
cp 0.9375
rs 10
c 0
b 0
f 0
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A Applications.find() 0 7 3
A Application.no_wait() 0 3 1
A Application.__init__() 0 6 1
A Application.auto_queue() 0 3 1
A Applications.get() 0 5 1
1
"""Data structures for application information."""
2
3 1
import log
4
import yorm
5 1
6
from ._bases import NameMixin
7 1
8
9
@yorm.attr(mac=yorm.types.NullableString)
10 1
@yorm.attr(windows=yorm.types.NullableString)
11
@yorm.attr(linux=yorm.types.NullableString)
12
class Versions(yorm.types.AttributeDictionary):
13 1
    """Dictionary of OS-specific application filenames."""
14 1
15 1
16 1
@yorm.attr(auto_queue=yorm.types.Boolean)
17
@yorm.attr(single_instance=yorm.types.Boolean)
18
class Properties(yorm.types.AttributeDictionary):
19
    """Dictionary of application management settings."""
20 1
21 1
22 1
@yorm.attr(name=yorm.types.String)
23
@yorm.attr(properties=Properties)
24
@yorm.attr(versions=Versions)
25
class Application(NameMixin, yorm.types.AttributeDictionary):
26 1
    """Dictionary of application information."""
27 1
28 1
    def __init__(self, name=None, properties=None, versions=None, filename=None):
29 1
        super().__init__()
30
        self.name = name
31
        self.properties = properties or Properties()
32 1
        self.versions = versions or Versions(
33 1
            mac=filename, windows=filename, linux=filename
34 1
        )
35 1
36 1
    @property
37
    def auto_queue(self):
38
        return self.properties.auto_queue
39
40 1
    @property
41
    def no_wait(self):
42
        return not self.properties.single_instance
43
44 1
45
@yorm.attr(all=Application)
46
class Applications(yorm.types.SortedList):
47
    """List of monitored applications."""
48
49 1
    def get(self, name):
50 1
        """Get the application with the given name."""
51
        application = self.find(name)
52
        assert application, name
53 1
        return application
54
55 1
    def find(self, name):
56 1
        """Find the application with the given name, else None."""
57 1
        log.debug("Finding application for '%s'...", name)
58
        for application in self:
59 1
            if application == name:
60
                return application
61
        return None
62