Skip to content

Commit

Permalink
Replace print with log.msg().
Browse files Browse the repository at this point in the history
also 2 more compatability fixes (func_name->__name__), (exception, e->exception as e)
  • Loading branch information
lurimax-north committed Jun 18, 2015
1 parent 5330478 commit 4d733e6
Show file tree
Hide file tree
Showing 19 changed files with 168 additions and 155 deletions.
5 changes: 3 additions & 2 deletions slave/buildslave/commands/repo.py
Expand Up @@ -18,6 +18,7 @@
import textwrap

from twisted.internet import defer
from twisted.python import log

from buildslave import runprocess
from buildslave.commands.base import AbandonChain
Expand Down Expand Up @@ -66,8 +67,8 @@ def _fullSrcdir(self):
return os.path.join(self.builder.basedir, self.srcdir)

def sourcedirIsUpdateable(self):
print os.path.join(self._fullSrcdir(), ".repo")
print os.path.isdir(os.path.join(self._fullSrcdir(), ".repo"))
log.msg(os.path.join(self._fullSrcdir(), ".repo"))
log.msg(os.path.isdir(os.path.join(self._fullSrcdir(), ".repo")))
return os.path.isdir(os.path.join(self._fullSrcdir(), ".repo"))

def _repoCmd(self, command, cb=None, abandonOnFailure=True, **kwargs):
Expand Down
6 changes: 4 additions & 2 deletions slave/buildslave/scripts/base.py
Expand Up @@ -15,15 +15,17 @@

import os

from twisted.python import log


def isBuildslaveDir(dir):
def print_error(error_message):
print "%s\ninvalid buildslave directory '%s'" % (error_message, dir)
log.msg("%s\ninvalid buildslave directory '%s'" % (error_message, dir))

buildbot_tac = os.path.join(dir, "buildbot.tac")
try:
contents = open(buildbot_tac).read()
except IOError, exception:
except IOError as exception:
print_error("error reading '%s': %s" %
(buildbot_tac, exception.strerror))
return False
Expand Down
29 changes: 15 additions & 14 deletions slave/buildslave/scripts/create_slave.py
Expand Up @@ -15,6 +15,7 @@

import os

from twisted.python import log

