123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- class ObjectConnection:
- def __init__(self):
- self.RUN_OK = 0
- self.RUN_ERROR = 1
- self.QUIT = True
- self.olt = None
- self.brand = None
- self.model = None
- self.hostname = None
- self.user = None
- self.password = None
- self.password_enable = None
- self.port = None
- self.timeout = None
- self.file_name = None
- self.file_name_log = None
- self.file_name_exec = None
- self.data = None
- self.all_data = ""
- self.NEW_LINE_UNIX = '\n'
- self.NEW_LINE_WINDOWS = '\r\n'
- def initialize(self, brand, model, hostname, user, password, password_enable, port, file_name, data, timeout):
- """
- Initialize all properties
- :param brand:
- :param model:
- :param hostname:
- :param user:
- :param password:
- :param password_enable:
- :param port:
- :param file_name:
- :param data:
- :param timeout:
- :return:
- """
- self.brand = brand
- self.model = model
- self.hostname = hostname
- self.user = user
- self.password = password
- self.password_enable = password_enable
- self.port = port
- self.file_name = file_name
- self.data = data
- if file_name is not None:
- fl = file_name.split(".")
- fl.pop()
- self.file_name_log = ".".join(fl) + ".log"
- if file_name is not None:
- fl = file_name.split(".")
- fl.pop()
- self.file_name_exec = ".".join(fl) + ".exec"
- def save_log(self):
- """
- Save all data in log
- """
- if self.file_name_log:
- f = open(self.file_name_log, "w+")
- f.write(self.all_data)
- f.close()
- self.check_error_log()
- def check_error_log(self):
- """
- Check if scripts produce error
- """
- if self.olt.get_character_error() in self.all_data:
- self.RUN_OK = 1
- f = open(self.file_name_exec, "w+")
- f.write(str(self.RUN_OK))
- f.close()
- def command_print(self, command):
- """
- Print command
- :param command:
- """
- print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n" + command)
|