Advertisement
Guest User

fence_wti.diff

a guest
Jul 22nd, 2013
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 8.41 KB | None | 0 0
  1. 24,25c24,25
  2. < def get_listing(conn, options, listing_command):
  3. <         listing = ""
  4. ---
  5. > def get_power_status(conn, options):
  6. >   listing = ""
  7. 27,28c27,28
  8. <         try:
  9. <                 conn.send(listing_command+"\r\n")
  10. ---
  11. >   try:       
  12. >       conn.send("/S"+"\r\n")
  13. 30,149c30,42
  14. <                 if isinstance(options["-c"], list):
  15. <                         re_all = list(options["-c"])
  16. <                 else:
  17. <                         re_all = [options["-c"]]
  18. <                 re_next = re.compile("Enter: ", re.IGNORECASE)
  19. <                 re_all.append(re_next)
  20. <
  21. <                 result = conn.log_expect(options, re_all, int(options["-Y"]))
  22. <                 listing = conn.before
  23. <                 if result == (len(re_all) - 1):
  24. <                         conn.send("\r\n")
  25. <                         conn.log_expect(options, options["-c"], int(options["-Y"]))
  26. <                         listing += conn.before
  27. <
  28. <         except pexpect.EOF:
  29. <                 fail(EC_CONNECTION_LOST)
  30. <         except pexpect.TIMEOUT:
  31. <                 fail(EC_TIMED_OUT)
  32. <
  33. <         return listing
  34. <
  35. < def get_plug_status(conn, options):
  36. <         listing = get_listing(conn, options, "/S")
  37. <
  38. <         plug_section = 0
  39. <         outlets = {}
  40. <         for line in listing.splitlines():
  41. <                 if (plug_section == 2) and line.find("|") >= 0 and line.startswith("PLUG") == False:
  42. <                         plug_line = [x.strip().lower() for x in line.split("|")]
  43. <                         if len(plug_line) < len(plug_header):
  44. <                                 plug_section = -1
  45. <                                 pass
  46. <                         if ["list", "monitor"].count(options["-o"]) == 0 and options["-n"].lower() == plug_line[plug_index]:
  47. <                                 return plug_line[status_index]
  48. <                         else:
  49. <                                 ## We already believe that first column contains plug number
  50. <                                 if len(plug_line[0]) != 0:
  51. <                                         outlets[plug_line[0]] = (plug_line[name_index], plug_line[status_index])
  52. <                 elif (plug_section == 1):
  53. <                         plug_section = 2
  54. <                         pass
  55. <                 elif (line.upper().startswith("PLUG")):
  56. <                         plug_section = 1
  57. <                         plug_header = [x.strip().lower() for x in line.split("|")]
  58. <                         plug_index = plug_header.index("plug")
  59. <                         name_index = plug_header.index("name")
  60. <                         status_index = plug_header.index("status")
  61. <
  62. <         if ["list", "monitor"].count(options["-o"]) == 1:
  63. <                 return outlets
  64. <         else:
  65. <                 return "PROBLEM"
  66. <
  67. < def get_plug_group_status_from_list(status_list):
  68. <         for status in status_list:
  69. <                 if status == "on":
  70. <                       return status
  71. <         return "off"
  72. <
  73. < def get_plug_group_status(conn, options):
  74. <         listing = get_listing(conn, options, "/SG")
  75. <
  76. <         plug_section = 0
  77. <         outlets = {}
  78. <         current_outlet = ""
  79. <         line_index = 0
  80. <         lines = listing.splitlines()
  81. <         while line_index < len(lines) and line_index >= 0:
  82. <                 line = lines[line_index]
  83. <                 if (line.find("|") >= 0 and line.lstrip().startswith("GROUP NAME") == False):
  84. <                         plug_line = [x.strip().lower() for x in line.split("|")]
  85. <                         if ["list", "monitor"].count(options["-o"]) == 0 and options["-n"].lower() == plug_line[name_index]:
  86. <                                 line_index += 1
  87. <                                 plug_status = []
  88. <                                 while line_index < len(lines) and line_index >= 0:
  89. <                                         plug_line = [x.strip().lower() for x in lines[line_index].split("|")]
  90. <                                         if len(plug_line[plug_index]) > 0 and len(plug_line[name_index]) == 0:
  91. <                                                 plug_status.append(plug_line[status_index])
  92. <                                                 line_index += 1
  93. <                                         else:
  94. <                                                 line_index = -1
  95. <
  96. <                                 return get_plug_group_status_from_list(plug_status)
  97. <  
  98. <                         else:
  99. <                                 ## We already believe that first column contains plug number
  100. <                                 if len(plug_line[0]) != 0:
  101. <                                         group_name = plug_line[0]
  102. <                                         plug_line_index = line_index + 1
  103. <                                         plug_status = []
  104. <                                         while plug_line_index < len(lines) and plug_line_index >= 0:
  105. <                                                 plug_line = [x.strip().lower() for x in lines[plug_line_index].split("|")]
  106. <                                                 if len(plug_line[name_index]) > 0:
  107. <                                                         plug_line_index = -1
  108. <                                                         break
  109. <                                                 if len(plug_line[plug_index]) > 0:
  110. <                                                         plug_status.append(plug_line[status_index])
  111. <                                                         plug_line_index += 1
  112. <                                                 else:
  113. <                                                         plug_line_index = -1
  114. <                                         outlets[group_name] = (group_name, get_plug_group_status_from_list(plug_status))
  115. <                                 line_index += 1
  116. <
  117. <                 elif (line.upper().lstrip().startswith("GROUP NAME")):
  118. <                         plug_header = [x.strip().lower() for x in line.split("|")]
  119. <                         name_index = plug_header.index("group name")
  120. <                         plug_index = plug_header.index("plug")
  121. <                         status_index = plug_header.index("status")
  122. <                         line_index += 2
  123. <                 else:
  124. <                         line_index += 1
  125. <
  126. <
  127. <         if ["list", "monitor"].count(options["-o"]) == 1:
  128. <                 for group, status in outlet_groups:
  129. <                         outlets[group] = (group, status[0])
  130. <
  131. <                 return outlets
  132. <         else:
  133. <                 return "PROBLEM"
  134. ---
  135. >       if isinstance(options["-c"], list):
  136. >           re_all = list(options["-c"])
  137. >       else:
  138. >           re_all = [options["-c"]]
  139. >       re_next = re.compile("Enter: ", re.IGNORECASE)
  140. >       re_all.append(re_next)
  141. >
  142. >       result = conn.log_expect(options, re_all, int(options["-Y"]))
  143. >       listing = conn.before
  144. >       if result == (len(re_all) - 1):
  145. >           conn.send("\r\n")
  146. >           conn.log_expect(options, options["-c"], int(options["-Y"]))
  147. >           listing += conn.before
  148. 151,155c44,71
  149. < def get_power_status(conn, options):
  150. <         ret = get_plug_status(conn, options)
  151. <        
  152. <         if ret == "PROBLEM":
  153. <                 ret = get_plug_group_status(conn, options)
  154. ---
  155. >   except pexpect.EOF:
  156. >       fail(EC_CONNECTION_LOST)
  157. >   except pexpect.TIMEOUT:
  158. >       fail(EC_TIMED_OUT)
  159. >  
  160. >   plug_section = 0
  161. >   outlets = {}
  162. >   for line in listing.splitlines():
  163. >       if (plug_section == 2) and line.find("|") >= 0 and line.startswith("PLUG") == False:
  164. >           plug_line = [x.strip().lower() for x in line.split("|")]
  165. >           if len(plug_line) < len(plug_header):
  166. >               plug_section = -1
  167. >               pass
  168. >           if ["list", "monitor"].count(options["-o"]) == 0 and options["-n"].lower() == plug_line[plug_index]:
  169. >               return plug_line[status_index]
  170. >           else:
  171. >               ## We already believe that first column contains plug number
  172. >               if len(plug_line[0]) != 0:
  173. >                   outlets[plug_line[0]] = (plug_line[name_index], plug_line[status_index])
  174. >       elif (plug_section == 1):
  175. >           plug_section = 2
  176. >           pass
  177. >       elif (line.upper().startswith("PLUG")):
  178. >           plug_section = 1
  179. >           plug_header = [x.strip().lower() for x in line.split("|")]
  180. >           plug_index = plug_header.index("plug")
  181. >           name_index = plug_header.index("name")
  182. >           status_index = plug_header.index("status")
  183. 157c73,76
  184. <         return ret
  185. ---
  186. >   if ["list", "monitor"].count(options["-o"]) == 1:
  187. >       return outlets
  188. >   else:
  189. >       return "PROBLEM"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement