patch 275639e05e10d91ef44554c6a8a24efed5145c4e
Author: Peter Bui <pbui@bx612.space>
Date: Fri Jul 26 03:05:21 CEST 2019
* Rename classes, add command line options
hunk ./irtelegramd.py 30
-# IRC Server
-
-class IRCServer(tornado.tcpserver.TCPServer):
- def __init__(self, address=None, port=6667):
+# IRC Telegram Daemon
+
+class IRCTelegramd(tornado.tcpserver.TCPServer):
+ def __init__(self, address=None, port=6667, config_dir=None, **settings):
hunk ./irtelegramd.py 36
- self.logger = logging.getLogger()
- self.address = address or '127.0.0.1'
- self.port = port
-
- self.logger.setLevel(logging.INFO)
+ self.logger = logging.getLogger()
+ self.address = address or '127.0.0.1'
+ self.port = port
+ self.config_dir = config_dir or os.path.expanduser('~/.config/irtelegramd')
+
+ if not os.path.exists(self.config_dir):
+ os.makedirs(self.config_dir)
hunk ./irtelegramd.py 45
- client = IRCClient(stream, address)
- await client.run()
+ handler = IRCHandler(stream, address, self.config_dir)
+ await handler.run()
hunk ./irtelegramd.py 62
-# IRC Client
-
-class IRCClient(object):
- def __init__(self, stream, address):
+# IRC Handler
+
+class IRCHandler(object):
+ def __init__(self, stream, address, config_dir):
hunk ./irtelegramd.py 71
-
- # Initialize configuration directory
- self.config_dir = os.path.expanduser('~/.config/irtelegramd')
- if not os.path.exists(self.config_dir):
- os.makedirs(self.config_dir)
+ self.config_dir = config_dir
hunk ./irtelegramd.py 400
- # TODO: Make configuration directory settable at run-time
- irc_server = IRCServer()
+ tornado.options.define('address', default=None, help='Address to listen on.')
+ tornado.options.define('port', default=6667, help='Port to listen on.')
+ tornado.options.define('config_dir', default=None, help='Configuration directory')
+ tornado.options.parse_command_line()
+
+ options = tornado.options.options.as_dict()
+ irc_server = IRCTelegramd(**options)