3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-24 11:39:25 +01:00

Convert print() calls to log calls, Round 1

This commit is contained in:
James Lu 2015-07-05 13:29:01 -07:00
parent f06bcc7928
commit 54dff7a15a
2 changed files with 14 additions and 14 deletions

16
main.py
View File

@ -35,7 +35,7 @@ class Irc():
ip = self.serverdata["ip"] ip = self.serverdata["ip"]
port = self.serverdata["port"] port = self.serverdata["port"]
self.sid = self.serverdata["sid"] self.sid = self.serverdata["sid"]
log.info("Connecting to network %r on %s:%s" % (self.name, ip, port)) log.info("Connecting to network %r on %s:%s", self.name, ip, port)
self.socket = socket.socket() self.socket = socket.socket()
self.socket.connect((ip, port)) self.socket.connect((ip, port))
@ -57,16 +57,16 @@ class Irc():
break break
while '\n' in buf: while '\n' in buf:
line, buf = buf.split('\n', 1) line, buf = buf.split('\n', 1)
log.debug("<- {}".format(line)) log.debug("<- %s", line)
proto.handle_events(self, line) proto.handle_events(self, line)
except socket.error as e: except socket.error as e:
log.error('Received socket.error: %s, exiting.' % str(e)) log.error('Received socket.error: %s, exiting.', str(e))
break break
sys.exit(1) sys.exit(1)
def send(self, data): def send(self, data):
data = data.encode("utf-8") + b"\n" data = data.encode("utf-8") + b"\n"
log.debug("-> {}".format(data.decode("utf-8").strip("\n"))) log.debug("-> %s", data.decode("utf-8").strip("\n"))
self.socket.send(data) self.socket.send(data)
def load_plugins(self): def load_plugins(self):
@ -80,9 +80,9 @@ class Irc():
self.loaded.append(imp.load_source(plugin, moduleinfo[1])) self.loaded.append(imp.load_source(plugin, moduleinfo[1]))
except ImportError as e: except ImportError as e:
if str(e).startswith('No module named'): if str(e).startswith('No module named'):
log.error('Failed to load plugin %r: the plugin could not be found.' % plugin) log.error('Failed to load plugin %r: the plugin could not be found.', plugin)
else: else:
log.error('Failed to load plugin %r: import error %s' % (plugin, str(e))) log.error('Failed to load plugin %r: import error %s', plugin, str(e))
print("loaded plugins: %s" % self.loaded) print("loaded plugins: %s" % self.loaded)
if __name__ == '__main__': if __name__ == '__main__':
@ -98,9 +98,9 @@ if __name__ == '__main__':
proto = imp.load_source(protoname, moduleinfo[1]) proto = imp.load_source(protoname, moduleinfo[1])
except ImportError as e: except ImportError as e:
if str(e).startswith('No module named'): if str(e).startswith('No module named'):
log.critical('Failed to load protocol module %r: the file could not be found.' % protoname) log.critical('Failed to load protocol module %r: the file could not be found.', protoname)
else: else:
log.critical('Failed to load protocol module: import error %s' % (protoname, str(e))) log.critical('Failed to load protocol module: import error %s', protoname, str(e))
sys.exit(2) sys.exit(2)
else: else:
irc_obj = Irc(proto) irc_obj = Irc(proto)

View File

@ -78,9 +78,9 @@ def removeClient(irc, numeric):
for v in irc.channels.values(): for v in irc.channels.values():
v.removeuser(numeric) v.removeuser(numeric)
sid = numeric[:3] sid = numeric[:3]
print('Removing client %s from irc.users' % numeric) log.debug('Removing client %s from irc.users', numeric)
del irc.users[numeric] del irc.users[numeric]
print('Removing client %s from irc.servers[%s]' % (numeric, sid)) log.debug('Removing client %s from irc.servers[%s]', numeric, sid)
irc.servers[sid].users.remove(numeric) irc.servers[sid].users.remove(numeric)
def quitClient(irc, numeric, reason): def quitClient(irc, numeric, reason):
@ -221,7 +221,7 @@ def handle_uid(irc, numeric, command, args):
realname = args[-1] realname = args[-1]
irc.users[uid] = IrcUser(nick, ts, uid, ident, host, realname, realhost, ip) irc.users[uid] = IrcUser(nick, ts, uid, ident, host, realname, realhost, ip)
parsedmodes = utils.parseModes(irc, uid, [args[8], args[9]]) parsedmodes = utils.parseModes(irc, uid, [args[8], args[9]])
print('Applying modes %s for %s' % (parsedmodes, uid)) log.debug('Applying modes %s for %s', parsedmodes, uid)
utils.applyModes(irc, uid, parsedmodes) utils.applyModes(irc, uid, parsedmodes)
irc.servers[numeric].users.append(uid) irc.servers[numeric].users.append(uid)
return {'uid': uid, 'ts': ts, 'nick': nick, 'realhost': realhost, 'host': host, 'ident': ident, 'ip': ip} return {'uid': uid, 'ts': ts, 'nick': nick, 'realhost': realhost, 'host': host, 'ident': ident, 'ip': ip}
@ -286,15 +286,15 @@ def handle_mode(irc, numeric, command, args):
def handle_squit(irc, numeric, command, args): def handle_squit(irc, numeric, command, args):
# :70M SQUIT 1ML :Server quit by GL!gl@0::1 # :70M SQUIT 1ML :Server quit by GL!gl@0::1
split_server = args[0] split_server = args[0]
print('Netsplit on server %s' % split_server) log.info('(%s) Netsplit on server %s', irc.name, split_server)
# Prevent RuntimeError: dictionary changed size during iteration # Prevent RuntimeError: dictionary changed size during iteration
old_servers = copy(irc.servers) old_servers = copy(irc.servers)
for sid, data in old_servers.items(): for sid, data in old_servers.items():
if data.uplink == split_server: if data.uplink == split_server:
print('Server %s also hosts server %s, removing those users too...' % (split_server, sid)) log.debug('Server %s also hosts server %s, removing those users too...', split_server, sid)
handle_squit(irc, sid, 'SQUIT', [sid, "PyLink: Automatically splitting leaf servers of %s" % sid]) handle_squit(irc, sid, 'SQUIT', [sid, "PyLink: Automatically splitting leaf servers of %s" % sid])
for user in copy(irc.servers[split_server].users): for user in copy(irc.servers[split_server].users):
print('Removing client %s (%s)' % (user, irc.users[user].nick)) log.debug('Removing client %s (%s)', user, irc.users[user].nick)
removeClient(irc, user) removeClient(irc, user)
del irc.servers[split_server] del irc.servers[split_server]
return {'target': split_server} return {'target': split_server}