forked from NickSto/dunovo
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathshims.py
57 lines (47 loc) · 1.37 KB
/
shims.py
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
import sys
import importlib
"""Stub versions of optional submodules which may fail to clone."""
class Shim(object):
def __init__(self):
self.is_shim = True
class version(Shim):
def get_version(self):
return None
class simplewrap(Shim):
class Wrapper(object):
def __init__(self):
self.width = 80
def wrap(self, string):
return string
class phone(Shim):
class Call(object):
def __init__(self,
script_path,
version,
run_id=None,
domain=None,
timeout=None,
secure=None,
platform=None,
test=False,
fail='exception'):
pass
def send_data(self, event_type, run_data={}, run_time=None):
pass
def get_module_or_shim(module_path):
"""Load the given module, or if not possible, return a stub."""
try:
return importlib.import_module(module_path)
except ImportError:
sys.stderr.write('Error importing module '+module_path+'. Some functionality may be missing.\n')
module_name = module_path.split('.')[-1]
try:
shim = globals()[module_name]
except KeyError:
sys.stderr.write('Error: cannot find a shim named "'+module_name+'".\n')
raise
try:
return shim()
except TypeError:
sys.stderr.write('Error: problem loading shim "'+module_name+'".\n')
raise