checks if reconnect needed
(self)
| 158 | |
| 159 | #---------------------------------------------------------------------- |
| 160 | def tryReconnect(self): |
| 161 | """checks if reconnect needed""" |
| 162 | |
| 163 | if not (self.core.config["reconnect"]["activated"] and self.core.api.isTimeReconnect()): |
| 164 | return False |
| 165 | |
| 166 | active = [x.active.plugin.wantReconnect and x.active.plugin.waiting for x in self.threads if x.active] |
| 167 | |
| 168 | if not (0 < active.count(True) == len(active)): |
| 169 | return False |
| 170 | |
| 171 | if not exists(self.core.config['reconnect']['method']): |
| 172 | if exists(join(pypath, self.core.config['reconnect']['method'])): |
| 173 | self.core.config['reconnect']['method'] = join(pypath, self.core.config['reconnect']['method']) |
| 174 | else: |
| 175 | self.core.config["reconnect"]["activated"] = False |
| 176 | self.log.warning(_("Reconnect script not found!")) |
| 177 | return |
| 178 | |
| 179 | self.reconnecting.set() |
| 180 | |
| 181 | #Do reconnect |
| 182 | self.log.info(_("Starting reconnect")) |
| 183 | |
| 184 | while [x.active.plugin.waiting for x in self.threads if x.active].count(True) != 0: |
| 185 | sleep(0.25) |
| 186 | |
| 187 | ip = self.getIP() |
| 188 | |
| 189 | self.core.hookManager.beforeReconnecting(ip) |
| 190 | |
| 191 | self.log.debug("Old IP: %s" % ip) |
| 192 | |
| 193 | try: |
| 194 | reconn = Popen(self.core.config['reconnect']['method'], bufsize=-1, shell=True)#, stdout=subprocess.PIPE) |
| 195 | except: |
| 196 | self.log.warning(_("Failed executing reconnect script!")) |
| 197 | self.core.config["reconnect"]["activated"] = False |
| 198 | self.reconnecting.clear() |
| 199 | if self.core.debug: |
| 200 | print_exc() |
| 201 | return |
| 202 | |
| 203 | reconn.wait() |
| 204 | sleep(1) |
| 205 | ip = self.getIP() |
| 206 | self.core.hookManager.afterReconnecting(ip) |
| 207 | |
| 208 | self.log.info(_("Reconnected, new IP: %s") % ip) |
| 209 | |
| 210 | self.reconnecting.clear() |
| 211 | |
| 212 | def getIP(self): |
| 213 | """retrieve current ip""" |
no test coverage detected