from mylinux import view
from mylinux.libs import AppErr
[docs]class Script:
"""Class for handeling scripts data etc...
Args:
name (str): Name of the script.
path (str): Absolute path to the scirpt.
Attributes:
__data (str): All data from file on path.
__name (str): Name of the script.
__path (str): Absolute path to the script.
__cmdArrays (arr-arr-str): Script commands.
Other Parameters:
Update __data and __cmdArrays variables.
"""
def __init__(self, name, path):
self.__data = None
self.__name = name
self.__path = path
self.__cmdArrays = None
self.update()
[docs] def __call__(self):
"""
Return:
__data
"""
return self.__data
@property
def name(self):
"""
Return:
__name
"""
return self.__name
@property
def path(self):
"""
Return:
__path
"""
return self.__path
@property
def cmdArrays(self):
"""
Return:
__cmdArrays
"""
return self.__cmdArrays
[docs] def update(self):
"""Update __data and __cmdArrays
Other Parameters:
Check if file exist on __path.
If check fails show error report.
Set __data variable.
Split file on lines.
Split every line on words.
Set __cmdArrays variable.
"""
try:
with open(self.__path) as f:
self.__data = f.read()
except Exception as err:
view.Tli.raiseError(
AppErr.model,
self.__path,
['ERROR', 'File open', err[1]]
)
self.__cmdArrays = []
array = self.__data.split('\n')
for line in array:
if line:
self.__cmdArrays.append(line.split())