patch 41f19aaddb6d10537b87620bf88715276dc7f234
Author: E. Bosch <presidev@AT@gmail.com>
Date: Sat Dec 11 22:32:43 CET 2021
* Add configuration file support
hunk ./irgramd 19
- def __init__(self, address=None, port=None, config_dir=None, **settings):
- self.logger = logging.getLogger()
+ def __init__(self, logger, config_direc, address=None, port=None, **settings):
+ self.logger = logger
hunk ./irgramd 41
- self.config_dir = config_dir or os.path.expanduser('~/.config/irgramd')
+ self.config_dir = config_direc
hunk ./irgramd 45
- if not os.path.exists(self.config_dir):
- os.makedirs(self.config_dir)
hunk ./irgramd 52
- self.logger.info('Configuration Directory: %s', self.config_dir)
-
hunk ./irgramd 61
+ logger = logging.getLogger()
+ tornado.options.define('config', default='irgramdrc', metavar='CONFIGFILE', help='Config file absolute or relative to `config_dir` (command line options override it)')
hunk ./irgramd 65
- tornado.options.define('config_dir', default=None, metavar='PATH', help='Configuration directory')
+ tornado.options.define('config_dir', default='~/.config/irgramd', metavar='PATH', help='Configuration directory where telegram session info is saved')
hunk ./irgramd 69
+ # parse cmd line first time to get --config and --config_dir
hunk ./irgramd 71
+ config_file = os.path.expanduser(tornado.options.options.config)
+ config_dir = os.path.expanduser(tornado.options.options.config_dir)
+ if not os.path.exists(config_dir):
+ os.makedirs(config_dir)
+ logger.info('Configuration Directory: %s', config_dir)
+
+ if not os.path.isabs(config_file):
+ config_file = os.path.join(config_dir, config_file)
+ if os.path.isfile(config_file):
+ logger.info('Using configuration file: %s', config_file)
+ tornado.options.parse_config_file(config_file)
+ else:
+ logger.warning('Configuration file not present, using only command line options and defaults')
+ # parse cmd line second time to override file options
+ tornado.options.parse_command_line()
hunk ./irgramd 88
- irc_server = IRCTelegramd(**options)
+
+ irc_server = IRCTelegramd(logger, config_dir, **options)