Skip to content
This repository has been archived by the owner on Oct 25, 2019. It is now read-only.

Commit

Permalink
Merge pull request #1 from mutantmonkey/master
Browse files Browse the repository at this point in the history
updating vtluug's fork
  • Loading branch information
paulwalko committed May 27, 2017
2 parents a10f513 + 42325d8 commit 7dc5ece
Show file tree
Hide file tree
Showing 8 changed files with 203 additions and 177 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ language: python
sudo: false
cache: pip
python:
- 3.2
- 3.3
- 3.4
- 3.5
- 3.6
install:
- pip install -r requirements.txt
script: nosetests
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ will need to be updated to run on Python3 if they do not already. All of the
core modules have been ported, removed, or replaced.

## Requirements
* Python 3.2+
* Python 3.4+
* [python-requests](http://docs.python-requests.org/en/latest/)

## Installation
Expand Down
57 changes: 38 additions & 19 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@
http://inamidst.com/phenny/
"""

import sys, os, time, threading, signal
import os
import signal
import sys
import threading
import time

class Watcher(object):

class Watcher(object):
# Cf. http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496735
def __init__(self):
self.child = os.fork()
Expand All @@ -18,51 +23,65 @@ def __init__(self):
self.watch()

def watch(self):
try: os.wait()
try:
os.wait()
except KeyboardInterrupt:
self.kill()
sys.exit()

def kill(self):
try: os.kill(self.child, signal.SIGKILL)
except OSError: pass
try:
os.kill(self.child, signal.SIGKILL)
except OSError:
pass

def sig_term(self, signum, frame):
self.kill()
sys.exit()

def run_phenny(config):
if hasattr(config, 'delay'):

def run_phenny(config):
if hasattr(config, 'delay'):
delay = config.delay
else: delay = 20
else:
delay = 20

def connect(config):
def connect(config):
import bot
p = bot.Phenny(config)
p.run(config.host, config.port, config.ssl, config.ipv6,
config.ca_certs)

try: Watcher()
ssl_context = p.get_ssl_context(config.ca_certs)
if config.ssl_cert and config.ssl_key:
ssl_context.load_cert_chain(config.ssl_cert, config.ssl_key)
p.run(config.host, config.port, config.ssl, config.ipv6, None,
ssl_context)

try:
Watcher()
except Exception as e:
print('Warning:', e, '(in __init__.py)', file=sys.stderr)

while True:
try: connect(config)
while True:
try:
connect(config)
except KeyboardInterrupt:
sys.exit()
sys.exit()

if not isinstance(delay, int):
break

warning = 'Warning: Disconnected. Reconnecting in %s seconds...' % delay
print(warning, file=sys.stderr)
msg = "Warning: Disconnected. Reconnecting in {0} seconds..."
print(msg.format(delay), file=sys.stderr)
time.sleep(delay)

def run(config):

def run(config):
t = threading.Thread(target=run_phenny, args=(config,))
if hasattr(t, 'run'):
t.run()
else: t.start()
else:
t.start()


if __name__ == '__main__':
print(__doc__)
Loading

0 comments on commit 7dc5ece

Please sign in to comment.