forked from microsoft/azure-devops-python-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrunner_lib.py
More file actions
68 lines (48 loc) · 1.77 KB
/
runner_lib.py
File metadata and controls
68 lines (48 loc) · 1.77 KB
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
58
59
60
61
62
63
64
65
66
67
68
"""
Helper methods moved out of the main runner file.
"""
import importlib
import logging
import pathlib
import pkgutil
import http_logging
from utils import emit
logger = logging.getLogger(__name__)
###
# Sample discovery
###
SAMPLES_MODULE_NAME = 'samples'
logger.debug("loading samples module")
_samples_module = importlib.import_module(SAMPLES_MODULE_NAME)
logger.debug('loading all modules in `%s`', SAMPLES_MODULE_NAME)
for _, name, _ in pkgutil.iter_modules(_samples_module.__path__):
importlib.import_module('%s.%s' % (SAMPLES_MODULE_NAME, name))
# trim the sample module name off the area names
discovered_samples = {
area[len(SAMPLES_MODULE_NAME)+1:]: module for area, module in _samples_module.discovered_samples.items()
}
###
# Logging helpers and so on
###
def enter_area(area, http_logging_path):
emit("== %s ==", area)
if http_logging_path is not None:
area_log_dir = pathlib.Path(http_logging_path / area)
area_log_dir.mkdir(parents=True, exist_ok=True)
return area_log_dir
return None
def enter_resource(resource, http_logging_path):
emit("-- %s --", resource)
if http_logging_path is not None:
resource_log_dir = pathlib.Path(http_logging_path / resource)
resource_log_dir.mkdir(parents=True, exist_ok=True)
return resource_log_dir
return None
def before_run_sample(func_name, http_logging_path):
if http_logging_path is not None:
example_log_file = pathlib.Path(http_logging_path / (func_name + '.json'))
http_logging.target = example_log_file.open('w')
def after_run_sample(http_logging_path):
if http_logging_path is not None:
http_logging.target.close()
http_logging.target = None