Passed
Push — master ( aeb165...d9ae97 )
by Dean
03:04
created

PathEnvironment   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 90.48%
Metric Value
dl 0
loc 40
ccs 19
cts 21
cp 0.9048
rs 10
wmc 9

7 Methods

Rating   Name   Duplication   Size   Complexity  
A plugin_database() 0 3 1
A code() 0 3 1
A __init__() 0 4 1
A plugin_caches() 0 3 1
A libraries() 0 3 1
A plugin_support() 0 8 1
A plugin_data() 0 3 1
1 1
from plugin.core.constants import PLUGIN_IDENTIFIER
2
3 1
import os
4
5
6 1
class PathEnvironment(object):
7
    # TODO confirm validity of this on *nix and OS X
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
8
9 1
    def __init__(self, core):
10 1
        self._core = core
11
12 1
        self._plugin_support = None
13
14 1
    @property
15
    def code(self):
16 1
        return self._core.code_path
17
18 1
    @property
19
    def libraries(self):
20 1
        return os.path.abspath(os.path.join(self.code, '..', 'Libraries'))
21
22 1
    @property
23
    def plugin_caches(self):
24 1
        return os.path.join(self.plugin_support, 'Caches', PLUGIN_IDENTIFIER)
25
26 1
    @property
27
    def plugin_data(self):
28 1
        return os.path.join(self.plugin_support, 'Data', PLUGIN_IDENTIFIER)
29
30 1
    @property
31
    def plugin_database(self):
32 1
        return os.path.join(self.plugin_support, 'Databases', '%s.db' % PLUGIN_IDENTIFIER)
33
34 1
    @property
35
    def plugin_support(self):
36 1
        if self._plugin_support is not None:
37 1
            return self._plugin_support
38
39
        base_path = self.code[:self.code.index(os.path.sep + 'Plug-ins')]
40
41
        return os.path.join(base_path, 'Plug-in Support')
42
43 1
    @plugin_support.setter
44
    def plugin_support(self, path):
45 1
        self._plugin_support = path
46
47
48 1
class PlatformEnvironment(object):
49 1
    def __init__(self, platform):
50 1
        self._platform = platform
51
52 1
    @property
53
    def machine_identifier(self):
54
        return self._platform.MachineIdentifier
55
56 1
    @property
57
    def server_version(self):
58
        return self._platform.ServerVersion
59
60
61 1
class Environment(object):
62 1
    dict = None
63 1
    path = None
64 1
    platform = None
65 1
    prefs = None
66
67 1
    @classmethod
68
    def setup(cls, core, dict, platform, prefs):
0 ignored issues
show
Bug Best Practice introduced by
This seems to re-define the built-in dict.

It is generally discouraged to redefine built-ins as this makes code very hard to read.

Loading history...
69 1
        cls.path = PathEnvironment(core)
70 1
        cls.dict = dict
71 1
        cls.platform = PlatformEnvironment(platform)
72 1
        cls.prefs = prefs
73
74 1
    @classmethod
75
    def get_pref(cls, key):
76 1
        try:
77 1
            return cls.prefs[key]
78
        except:
0 ignored issues
show
Coding Style Best Practice introduced by
General except handlers without types should be used sparingly.

Typically, you would use general except handlers when you intend to specifically handle all types of errors, f.e. when logging. Otherwise, such general error handlers can mask errors in your application that you want to know of.

Loading history...
79
            return None
80