ObjectConnection.py 2.2 KB

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