ObjectConnection.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. class ObjectConnection:
  2. def __init__(self):
  3. self.RUN_OK = 0
  4. self.RUN_ERROR = 1
  5. self.QUIT = True
  6. self.olt = None
  7. self.brand = None
  8. self.model = None
  9. self.hostname = None
  10. self.user = None
  11. self.password = None
  12. self.password_enable = None
  13. self.port = None
  14. self.timeout = None
  15. self.file_name = None
  16. self.file_name_log = None
  17. self.file_name_exec = None
  18. self.data = None
  19. self.all_data = ""
  20. self.NEW_LINE_UNIX = '\n'
  21. self.NEW_LINE_WINDOWS = '\r\n'
  22. def initialize(self, brand, model, hostname, user, password, password_enable, port, file_name, data, timeout):
  23. """
  24. Initialize all properties
  25. :param brand:
  26. :param model:
  27. :param hostname:
  28. :param user:
  29. :param password:
  30. :param password_enable:
  31. :param port:
  32. :param file_name:
  33. :param data:
  34. :param timeout:
  35. :return:
  36. """
  37. self.brand = brand
  38. self.model = model
  39. self.hostname = hostname
  40. self.user = user
  41. self.password = password
  42. self.password_enable = password_enable
  43. self.port = port
  44. self.file_name = file_name
  45. self.timeout = timeout
  46. self.data = data
  47. if file_name is not None:
  48. fl = file_name.split(".")
  49. fl.pop()
  50. self.file_name_log = ".".join(fl) + ".log"
  51. if file_name is not None:
  52. fl = file_name.split(".")
  53. fl.pop()
  54. self.file_name_exec = ".".join(fl) + ".exec"
  55. def save_log(self):
  56. """
  57. Save all data in log
  58. """
  59. if self.file_name_log:
  60. f = open(self.file_name_log, "w+")
  61. f.write(self.all_data)
  62. f.close()
  63. self.check_error_log()
  64. def check_error_log(self):
  65. """
  66. Check if scripts produce error
  67. """
  68. if self.olt.get_character_error() in self.all_data:
  69. self.RUN_OK = 1
  70. f = open(self.file_name_exec, "w+")
  71. f.write(str(self.RUN_OK))
  72. f.close()
  73. def command_print(self, command):
  74. """
  75. Print command
  76. :param command:
  77. """
  78. print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n" + command)