slaveTACTemplate = ["""
import os
Expand Down Expand Up @@ -83,11 +84,11 @@ def _makeBaseDir(basedir, quiet):
"""
if os.path.exists(basedir):
if not quiet:
print "updating existing installation"
log.msg("updating existing installation")
return

if not quiet:
print "mkdir", basedir
log.msg("mkdir", basedir)

try:
os.mkdir(basedir)
Expand Down Expand Up @@ -118,12 +119,12 @@ def _makeBuildbotTac(basedir, tac_file_contents, quiet):

if oldcontents == tac_file_contents:
if not quiet:
print "buildbot.tac already exists and is correct"
log.msg("buildbot.tac already exists and is correct")
return

if not quiet:
print "not touching existing buildbot.tac"
print "creating buildbot.tac.new instead"
log.msg("not touching existing buildbot.tac")
log.msg("creating buildbot.tac.new instead")

tacfile = os.path.join(basedir, "buildbot.tac.new")

Expand Down Expand Up @@ -154,8 +155,8 @@ def createFile(path, file, contents):
return False

if not quiet:
print "Creating %s, you need to edit it appropriately." % \
os.path.join("info", file)
log.msg("Creating %s, you need to edit it appropriately." %
os.path.join("info", file))

try:
open(filepath, "wt").write(contents)
Expand All @@ -167,7 +168,7 @@ def createFile(path, file, contents):
path = os.path.join(basedir, "info")
if not os.path.exists(path):
if not quiet:
print "mkdir", path
log.msg("mkdir", path)
try:
os.mkdir(path)
except OSError as exception:
Expand All @@ -186,11 +187,11 @@ def createFile(path, file, contents):

if not os.path.exists(access_uri):
if not quiet:
print "Not creating %s - add it if you wish" % \
os.path.join("info", "access_uri")
log.msg("Not creating %s - add it if you wish" %
os.path.join("info", "access_uri"))

if created and not quiet:
print "Please edit the files in %s appropriately." % path
log.msg("Please edit the files in %s appropriately." % path)


def createSlave(config):
Expand All @@ -215,11 +216,11 @@ def createSlave(config):
_makeBuildbotTac(basedir, contents, quiet)
_makeInfoFiles(basedir, quiet)
except CreateSlaveError as exception:
print "%s\nfailed to configure buildslave in %s" % \
(exception, config['basedir'])
log.msg("%s\nfailed to configure buildslave in %s" %
(exception, config['basedir']))
return 1

if not quiet:
print "buildslave configured in %s" % basedir
log.msg("buildslave configured in %s" % basedir)

return 0
6 changes: 3 additions & 3 deletions slave/buildslave/scripts/logwatcher.py
Expand Up @@ -13,14 +13,14 @@
#
# Copyright Buildbot Team Members


import os
import platform

from twisted.internet import defer
from twisted.internet import error
from twisted.internet import protocol
from twisted.internet import reactor
from twisted.python import log
from twisted.protocols.basic import LineOnlyReceiver
from twisted.python.failure import Failure

Expand Down Expand Up @@ -51,7 +51,7 @@ def outReceived(self, data):
self.lw.dataReceived(data)

def errReceived(self, data):
print "ERR: '%s'" % (data,)
log.msg("ERR: '%s'" % (data,))


class LogWatcher(LineOnlyReceiver):
Expand Down Expand Up @@ -126,7 +126,7 @@ def lineReceived(self, line):
self.processtype = "buildslave"

if self.in_reconfig:
print line
log.msg(line)

if "message from master: attached" in line:
return self.finished("buildslave")
Expand Down
6 changes: 4 additions & 2 deletions slave/buildslave/scripts/restart.py
Expand Up @@ -13,6 +13,8 @@
#
# Copyright Buildbot Team Members

from twisted.python import log

from buildslave.scripts import base
from buildslave.scripts import start
from buildslave.scripts import stop
Expand All @@ -29,8 +31,8 @@ def restart(config):
stop.stopSlave(basedir, quiet)
except stop.SlaveNotRunning:
if not quiet:
print "no old buildslave process found to stop"
log.msg("no old buildslave process found to stop")
if not quiet:
print "now restarting buildslave process.."
log.msg("now restarting buildslave process..")

return start.startSlave(basedir, quiet, config['nodaemon'])
12 changes: 7 additions & 5 deletions slave/buildslave/scripts/runner.py
Expand Up @@ -15,12 +15,15 @@

# N.B.: don't import anything that might pull in a reactor yet. Some of our
# subcommands want to load modules that need the gtk reactor.

import os
import re
import sys

from twisted.python import reflect
from twisted.python import usage
from twisted.python import log


# the create/start/stop commands should all be run as the same user,
# preferably a separate 'buildbot' account.
Expand Down Expand Up @@ -234,11 +237,10 @@ class Options(usage.Options):

def opt_version(self):
import buildslave
print "Buildslave version: %s" % buildslave.version
log.msg("Buildslave version: %s" % buildslave.version)
usage.Options.opt_version(self)

def opt_verbose(self):
from twisted.python import log
log.startLogging(sys.stderr)

def postOptions(self):
Expand All @@ -251,10 +253,10 @@ def run():
try:
config.parseOptions()
except usage.error as e:
print "%s: %s" % (sys.argv[0], e)
print
log.msg("%s: %s" % (sys.argv[0], e))
log.msg()
c = getattr(config, 'subOptions', config)
print str(c)
log.msg(str(c))
sys.exit(1)

subconfig = config.subOptions
Expand Down
28 changes: 14 additions & 14 deletions slave/buildslave/scripts/start.py
Expand Up @@ -13,10 +13,10 @@
#
# Copyright Buildbot Team Members


import os
import sys
import time
from twisted.python import log

from buildslave.scripts import base

Expand All @@ -27,7 +27,7 @@ def follow(self):
from twisted.internet import reactor
from buildslave.scripts.logwatcher import LogWatcher
self.rc = 0
print "Following twistd.log until startup finished.."
log.msg("Following twistd.log until startup finished..")
lw = LogWatcher("twistd.log")
d = lw.start()
d.addCallbacks(self._success, self._failure)
Expand All @@ -36,7 +36,7 @@ def follow(self):

def _success(self, processtype):
from twisted.internet import reactor
print "The %s appears to have (re)started correctly." % processtype
log.msg("The %s appears to have (re)started correctly." % processtype)
self.rc = 0
reactor.stop()

Expand All @@ -45,13 +45,13 @@ def _failure(self, why):
from buildslave.scripts.logwatcher import BuildmasterTimeoutError, \
ReconfigError, BuildslaveTimeoutError, BuildSlaveDetectedError
if why.check(BuildmasterTimeoutError):
print """
log.msg("""
The buildslave took more than 10 seconds to start, so we were unable to
confirm that it started correctly. Please 'tail twistd.log' and look for a
line that says 'configuration update complete' to verify correct startup.
"""
""")
elif why.check(BuildslaveTimeoutError):
print """
log.msg("""
The buildslave took more than 10 seconds to start and/or connect to the
buildslave, so we were unable to confirm that it started and connected
correctly. Please 'tail twistd.log' and look for a line that says 'message
Expand All @@ -62,23 +62,23 @@ def _failure(self, why):
'Failure: twisted.cred.error.UnauthorizedLogin'
then your buildslave might be using the wrong botname or password. Please
correct these problems and then restart the buildslave.
"""
""")
elif why.check(ReconfigError):
print """
log.msg("""
The buildslave appears to have encountered an error in the master.cfg config
file during startup. It is probably running with an empty configuration right
now. Please inspect and fix master.cfg, then restart the buildslave.
"""
""")
elif why.check(BuildSlaveDetectedError):
print """
log.msg("""
Buildslave is starting up, not following logfile.
"""
""")
else:
print """
log.msg("""
Unable to confirm that the buildslave started correctly. You may need to
stop it, fix the config file, and restart.
"""
print why
""")
log.msg(why)
self.rc = 1
reactor.stop()

