2023-03-23 13:31:36 -04:00
|
|
|
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:
|
2023-06-07 14:48:21 -04:00
|
|
|
def __init__(self, city, file_path, output_file_path):
|
2023-03-23 13:31:36 -04:00
|
|
|
"""
|
|
|
|
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
|
|
|
|
if platform.system() == 'Linux':
|
2023-05-31 10:49:17 -04:00
|
|
|
self._executable = 'sra'
|
2023-03-23 13:31:36 -04:00
|
|
|
elif platform.system() == 'Windows':
|
2023-07-11 16:35:13 -04:00
|
|
|
self._executable = 'sra.exe'
|
2023-06-07 14:48:21 -04:00
|
|
|
ExportsFactory('sra', self._city, output_file_path).export()
|
2023-03-23 13:31:36 -04:00
|
|
|
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)
|