Total Complexity | 5 |
Total Lines | 37 |
Duplicated Lines | 0 % |
Coverage | 56.25% |
1 | 1 | from plugin.core.libraries.helpers.storage import StorageHelper |
|
10 | 1 | class PathHelper(object): |
|
11 | 1 | @classmethod |
|
12 | def insert(cls, base, system, architecture, *args): |
||
13 | """Insert a new path into `sys.path` if it passes basic validation |
||
14 | |||
15 | :type base: str |
||
16 | :type system: str |
||
17 | :type architecture: str |
||
18 | """ |
||
19 | |||
20 | 1 | path = os.path.join(base, system, architecture, *args) |
|
21 | |||
22 | 1 | if path in sys.path: |
|
23 | return False |
||
24 | |||
25 | 1 | if not os.path.exists(path): |
|
26 | return False |
||
27 | |||
28 | 1 | sys.path.insert(0, path) |
|
29 | |||
30 | 1 | log.debug('Inserted path: %r', StorageHelper.to_relative_path(path)) |
|
31 | 1 | return True |
|
32 | |||
33 | 1 | @classmethod |
|
34 | def remove(cls, path): |
||
35 | """Remove path from `sys.path` if it exists |
||
36 | |||
37 | :type path: str |
||
38 | """ |
||
39 | |||
40 | if path not in sys.path: |
||
41 | return False |
||
42 | |||
43 | sys.path.remove(path) |
||
44 | |||
45 | log.debug('Removed path: %r', StorageHelper.to_relative_path(path)) |
||
46 | return True |
||
47 |