Add a check for non-existent config file

This commit is contained in:
Alexei Sorokin 2016-08-11 00:26:08 +03:00
parent 39da2633f5
commit bf916e83fd

View File

@ -258,28 +258,32 @@ class Intermedia:
self.xmpp_users.remove(user) self.xmpp_users.remove(user)
if __name__ == '__main__': if __name__ == '__main__':
parser = SafeConfigParser() config = SafeConfigParser()
shared_opts = {} shared_opts = {}
xmpp_opts = {} xmpp_opts = {}
irc_opts = {} irc_opts = {}
if len(sys.argv) > 1: if len(sys.argv) > 1:
parser.read(sys.argv[1]) config.read(sys.argv[1])
else: else:
parser.read('config.ini') config.read('config.ini')
shared_opts['prefix'] = parser.get('Shared', 'prefix') if not config.sections():
shared_opts['owner'] = parser.get('Shared', 'owner') sys.stderr.write('Error: Configuration file does not exist or is empty.\n')
sys.exit(1)
irc_opts['chan'] = parser.get('IRC', 'channel') shared_opts['prefix'] = config.get('Shared', 'prefix')
irc_opts['nick'] = parser.get('IRC', 'nick') shared_opts['owner'] = config.get('Shared', 'owner')
irc_opts['server'] = parser.get('IRC', 'server')
irc_opts['port'] = int(parser.get('IRC', 'port'))
xmpp_opts['jid'] = parser.get('XMPP', 'jid') irc_opts['chan'] = config.get('IRC', 'channel')
xmpp_opts['passwd'] = parser.get('XMPP', 'password') irc_opts['nick'] = config.get('IRC', 'nick')
xmpp_opts['muc'] = parser.get('XMPP', 'muc') irc_opts['server'] = config.get('IRC', 'server')
xmpp_opts['nick'] = parser.get('XMPP', 'nick') irc_opts['port'] = int(config.get('IRC', 'port'))
xmpp_opts['jid'] = config.get('XMPP', 'jid')
xmpp_opts['passwd'] = config.get('XMPP', 'password')
xmpp_opts['muc'] = config.get('XMPP', 'muc')
xmpp_opts['nick'] = config.get('XMPP', 'nick')
try: try:
inter = Intermedia(shared_opts, irc_opts['chan'], xmpp_opts['muc']) inter = Intermedia(shared_opts, irc_opts['chan'], xmpp_opts['muc'])