import subprocess from subprocess import SubprocessError, TimeoutExpired, CalledProcessError import platform from hub.exports.exports_factory import ExportsFactory from hub.imports.results_factory import ResultFactory class SraEngine: def __init__(self, city, file_path, output_file_path, weather_file): """ SRA class :param file_path: _sra.xml file path :param output_file_path: path to output the sra calculation """ self._city = city self._file_path = file_path self._output_file_path = output_file_path self._weather_file = weather_file if platform.system() == 'Linux': self._executable = 'sra' elif platform.system() == 'Windows': self._executable = 'shortwave_integer' ExportsFactory('sra', self._city, output_file_path, weather_file=self._weather_file, weather_format='epw').export() self._run() ResultFactory('sra', self._city, output_file_path).enrich() def _run(self): """ Calls the software """ try: subprocess.run([self._executable, str(self._file_path)], stdout=subprocess.DEVNULL) except (SubprocessError, TimeoutExpired, CalledProcessError) as error: raise Exception(error)