vendor/zasync/1.1

changeset 34:e080458b93a1 1.1-nux 1.0.0-1.1-nux

run/kill methods from zasyncctl.py got new keyword parameter 'output' which controls whether zasync will print possible messages to stdout/stderr on startup/shutdown. By default 'output' is False.
author rspivak
date Wed, 31 Jan 2007 20:42:44 +0000
parents 834d90397cb7
children 4f2bae7490b2
files CHANGES bin/zasyncctl.py
diffstat 2 files changed, 35 insertions(+), 7 deletions(-) [+]
line diff
     1.1 --- a/CHANGES
     1.2 +++ b/CHANGES
     1.3 @@ -3,7 +3,9 @@
     1.4  -
     1.5  New features:
     1.6  ~~~~~~~~~~~~~
     1.7 --
     1.8 +- run/kill methods from zasyncctl.py got new keyword parameter 'output'
     1.9 +  which controls whether zasync will print possible messages to
    1.10 +  stdout/stderr on startup/shutdown. By default 'output' is False.
    1.11  Bug fixes:
    1.12  ~~~~~~~~~~
    1.13  -
     2.1 --- a/bin/zasyncctl.py
     2.2 +++ b/bin/zasyncctl.py
     2.3 @@ -1,4 +1,10 @@
     2.4  import os
     2.5 +import sys
     2.6 +
     2.7 +class DummyRedirect(object):
     2.8 +
     2.9 +    def write(self, s):
    2.10 +        pass
    2.11  
    2.12  def makePidFile(cfg):
    2.13      # write the pid into the pidfile if possible
    2.14 @@ -11,20 +17,40 @@
    2.15      except IOError:
    2.16           pass
    2.17  
    2.18 -def kill(config_file=None, version=2.8):
    2.19 +def initialize(config_file, version, output):
    2.20      from zasync import config
    2.21 +
    2.22 +    if output:
    2.23 +        return config.initialize(config_file, version)
    2.24 +
    2.25 +    # redirect to avoid messages in console on startup
    2.26 +    old_stdout, old_stderr = sys.stdout, sys.stderr
    2.27 +    sys.stdout = sys.stderr = DummyRedirect()
    2.28 +
    2.29 +    conf = config.initialize(config_file, version)
    2.30 +    # restore old objects
    2.31 +    sys.stdout, sys.stderr = old_stdout, old_stderr
    2.32 +    return conf
    2.33 +
    2.34 +
    2.35 +def kill(config_file=None, version=2.8, output=False):
    2.36 +    """@output - defines whether we should print possible messages
    2.37 +    to stderr/stdout on shutdown.
    2.38 +    """
    2.39      import signal
    2.40 -    cfg = config.initialize(config_file, version)
    2.41 -    pid_filename = cfg.pid_filename
    2.42 +    conf = initialize(config_file, version, output)
    2.43 +    pid_filename = conf.pid_filename
    2.44      f = open(pid_filename, 'r')
    2.45      pid = int(f.read())
    2.46      f.close()
    2.47      os.kill(pid, signal.SIGKILL)
    2.48  
    2.49  # Taken from zasync/client/zasync/__init__.py
    2.50 -def run(config_file=None, version=2.8):
    2.51 -    from zasync import config
    2.52 +def run(config_file=None, version=2.8, output=False):
    2.53 +    """@output - defines whether we should print possible messages
    2.54 +    to stderr/stdout on startup.
    2.55 +    """
    2.56      from zasync import client
    2.57 -    conf = config.initialize(config_file, version)
    2.58 +    conf = initialize(config_file, version, output)
    2.59      makePidFile(conf)
    2.60      client.run(conf.target_path)