ObjectConnection.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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.data = data
  46. if file_name is not None:
  47. fl = file_name.split(".")
  48. fl.pop()
  49. self.file_name_log = ".".join(fl) + ".log"
  50. if file_name is not None:
  51. fl = file_name.split(".")
  52. fl.pop()
  53. self.file_name_exec = ".".join(fl) + ".exec"
  54. def save_log(self):
  55. """
  56. Save all data in log
  57. """
  58. if self.file_name_log:
  59. f = open(self.file_name_log, "w+")
  60. f.write(self.all_data)
  61. f.close()
  62. self.check_error_log()
  63. def check_error_log(self):
  64. """
  65. Check if scripts produce error
  66. """
  67. if self.olt.get_character_error() in self.all_data:
  68. self.RUN_OK = 1
  69. f = open(self.file_name_exec, "w+")
  70. f.write(str(self.RUN_OK))
  71. f.close()
  72. def command_print(self, command):
  73. """
  74. Print command
  75. :param command:
  76. """
  77. print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n" + command)