DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
utils Namespace Reference

Functions

 setup_logging (str level="INFO")
 
 find_oksincludes (list[str] includes, list[str] extra_dirs=[])
 
 find_free_port ()
 

Variables

list log_levels = ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]
 

Function Documentation

◆ find_free_port()

utils.find_free_port ( )

Definition at line 90 of file utils.py.

90def find_free_port():
91 with socket.socket() as s:
92 s.bind(("", 0))
93 s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
94 port = s.getsockname()[1]
95 s.close()
96 return port

◆ find_oksincludes()

utils.find_oksincludes ( list[str] includes,
list[str] extra_dirs = [] )

Definition at line 37 of file utils.py.

37def find_oksincludes(includes:list[str], extra_dirs:list[str] = []):
38 includefiles = []
39
40 searchdirs = [path for path in os.environ["DUNEDAQ_DB_PATH"].split(":")]
41 for dir in extra_dirs:
42 searchdirs.append(dir)
43
44 for inc in includes:
45 # print (f"Searching for {inc}")
46 match = False
47 inc = inc.removesuffix(".xml")
48 if inc.endswith(".data"):
49 sub_dirs = ["config", "data"]
50 elif inc.endswith(".schema"):
51 sub_dirs = ["schema"]
52 else:
53 sub_dirs = ["*"]
54 inc = inc + "*"
55 for path in searchdirs:
56 # print (f" {path}/{inc}.xml")
57 matches = glob.glob(f"{inc}.xml", root_dir=path)
58 if len(matches) == 0:
59 for search_dir in sub_dirs:
60 # print (f" {path}/{search_dir}/{inc}.xml")
61 matches = glob.glob(f"{search_dir}/{inc}.xml", root_dir=path)
62 for filename in matches:
63 if filename not in includefiles:
64 print(f"Adding {filename} to include list")
65 includefiles.append(filename)
66 #else:
67 # print(f"{filename} already in include list")
68 match = True
69 break
70 if match:
71 break
72 if match:
73 break
74 else:
75 for filename in matches:
76 if filename not in includefiles:
77 print(f"Adding {filename} to include list")
78 includefiles.append(filename)
79 #else:
80 # print(f"{filename} already in include list")
81 match = True
82 break
83
84 if not match:
85 print(f"Error could not find include file for {inc}")
86 return [False, []]
87
88 return [True, includefiles]
89

◆ setup_logging()

utils.setup_logging ( str level = "INFO")

Definition at line 11 of file utils.py.

11def setup_logging(level:str="INFO"):
12 level = level.upper()
13
14 loglevel = logging.INFO
15
16 match level:
17 case "DEBUG":
18 loglevel = logging.DEBUG
19 case "INFO":
20 loglevel = logging.INFO
21 case "WARNING":
22 loglevel = logging.WARNING
23 case "ERROR":
24 loglevel = logging.ERROR
25 case "CRITICAL":
26 loglevel = logging.CRITICAL
27 case _:
28 loglevel = logging.INFO
29
30 FORMAT = "%(message)s"
31 logging.basicConfig(
32 level="NOTSET", format=FORMAT, datefmt="[%X]", handlers=[RichHandler()]
33 )
34 logging.getLogger().setLevel(loglevel)
35
36

Variable Documentation

◆ log_levels

list utils.log_levels = ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]

Definition at line 8 of file utils.py.