Expand Down
8 changes: 5 additions & 3 deletions slave/buildslave/scripts/stop.py
Expand Up @@ -16,6 +16,8 @@
import os
import time

from twisted.python import log

from buildslave.scripts import base


Expand Down Expand Up @@ -63,12 +65,12 @@ def stopSlave(basedir, quiet, signame="TERM"):
os.kill(pid, 0)
except OSError:
if not quiet:
print "buildslave process %d is dead" % pid
log.msg("buildslave process %d is dead" % pid)
return
timer += 1
time.sleep(1)
if not quiet:
print "never saw process go away"
log.msg("never saw process go away")


def stop(config, signame="TERM"):
Expand All @@ -82,6 +84,6 @@ def stop(config, signame="TERM"):
stopSlave(basedir, quiet, signame)
except SlaveNotRunning:
if not quiet:
print "buildslave not running"
log.msg("buildslave not running")

return 0
6 changes: 4 additions & 2 deletions slave/buildslave/scripts/upgrade_slave.py
Expand Up @@ -15,6 +15,8 @@

import os

from twisted.python import log

from buildslave.scripts import base


Expand All @@ -30,8 +32,8 @@ def upgradeSlave(config):
"from buildslave.bot import BuildSlave")
if new_buildbot_tac != buildbot_tac:
open(os.path.join(basedir, "buildbot.tac"), "w").write(new_buildbot_tac)
print "buildbot.tac updated"
log.msg("buildbot.tac updated")
else:
print "No changes made"
log.msg("No changes made")

return 0
4 changes: 2 additions & 2 deletions slave/buildslave/test/fake/slavebuilder.py
Expand Up @@ -12,7 +12,7 @@
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Copyright Buildbot Team Members

from __future__ import print_function
import pprint


Expand All @@ -33,7 +33,7 @@ def __init__(self, usePTY=False, basedir="/slavebuilder/basedir"):

def sendUpdate(self, data):
if self.debug:
print "FakeSlaveBuilder.sendUpdate", data
print("FakeSlaveBuilder.sendUpdate", data)
self.updates.append(data)

def show(self):
Expand Down
2 changes: 1 addition & 1 deletion slave/buildslave/test/unit/runprocess-scripts.py
Expand Up @@ -57,7 +57,7 @@ def wait_for_parent_death(orig_parent_pid):


def script(fn):
script_fns[fn.func_name] = fn
script_fns[fn.__name__] = fn
return fn

# scripts
Expand Down
3 changes: 2 additions & 1 deletion slave/buildslave/test/unit/test_commands_utils.py
Expand Up @@ -12,6 +12,7 @@
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Copyright Buildbot Team Members
from __future__ import print_function

import os
import shutil
Expand Down Expand Up @@ -108,7 +109,7 @@ def tearDown(self):
if os.path.exists(self.target):
shutil.rmtree(self.target)
except Exception:
print "\n(target directory was not removed by test, and cleanup failed too)\n"
print("\n(target directory was not removed by test, and cleanup failed too)\n")
raise

def test_rmdirRecursive_easy(self):
Expand Down

0 comments on commit 4d733e6

Please sign in to comment.