-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_genie_python_usage.py
More file actions
95 lines (73 loc) · 2.97 KB
/
get_genie_python_usage.py
File metadata and controls
95 lines (73 loc) · 2.97 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
from __future__ import absolute_import, print_function
import argparse
import glob
import os
from run_tests import setup_instrument_tests
from tests.settings import Settings
from util.channel_access import ChannelAccessUtils
def get_usage_on_instruments(instruments, functions_to_check):
"""
:param instruments: list containing the instruments to check
:param functions_to_check: list containing the functions to check for
:return: Dictionary of instruments containing a set of IOCs on that instrument
"""
found_items = {}
for instrument in instruments:
instrument_name = instrument["name"]
found_items[instrument_name] = set()
setup_instrument_tests(instrument)
for filename in glob.glob(
os.path.join(Settings.config_repo_path, "**/*.py"), recursive=True
):
print("Found python file: {}".format(filename))
with open(filename, "r") as f:
for line_no, line in enumerate(f):
for function in functions_to_check:
if function in line:
found_items[instrument_name].add((filename, line_no, line))
return found_items
def main():
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
description="""Looks through all configurations for IOCS configured to run.
Note: all repositories used by this script will be forcibly cleaned and
reset while the tests are running.
Do not point this script at any repository where you have changes you want
to keep!""",
)
parser.add_argument(
"--configs_repo_path",
type=str,
default="configs",
help="The path to the configurations repository.",
)
args = parser.parse_args()
instruments = ChannelAccessUtils().get_inst_list()
if len(instruments) == 0:
raise IOError(
"No instruments found. This is probably because the instrument list PV is unavailable."
)
Settings.set_repo_paths(os.path.abspath(args.configs_repo_path), None)
functions_to_check = [
"check_lowlimit_against_highlimit",
"set_title",
"set_script_dir",
"set_number_soft_periods",
"set_sample_par",
"set_beamline_par",
"set_period",
"get_absolute_path" "is_absolute",
"get_instrument_py_name" "get_instrument",
"send_tcpip",
"set_messages_verbosity",
]
found_usages = get_usage_on_instruments(instruments, functions_to_check)
print("Finished searching")
print()
for instrument, found_item in found_usages.items():
if found_item:
print("For instrument {}".format(instrument))
[print(line) for line in found_item]
print()
if __name__ == "__main__":
main()