ObjectConnection.py 2.2 KB

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