MCPcopy Create free account
hub / github.com/comaps/comaps / Omim

Class Omim

tools/python/routing/src/utils.py:84–202  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

82
83
84class Omim():
85 def __init__(self):
86 config_ini = ConfigINI('etc/paths.ini')
87
88 self.omim_path = config_ini.read_value_by_path(path=['PATHS', 'OmimPath'])
89 self.data_path = config_ini.read_value_by_path(path=['PATHS', 'DataPath'])
90 self.build_dir = config_ini.read_value_by_path(path=['PATHS', 'BuildDir'])
91 self.cpu_count = cpu_count()
92
93 repo = Repo(self.omim_path)
94 self.branch = repo.active_branch.name
95 self.hash = repo.head.object.hexsha
96
97 self.init_branch = self.branch
98 self.init_hash = self.hash
99
100 self.cur_time_string = self._pretty_time_string(dt=datetime.now())
101 self.cmake_cmd = get_cmake_cmd()
102
103 @staticmethod
104 def _pretty_time_string(*, dt):
105 return dt.strftime('%Y_%m_%d__%H_%M_%S')
106
107 def _run_system_unsafe(self, *, cmd, env=None, output_file=None, log_cmd=False):
108 env_params = ""
109 if env is None:
110 env = dict()
111 else:
112 env_params = "env "
113
114 for key, value in env.items():
115 env_params += f'{key}={value} '
116
117 if output_file is None:
118 output = ""
119 else:
120 output = f'> {output_file} 2>&1'
121
122 full_cmd = env_params + cmd + output
123 if log_cmd:
124 LOG.info(f'Run: {full_cmd}')
125 return {os.system(full_cmd), full_cmd}
126
127 def _run_system(self, *, cmd, env=None, output_file=None, log_cmd=False):
128 result, full_cmd = self._run_system_unsafe(cmd=cmd, env=env, output_file=output_file, log_cmd=log_cmd)
129 if result:
130 raise Exception(f'Error during executing {full_cmd}')
131
132 def _get_cached_binary_name(self, *, binary, binary_cache_suffix=None):
133 binary_path = os.path.join(self.build_dir, f'{binary}_{self.branch}')
134
135 if self.hash is not None:
136 binary_path += f'_{self.hash}'
137
138 if binary_cache_suffix is not None:
139 binary_path += f'_{binary_cache_suffix}'
140
141 return binary_path

Callers 2

mainFunction · 0.90
mainFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected