Belle II Software  release-08-01-10
validationtestutil.py
1 #!/usr/bin/env python3
2 
3 
10 
11 import os
12 import sys
13 
14 
15 def check_execute(cmd, terminate_on_error=True):
16  """
17  Executes a shell commands and check for =! 0 return codes
18  """
19 
20  print(f"Executing command '{cmd}'")
21  res = os.system(cmd)
22  print(f"Command '{cmd}' exited with code {res}")
23  if not res == 0:
24  print("FATAL: Exit code is not 0")
25  if terminate_on_error:
26  sys.exit(res)
27  return False
28 
29  return True
30 
31 
32 def check_path_exists(paths, terminate_on_error=True):
33  """
34  Checks if a path exists.
35 
36  @param paths: list of file system path (directories or files)
37  @param terminate_on_error: if true, the execution is terminated if one part
38  is not present
39  @return: None
40  """
41 
42  for p in paths:
43  print(f"Checking for existance of file {p}")
44  if not os.path.exists(p):
45  print(f"Path {p} does not exist")
46  if terminate_on_error:
47  sys.exit(1)
48  print("Jep !")
49 
50 
51 def create_fake_scripts(folders, scriptname):
52  """
53  Creates a fake script inside a nested path
54  :param folders: folders to hold the script
55  :param scriptname: name of the script itself
56  :return: nothing
57  """
58  if not os.path.exists(folders):
59  os.makedirs(folders)
60  with open(os.path.join(folders, scriptname), "w") as f:
61  f.write("# not content on purpose")