Skip to content
Snippets Groups Projects
Commit 44237c0f authored by Pavel Kácha's avatar Pavel Kácha
Browse files

Print as a function (Py3 preparation) (thx krkos@cesnet.cz)

parent 9b9fabc1
No related branches found
No related tags found
No related merge requests found
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
# Copyright (C) 2011-2015 Cesnet z.s.p.o # Copyright (C) 2011-2015 Cesnet z.s.p.o
# Use of this source is governed by a 3-clause BSD-style license, see LICENSE file. # Use of this source is governed by a 3-clause BSD-style license, see LICENSE file.
from __future__ import print_function
import sys import sys
import os import os
import logging import logging
...@@ -1473,7 +1475,7 @@ def build_server(conf, section_order=section_order, section_def=section_def, par ...@@ -1473,7 +1475,7 @@ def build_server(conf, section_order=section_order, section_def=section_def, par
def check_config(): def check_config():
# If we got so far, server object got set up fine # If we got so far, server object got set up fine
print >>sys.stderr, "Looks clear." print("Looks clear.", file=sys.stderr)
return 0 return 0
...@@ -1483,7 +1485,7 @@ def list_clients(id=None): ...@@ -1483,7 +1485,7 @@ def list_clients(id=None):
col_width = [max(len(val) for val in col) for col in zip(*(lines+[Client._fields]))] col_width = [max(len(val) for val in col) for col in zip(*(lines+[Client._fields]))]
divider = ["-" * l for l in col_width] divider = ["-" * l for l in col_width]
for line in [Client._fields, divider] + lines: for line in [Client._fields, divider] + lines:
print " ".join([val.ljust(width) for val, width in zip(line, col_width)]) print(" ".join([val.ljust(width) for val, width in zip(line, col_width)]))
return 0 return 0
...@@ -1529,29 +1531,29 @@ def modify_client(**kwargs): ...@@ -1529,29 +1531,29 @@ def modify_client(**kwargs):
if kwargs["name"] is not None: if kwargs["name"] is not None:
kwargs["name"] = kwargs["name"].lower() kwargs["name"] = kwargs["name"].lower()
if not isValidNSID(kwargs["name"]): if not isValidNSID(kwargs["name"]):
print >>sys.stderr, "Invalid client name \"%s\"." % kwargs["name"] print("Invalid client name \"%s\"." % (kwargs["name"]), file=sys.stderr)
return 254 return 254
if kwargs["hostname"] is not None: if kwargs["hostname"] is not None:
kwargs["hostname"] = kwargs["hostname"].lower() kwargs["hostname"] = kwargs["hostname"].lower()
if not isValidHostname(kwargs["hostname"]): if not isValidHostname(kwargs["hostname"]):
print >>sys.stderr, "Invalid hostname \"%s\"." % kwargs["hostname"] print("Invalid hostname \"%s\"." % (kwargs["hostname"]), file=sys.stderr)
return 253 return 253
if kwargs["requestor"] is not None and not isValidEmail(kwargs["requestor"]): if kwargs["requestor"] is not None and not isValidEmail(kwargs["requestor"]):
print >>sys.stderr, "Invalid requestor email \"%s\"." % kwargs["requestor"] print("Invalid requestor email \"%s\"." % (kwargs["requestor"]), file=sys.stderr)
return 252 return 252
if kwargs["id"] is not None and not isValidID(kwargs["id"]): if kwargs["id"] is not None and not isValidID(kwargs["id"]):
print >>sys.stderr, "Invalid id \"%s\"." % kwargs["id"] print("Invalid id \"%s\"." % (kwargs["id"]), file=sys.stderr)
return 251 return 251
for c in server.handler.db.get_clients(): for c in server.handler.db.get_clients():
if kwargs["name"] is not None and kwargs["name"].lower()==c.name: if kwargs["name"] is not None and kwargs["name"].lower()==c.name:
print >>sys.stderr, "Clash with existing name: %s" % str(c) print("Clash with existing name: %s" % (str(c)), file=sys.stderr)
return 250 return 250
if kwargs["secret"] is not None and kwargs["secret"]==c.secret: if kwargs["secret"] is not None and kwargs["secret"]==c.secret:
print >>sys.stderr, "Clash with existing secret: %s" % str(c) print("Clash with existing secret: %s" % str(c), file=sys.stderr)
return 249 return 249
newid = server.handler.db.add_modify_client(**kwargs) newid = server.handler.db.add_modify_client(**kwargs)
...@@ -1569,10 +1571,10 @@ def purge(days=30, lastlog=None, events=None): ...@@ -1569,10 +1571,10 @@ def purge(days=30, lastlog=None, events=None):
lastlog = events = True lastlog = events = True
if lastlog: if lastlog:
count = server.handler.db.purge_lastlog(days) count = server.handler.db.purge_lastlog(days)
print "Purged %d lastlog entries." % count print("Purged %d lastlog entries." % (count))
if events: if events:
count = server.handler.db.purge_events(days) count = server.handler.db.purge_events(days)
print "Purged %d events." % count print("Purged %d events." % (count))
return 0 return 0
...@@ -1695,6 +1697,6 @@ if __name__=="__main__": ...@@ -1695,6 +1697,6 @@ if __name__=="__main__":
del subargs["command"] del subargs["command"]
del subargs["config"] del subargs["config"]
if not server or server is fallback_wsgi: if not server or server is fallback_wsgi:
print >>sys.stderr, "Failed initialization, check configured log targets for reasons." print("Failed initialization, check configured log targets for reasons.", file=sys.stderr)
sys.exit(255) sys.exit(255)
sys.exit(command(**subargs)) sys.exit(command(**subargs))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment