dynamic_building_simulation/insel/insel.py
2020-05-02 00:33:06 +02:00

55 lines
1.3 KiB
Python

import os
from pathlib import Path
class Insel:
def __init__(self, path, name, new_content="", keep_files=False):
self._path = path
self._name = name
self._full_path = None
self._content = None
self._results = None
self._keep_files = keep_files
self.add_content(new_content)
self.save()
self.run()
def save(self):
with open(self._full_path, 'w') as insel_file:
insel_file.write(self.content)
return
@property
def full_path(self):
if self._full_path is None:
self._full_path = (Path(self._path) / 'third_parties_files/insel' / self._name).resolve()
return self._full_path
@property
def content(self):
if self._content is None:
if os.path.exists(self.full_path):
with open(self.full_path, 'r') as insel_file:
self._content = insel_file.read()
else:
self._content = ''
return self._content
# todo: create method
def add_block(self):
raise Exception('Not implemented')
def add_content(self, new_content):
self._content = self.content + '\r\n' + new_content
return
def run(self):
finish = os.system('insel ' + str(self.full_path))
os.close(finish)
if not self._keep_files:
os.remove(self.full_path)
@property
def results(self):
raise Exception('Not implemented')