36 lines
1.1 KiB
Python
36 lines
1.1 KiB
Python
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, output_file_path):
|
|
"""
|
|
SRA class
|
|
:param city: City
|
|
:param output_file_path: path to output the sra calculation
|
|
"""
|
|
self._city = city
|
|
self._output_file_path = output_file_path
|
|
if platform.system() == 'Linux':
|
|
self._executable = 'sra'
|
|
elif platform.system() == 'Windows':
|
|
self._executable = 'sra.exe'
|
|
ExportsFactory('sra', self._city, output_file_path).export()
|
|
self._run()
|
|
ResultFactory('sra', self._city, output_file_path).enrich()
|
|
|
|
def _run(self):
|
|
"""
|
|
Calls the software
|
|
"""
|
|
try:
|
|
subprocess.run([self._executable,
|
|
(self._output_file_path / f'{self._city.name}_sra.xml')],
|
|
stdout=subprocess.DEVNULL)
|
|
except (SubprocessError, TimeoutExpired, CalledProcessError) as error:
|
|
raise Exception(error)
|