Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
S2-group
GitHub Repository: S2-group/android-runner
Path: blob/master/AndroidRunner/Scripts.py
629 views
1
import logging
2
import os.path as op
3
4
import paths
5
from .Python3 import Python3
6
from .util import ConfigError
7
8
9
class Scripts(object):
10
def __init__(self, config):
11
self.logger = logging.getLogger(self.__class__.__name__)
12
self.scripts = {}
13
for name, script in list(config.items()):
14
self.scripts[name] = []
15
if isinstance(script, str):
16
path = op.join(paths.CONFIG_DIR, script)
17
self.scripts[name].append(Python3(path))
18
continue
19
20
for s in script:
21
path = op.join(paths.CONFIG_DIR, s['path'])
22
timeout = s.get('timeout', 0)
23
logcat_regex = s.get('logcat_regex', None)
24
25
if s['type'] == 'python3':
26
script = Python3(path, timeout, logcat_regex)
27
else:
28
raise ConfigError('Unknown script type: {}'.format(s['type']))
29
30
self.scripts[name].append(script)
31
32
33
def run(self, name, device, *args, **kwargs):
34
self.logger.debug('Running hook {} on device {}\nargs: {}\nkwargs: {}'.format(name, device, args, kwargs))
35
for script in self.scripts.get(name, []):
36
script.run(device, *args, **kwargs)
37
38