[Zodb-checkins] SVN: zdaemon/branches/py3/ Initial stab at porting. I need help. :-)
Stephen Richter
cvs-admin at zope.org
Wed Feb 13 14:14:01 UTC 2013
Log message for revision 129326:
Initial stab at porting. I need help. :-)
Changed:
_U zdaemon/branches/py3/
U zdaemon/branches/py3/CHANGES.txt
A zdaemon/branches/py3/MANIFEST.in
U zdaemon/branches/py3/bootstrap.py
U zdaemon/branches/py3/buildout.cfg
U zdaemon/branches/py3/setup.py
U zdaemon/branches/py3/src/zdaemon/README.txt
U zdaemon/branches/py3/src/zdaemon/tests/parent.py
U zdaemon/branches/py3/src/zdaemon/tests/tests.py
U zdaemon/branches/py3/src/zdaemon/tests/testuser.py
U zdaemon/branches/py3/src/zdaemon/tests/testzdoptions.py
U zdaemon/branches/py3/src/zdaemon/tests/testzdrun.py
U zdaemon/branches/py3/src/zdaemon/zdctl.py
U zdaemon/branches/py3/src/zdaemon/zdoptions.py
U zdaemon/branches/py3/src/zdaemon/zdrun.py
A zdaemon/branches/py3/tox.ini
-=-
Property changes on: zdaemon/branches/py3
___________________________________________________________________
Modified: svn:ignore
- .installed.cfg
build
develop-eggs
dist
eggs
bin
parts
+ .coverage
.installed.cfg
.tox
build
coverage
develop-eggs
dist
eggs
bin
parts
*.xml
Modified: zdaemon/branches/py3/CHANGES.txt
===================================================================
--- zdaemon/branches/py3/CHANGES.txt 2013-02-13 14:10:31 UTC (rev 129325)
+++ zdaemon/branches/py3/CHANGES.txt 2013-02-13 14:14:00 UTC (rev 129326)
@@ -2,6 +2,13 @@
Change log
==========
+4.0.0 (unreleased)
+==================
+
+- Added tox support and MANIFEST.in for proper releasing.
+
+- Drop Python 2.4 and 2.5 support.
+
3.0.5 (2012-11-27)
==================
Added: zdaemon/branches/py3/MANIFEST.in
===================================================================
--- zdaemon/branches/py3/MANIFEST.in (rev 0)
+++ zdaemon/branches/py3/MANIFEST.in 2013-02-13 14:14:00 UTC (rev 129326)
@@ -0,0 +1,9 @@
+include *.rst
+include *.txt
+include tox.ini
+include bootstrap.py
+include buildout.cfg
+
+recursive-include src *
+
+global-exclude *.pyc
Modified: zdaemon/branches/py3/bootstrap.py
===================================================================
--- zdaemon/branches/py3/bootstrap.py 2013-02-13 14:10:31 UTC (rev 129325)
+++ zdaemon/branches/py3/bootstrap.py 2013-02-13 14:14:00 UTC (rev 129326)
@@ -16,51 +16,150 @@
Simply run this script in a directory containing a buildout.cfg.
The script accepts buildout command-line options, so you can
use the -c option to specify an alternate configuration file.
-
-$Id: bootstrap.py 68905 2006-06-29 10:46:56Z jim $
"""
-import os, shutil, sys, tempfile, urllib2
+import os, shutil, sys, tempfile
+from optparse import OptionParser
tmpeggs = tempfile.mkdtemp()
-ez = {}
-exec urllib2.urlopen('http://peak.telecommunity.com/dist/ez_setup.py'
- ).read() in ez
-ez['use_setuptools'](to_dir=tmpeggs, download_delay=0)
+usage = '''\
+[DESIRED PYTHON FOR BUILDOUT] bootstrap.py [options]
-import pkg_resources
+Bootstraps a buildout-based project.
-is_jython = sys.platform.startswith('java')
+Simply run this script in a directory containing a buildout.cfg, using the
+Python that you want bin/buildout to use.
-if is_jython:
- import subprocess
+Note that by using --setup-source and --download-base to point to
+local resources, you can keep this script from going over the network.
+'''
-ws = pkg_resources.working_set
+parser = OptionParser(usage=usage)
+parser.add_option("-v", "--version", help="use a specific zc.buildout version")
-if is_jython:
- assert subprocess.Popen(
- [sys.executable] + ['-c',
- 'from setuptools.command.easy_install import main; main()',
- '-mqNxd', tmpeggs, 'zc.buildout'],
- env = dict(
- PYTHONPATH =
- ws.find(pkg_resources.Requirement.parse('setuptools')).location
- ),
- ).wait() == 0
+parser.add_option("-t", "--accept-buildout-test-releases",
+ dest='accept_buildout_test_releases',
+ action="store_true", default=False,
+ help=("Normally, if you do not specify a --version, the "
+ "bootstrap script and buildout gets the newest "
+ "*final* versions of zc.buildout and its recipes and "
+ "extensions for you. If you use this flag, "
+ "bootstrap and buildout will get the newest releases "
+ "even if they are alphas or betas."))
+parser.add_option("-c", "--config-file",
+ help=("Specify the path to the buildout configuration "
+ "file to be used."))
+parser.add_option("-f", "--find-links",
+ help=("Specify a URL to search for buildout releases"))
-else:
- assert os.spawnle(
- os.P_WAIT, sys.executable, sys.executable,
- '-c', 'from setuptools.command.easy_install import main; main()',
- '-mqNxd', tmpeggs, 'zc.buildout',
- {'PYTHONPATH':
- ws.find(pkg_resources.Requirement.parse('setuptools')).location
- },
- ) == 0
+options, args = parser.parse_args()
+
+######################################################################
+# load/install distribute
+
+to_reload = False
+try:
+ import pkg_resources, setuptools
+ if not hasattr(pkg_resources, '_distribute'):
+ to_reload = True
+ raise ImportError
+except ImportError:
+ ez = {}
+
+ try:
+ from urllib.request import urlopen
+ except ImportError:
+ from urllib2 import urlopen
+
+ exec(urlopen('http://python-distribute.org/distribute_setup.py').read(), ez)
+ setup_args = dict(to_dir=tmpeggs, download_delay=0, no_fake=True)
+ ez['use_setuptools'](**setup_args)
+
+ if to_reload:
+ reload(pkg_resources)
+ import pkg_resources
+ # This does not (always?) update the default working set. We will
+ # do it.
+ for path in sys.path:
+ if path not in pkg_resources.working_set.entries:
+ pkg_resources.working_set.add_entry(path)
+
+######################################################################
+# Install buildout
+
+ws = pkg_resources.working_set
+
+cmd = [sys.executable, '-c',
+ 'from setuptools.command.easy_install import main; main()',
+ '-mZqNxd', tmpeggs]
+
+find_links = os.environ.get(
+ 'bootstrap-testing-find-links',
+ options.find_links or
+ ('http://downloads.buildout.org/'
+ if options.accept_buildout_test_releases else None)
+ )
+if find_links:
+ cmd.extend(['-f', find_links])
+
+distribute_path = ws.find(
+ pkg_resources.Requirement.parse('distribute')).location
+
+requirement = 'zc.buildout'
+version = options.version
+if version is None and not options.accept_buildout_test_releases:
+ # Figure out the most recent final version of zc.buildout.
+ import setuptools.package_index
+ _final_parts = '*final-', '*final'
+ def _final_version(parsed_version):
+ for part in parsed_version:
+ if (part[:1] == '*') and (part not in _final_parts):
+ return False
+ return True
+ index = setuptools.package_index.PackageIndex(
+ search_path=[distribute_path])
+ if find_links:
+ index.add_find_links((find_links,))
+ req = pkg_resources.Requirement.parse(requirement)
+ if index.obtain(req) is not None:
+ best = []
+ bestv = None
+ for dist in index[req.project_name]:
+ distv = dist.parsed_version
+ if _final_version(distv):
+ if bestv is None or distv > bestv:
+ best = [dist]
+ bestv = distv
+ elif distv == bestv:
+ best.append(dist)
+ if best:
+ best.sort()
+ version = best[-1].version
+if version:
+ requirement = '=='.join((requirement, version))
+cmd.append(requirement)
+
+import subprocess
+if subprocess.call(cmd, env=dict(os.environ, PYTHONPATH=distribute_path)) != 0:
+ raise Exception(
+ "Failed to execute command:\n%s",
+ repr(cmd)[1:-1])
+
+######################################################################
+# Import and run buildout
+
ws.add_entry(tmpeggs)
-ws.require('zc.buildout')
+ws.require(requirement)
import zc.buildout.buildout
-zc.buildout.buildout.main(sys.argv[1:] + ['bootstrap'])
+
+if not [a for a in args if '=' not in a]:
+ args.append('bootstrap')
+
+# if -c was provided, we push it back into args for buildout' main function
+if options.config_file is not None:
+ args[0:0] = ['-c', options.config_file]
+
+zc.buildout.buildout.main(args)
shutil.rmtree(tmpeggs)
Modified: zdaemon/branches/py3/buildout.cfg
===================================================================
--- zdaemon/branches/py3/buildout.cfg 2013-02-13 14:10:31 UTC (rev 129325)
+++ zdaemon/branches/py3/buildout.cfg 2013-02-13 14:14:00 UTC (rev 129326)
@@ -1,7 +1,8 @@
[buildout]
develop = .
-parts = test scripts coverage-test coverage-report
-find-links = http://download.zope.org/distribution/
+ ../ZConfig
+parts = test scripts coverage-test
+ coverage-report
[test]
recipe = zc.recipe.testrunner
@@ -10,13 +11,14 @@
[coverage-test]
recipe = zc.recipe.testrunner
eggs = ${test:eggs}
-defaults = ['--coverage', '../../coverage']
+defaults = ['--coverage', '${buildout:directory}/coverage']
[coverage-report]
recipe = zc.recipe.egg
eggs = z3c.coverage
-scripts = coverage=coverage-report
-arguments = ('coverage', 'coverage/report')
+scripts = coveragereport=coverage-report
+arguments = ('${buildout:directory}/coverage',
+ '${buildout:directory}/coverage/report')
[scripts]
recipe = zc.recipe.egg
Modified: zdaemon/branches/py3/setup.py
===================================================================
--- zdaemon/branches/py3/setup.py 2013-02-13 14:10:31 UTC (rev 129325)
+++ zdaemon/branches/py3/setup.py 2013-02-13 14:14:00 UTC (rev 129326)
@@ -11,10 +11,13 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
+import os
+import sys
-version = '0.0.0'
+tests_require=['zope.testing', 'zope.testrunner', 'manuel', 'mock']
+if sys.version_info[0] == 2:
+ tests_require.append('zc.customdoctests')
-import os
entry_points = """
[console_scripts]
@@ -24,6 +27,21 @@
def read(*rnames):
return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
+def alltests():
+ import os
+ import sys
+ import unittest
+ # use the zope.testrunner machinery to find all the
+ # test suites we've put under ourselves
+ import zope.testrunner.find
+ import zope.testrunner.options
+ here = os.path.abspath(os.path.dirname(sys.argv[0]))
+ args = sys.argv[:]
+ defaults = ["--test-path", here]
+ options = zope.testrunner.options.get_options(args, defaults)
+ suites = list(zope.testrunner.find.find_suites(options))
+ return unittest.TestSuite(suites)
+
try:
from setuptools import setup
setuptools_options = dict(
@@ -31,17 +49,17 @@
entry_points=entry_points,
include_package_data = True,
install_requires=["ZConfig"],
- extras_require=dict(
- test=['zope.testing', 'manuel', 'zc.customdoctests', 'mock']),
+ extras_require=dict(test=tests_require),
+ test_suite='__main__.alltests',
+ tests_require=tests_require
)
except ImportError:
from distutils.core import setup
setuptools_options = {}
-name = "zdaemon"
setup(
- name=name,
- version = version,
+ name="zdaemon",
+ version = "4.0.0dev",
url="http://www.python.org/pypi/zdaemon",
license="ZPL 2.1",
description=
@@ -65,8 +83,15 @@
'Intended Audience :: Developers',
'Intended Audience :: System Administrators',
'License :: OSI Approved :: Zope Public License',
+ 'Programming Language :: Python',
+ 'Programming Language :: Python :: 2',
+ 'Programming Language :: Python :: 2.6',
+ 'Programming Language :: Python :: 2.7',
+ #'Programming Language :: Python :: 3',
+ #'Programming Language :: Python :: 3.3',
+ 'Programming Language :: Python :: Implementation :: CPython',
+ 'Operating System :: POSIX',
'Topic :: Utilities',
- 'Operating System :: POSIX',
],
**setuptools_options)
Modified: zdaemon/branches/py3/src/zdaemon/README.txt
===================================================================
--- zdaemon/branches/py3/src/zdaemon/README.txt 2013-02-13 14:10:31 UTC (rev 129325)
+++ zdaemon/branches/py3/src/zdaemon/README.txt 2013-02-13 14:14:00 UTC (rev 129326)
@@ -83,7 +83,8 @@
.. -> text
- >>> open('conf', 'w').write(text)
+ >>> with open('conf', 'w') as file:
+ ... file.write(text)
Now, we can run with the -C option to read the configuration file:
@@ -115,7 +116,8 @@
.. -> text
- >>> open('conf', 'w').write(text.replace('/tmp', tmpdir))
+ >>> with open('conf', 'w') as file:
+ ... file.write(text.replace('/tmp', tmpdir))
Now, when we run zdaemon:
@@ -149,7 +151,8 @@
.. -> text
- >>> open('conf', 'w').write(text.replace('/tmp', tmpdir))
+ >>> with open('conf', 'w') as file:
+ ... file.write(text.replace('/tmp', tmpdir))
Then we can pass the program argument on the command line:
@@ -184,7 +187,8 @@
.. -> text
- >>> open('conf', 'w').write(text.replace('/tmp', tmpdir))
+ >>> with open('conf', 'w') as file:
+ ... file.write(text.replace('/tmp', tmpdir))
Now, when we run the command, we'll see out environment settings reflected:
@@ -280,12 +284,18 @@
the output will show up in the new file, not the old:
- >>> open('log').read()
+ >>> with open('log') as file:
+ ... file.read()
'rec 3\n'
- >>> open('log.1').read()
+ >>> with open('log.1') as file:
+ ... file.read()
'rec 1\nrec 2\n'
+Close files:
+
+ >>> f.close()
+
Start test program and timeout
==============================
Modified: zdaemon/branches/py3/src/zdaemon/tests/parent.py
===================================================================
--- zdaemon/branches/py3/src/zdaemon/tests/parent.py 2013-02-13 14:10:31 UTC (rev 129325)
+++ zdaemon/branches/py3/src/zdaemon/tests/parent.py 2013-02-13 14:14:00 UTC (rev 129326)
@@ -18,15 +18,13 @@
zctldir = os.path.dirname(dir)
zdrun = os.path.join(zctldir, 'zdrun.py')
donothing = os.path.join(tmp, 'donothing.sh')
- fd = os.open(donothing, os.O_WRONLY|os.O_CREAT, 0700)
+ fd = os.open(donothing, os.O_WRONLY|os.O_CREAT, 0o700)
os.write(fd, donothing_contents)
os.close(fd)
args = [sys.executable, zdrun]
args += ['-d', '-b', '10', '-s', os.path.join(tmp, 'testsock'),
'-x', '0,2', '-z', dir, donothing]
flag = os.P_NOWAIT
- #cmd = ' '.join([sys.executable] + args)
- #print cmd
os.spawnvpe(flag, args[0], args,
dict(os.environ, PYTHONPATH=':'.join(sys.path)),
)
Modified: zdaemon/branches/py3/src/zdaemon/tests/tests.py
===================================================================
--- zdaemon/branches/py3/src/zdaemon/tests/tests.py 2013-02-13 14:10:31 UTC (rev 129325)
+++ zdaemon/branches/py3/src/zdaemon/tests/tests.py 2013-02-13 14:14:00 UTC (rev 129326)
@@ -11,7 +11,7 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
-
+from __future__ import print_function
import doctest
import manuel.capture
import manuel.doctest
@@ -327,7 +327,7 @@
zdaemon = zdaemon_loc,
ZConfig = zconfig_loc,
))
- os.chmod('zdaemon', 0755)
+ os.chmod('zdaemon', 0o755)
test.globs.update(dict(
system = system
))
@@ -338,7 +338,7 @@
def system(command, input='', quiet=False, echo=False):
if echo:
- print command
+ print(command)
p = subprocess.Popen(
command, shell=True,
stdin=subprocess.PIPE,
@@ -349,10 +349,10 @@
p.stdin.close()
data = p.stdout.read()
if not quiet:
- print data,
+ print(data, end='')
r = p.wait()
if r:
- print 'Failed:', r
+ print('Failed:', r)
def checkenv(match):
match = [a for a in match.group(1).split('\n')[:-1]
@@ -387,20 +387,18 @@
checker=renormalizing.RENormalizing([
(re.compile('pid=\d+'), 'pid=NNN'),
(re.compile('(\. )+\.?'), '<BLANKLINE>'),
- ])
- ),
+ ])),
manuel.testing.TestSuite(
- manuel.doctest.Manuel(
- parser=zc.customdoctests.DocTestParser(
- ps1='sh>',
- transform=lambda s: 'system("%s")\n' % s.rstrip()
- ),
- checker=README_checker,
- ) +
- manuel.doctest.Manuel(checker=README_checker) +
- manuel.capture.Manuel(),
- '../README.txt',
- setUp=setUp, tearDown=tearDown,
- ),
+ manuel.doctest.Manuel(
+ parser=zc.customdoctests.DocTestParser(
+ ps1='sh>',
+ transform=lambda s: 'system("%s")\n' % s.rstrip()
+ ),
+ checker=README_checker,
+ ) +
+ manuel.doctest.Manuel(checker=README_checker) +
+ manuel.capture.Manuel(),
+ '../README.txt',
+ setUp=setUp, tearDown=tearDown),
))
Modified: zdaemon/branches/py3/src/zdaemon/tests/testuser.py
===================================================================
--- zdaemon/branches/py3/src/zdaemon/tests/testuser.py 2013-02-13 14:10:31 UTC (rev 129325)
+++ zdaemon/branches/py3/src/zdaemon/tests/testuser.py 2013-02-13 14:14:00 UTC (rev 129326)
@@ -50,7 +50,7 @@
... except SystemExit:
... pass
... else:
- ... print 'oops'
+ ... print('oops')
... # doctest: +ELLIPSIS
Error: only root can use -u USER to change users
For help, use ... -h
Modified: zdaemon/branches/py3/src/zdaemon/tests/testzdoptions.py
===================================================================
--- zdaemon/branches/py3/src/zdaemon/tests/testzdoptions.py 2013-02-13 14:10:31 UTC (rev 129325)
+++ zdaemon/branches/py3/src/zdaemon/tests/testzdoptions.py 2013-02-13 14:14:00 UTC (rev 129326)
@@ -19,7 +19,6 @@
import tempfile
import shutil
import unittest
-from StringIO import StringIO
import ZConfig
import zdaemon
@@ -27,6 +26,12 @@
ZDOptions, RunnerOptions,
existing_parent_directory, existing_parent_dirpath)
+try:
+ from StringIO import StringIO
+except:
+ # Python 3 support.
+ from io import StringIO
+
class ZDOptionsTestBase(unittest.TestCase):
OptionsClass = ZDOptions
@@ -47,7 +52,7 @@
sys.stderr = StringIO()
try:
options.realize(args)
- except SystemExit, err:
+ except SystemExit as err:
self.assertEqual(err.code, 2)
else:
self.fail("SystemExit expected")
@@ -96,7 +101,7 @@
options.realize([arg],**kw)
finally:
self.restore_streams()
- except SystemExit, err:
+ except SystemExit as err:
self.assertEqual(err.code, 0)
else:
self.fail("%s didn't call sys.exit()" % repr(arg))
@@ -307,7 +312,7 @@
options.realize([])
finally:
self.restore_streams()
- except SystemExit, e:
+ except SystemExit as e:
self.assertEqual(e.code, 2)
else:
self.fail("expected SystemExit")
Modified: zdaemon/branches/py3/src/zdaemon/tests/testzdrun.py
===================================================================
--- zdaemon/branches/py3/src/zdaemon/tests/testzdrun.py 2013-02-13 14:10:31 UTC (rev 129325)
+++ zdaemon/branches/py3/src/zdaemon/tests/testzdrun.py 2013-02-13 14:14:00 UTC (rev 129326)
@@ -1,4 +1,5 @@
"""Test suite for zdrun.py."""
+from __future__ import print_function
import os
import sys
@@ -9,7 +10,11 @@
import unittest
import socket
-from StringIO import StringIO
+try:
+ from StringIO import StringIO
+except:
+ # Python 3 support.
+ from io import StringIO
import ZConfig
@@ -105,7 +110,7 @@
def testCmdclassOverride(self):
class MyCmd(zdctl.ZDCmd):
def do_sproing(self, rest):
- print rest
+ print(rest)
self._run("-p echo sproing expected", cmdclass=MyCmd)
self.expect = "expected\n"
@@ -146,7 +151,7 @@
options = zdrun.ZDRunOptions()
try:
options.realize(["-h"], doc=zdrun.__doc__)
- except SystemExit, err:
+ except SystemExit as err:
self.failIf(err.code)
else:
self.fail("SystemExit expected")
@@ -305,7 +310,7 @@
sys.stdout = self.save_stdout
sys.stderr = self.save_stderr
if err:
- print >>sys.stderr, err,
+ print(err, end='', file=sys.stderr)
self.assertEqual(self.expect, got)
super(TestRunnerDirectory, self).tearDown()
@@ -425,7 +430,7 @@
response += data
sock.close()
return response
- except socket.error, msg:
+ except socket.error as msg:
if str(msg) == 'AF_UNIX path too long':
# MacOS has apparent small limits on the length of a UNIX
# domain socket filename, we want to make MacOS users aware
Modified: zdaemon/branches/py3/src/zdaemon/zdctl.py
===================================================================
--- zdaemon/branches/py3/src/zdaemon/zdctl.py 2013-02-13 14:10:31 UTC (rev 129325)
+++ zdaemon/branches/py3/src/zdaemon/zdctl.py 2013-02-13 14:14:00 UTC (rev 129326)
@@ -37,6 +37,7 @@
Actions are commands like "start", "stop" and "status". Use the
action "help" to find out about available actions.
"""
+from __future__ import print_function
import os
import os.path
@@ -127,9 +128,9 @@
args = eval(s, {"__builtins__": {}})
program = self.options.program
if args[:len(program)] != program:
- print "WARNING! zdrun is managing a different program!"
- print "our program =", program
- print "daemon's args =", args
+ print("WARNING! zdrun is managing a different program!")
+ print("our program =", program)
+ print("daemon's args =", args)
if options.configroot is not None:
env = getattr(options.configroot, 'environment', None)
@@ -226,7 +227,7 @@
response += data
sock.close()
return response
- except socket.error, msg:
+ except socket.error as msg:
return None
zd_testing = 0
@@ -266,21 +267,21 @@
if self.get_status():
was_running = True
elif (was_running or n > 10) and not cond(n):
- print "\ndaemon manager not running"
+ print("\ndaemon manager not running")
return 1
except KeyboardInterrupt:
- print "^C"
- print "\n" + msg % self.__dict__
+ print("^C")
+ print("\n" + msg % self.__dict__)
def help_help(self):
- print "help -- Print a list of available actions."
- print "help <action> -- Print help for <action>."
+ print("help -- Print a list of available actions.")
+ print("help <action> -- Print help for <action>.")
def _start_cond(self, n):
if (n > self.options.start_timeout):
- print '\nProgram took too long to start'
+ print('\nProgram took too long to start')
sys.exit(1)
return self.zd_pid and not self.zd_testing
@@ -315,7 +316,7 @@
elif not self.zd_pid:
self.send_action("start")
else:
- print "daemon process already running; pid=%d" % self.zd_pid
+ print("daemon process already running; pid=%d" % self.zd_pid)
return
if self.options.daemon:
return self.awhile(
@@ -349,30 +350,30 @@
return args
def help_start(self):
- print "start -- Start the daemon process."
- print " If it is already running, do nothing."
+ print("start -- Start the daemon process.")
+ print(" If it is already running, do nothing.")
def do_stop(self, arg):
self.get_status()
if not self.zd_up:
- print "daemon manager not running"
+ print("daemon manager not running")
elif not self.zd_pid:
- print "daemon process not running"
+ print("daemon process not running")
else:
self.send_action("stop")
self.awhile(lambda n: not self.zd_pid, "daemon process stopped")
def do_reopen_transcript(self, arg):
if not self.zd_up:
- print "daemon manager not running"
+ print("daemon manager not running")
elif not self.zd_pid:
- print "daemon process not running"
+ print("daemon process not running")
else:
self.send_action("reopen_transcript")
def help_stop(self):
- print "stop -- Stop the daemon process."
- print " If it is not running, do nothing."
+ print("stop -- Stop the daemon process.")
+ print(" If it is not running, do nothing.")
def do_restart(self, arg):
self.get_status()
@@ -385,7 +386,7 @@
"daemon process restarted, pid=%(zd_pid)d")
def help_restart(self):
- print "restart -- Stop and then start the daemon process."
+ print("restart -- Stop and then start the daemon process.")
def do_kill(self, arg):
if not arg:
@@ -394,149 +395,149 @@
try:
sig = int(arg)
except: # int() can raise any number of exceptions
- print "invalid signal number", `arg`
+ print("invalid signal number", repr(arg))
return
self.get_status()
if not self.zd_pid:
- print "daemon process not running"
+ print("daemon process not running")
return
- print "kill(%d, %d)" % (self.zd_pid, sig)
+ print("kill(%d, %d)" % (self.zd_pid, sig))
try:
os.kill(self.zd_pid, sig)
- except os.error, msg:
- print "Error:", msg
+ except os.error as msg:
+ print("Error:", msg)
else:
- print "signal %d sent to process %d" % (sig, self.zd_pid)
+ print("signal %d sent to process %d" % (sig, self.zd_pid))
def help_kill(self):
- print "kill [sig] -- Send signal sig to the daemon process."
- print " The default signal is SIGTERM."
+ print("kill [sig] -- Send signal sig to the daemon process.")
+ print(" The default signal is SIGTERM.")
def do_wait(self, arg):
self.awhile(lambda n: not self.zd_pid, "daemon process stopped")
self.do_status()
def help_wait(self):
- print "wait -- Wait for the daemon process to exit."
+ print("wait -- Wait for the daemon process to exit.")
def do_status(self, arg=""):
status = 0
if arg not in ["", "-l"]:
- print "status argument must be absent or -l"
+ print("status argument must be absent or -l")
return 1
self.get_status()
if not self.zd_up:
- print "daemon manager not running"
+ print("daemon manager not running")
status = 3
elif not self.zd_pid:
- print "daemon manager running; daemon process not running"
+ print("daemon manager running; daemon process not running")
else:
- print "program running; pid=%d" % self.zd_pid
+ print("program running; pid=%d" % self.zd_pid)
if arg == "-l" and self.zd_status:
- print self.zd_status
+ print(self.zd_status)
return status
def help_status(self):
- print "status [-l] -- Print status for the daemon process."
- print " With -l, show raw status output as well."
+ print("status [-l] -- Print status for the daemon process.")
+ print(" With -l, show raw status output as well.")
def do_show(self, arg):
if not arg:
arg = "options"
try:
method = getattr(self, "show_" + arg)
- except AttributeError, err:
- print err
+ except AttributeError as err:
+ print(err)
self.help_show()
return
method()
def show_options(self):
- print "zdctl/zdrun options:"
- print "schemafile: ", repr(self.options.schemafile)
- print "configfile: ", repr(self.options.configfile)
- print "zdrun: ", repr(self.options.zdrun)
- print "python: ", repr(self.options.python)
- print "program: ", repr(self.options.program)
- print "backofflimit:", repr(self.options.backofflimit)
- print "daemon: ", repr(self.options.daemon)
- print "forever: ", repr(self.options.forever)
- print "sockname: ", repr(self.options.sockname)
- print "exitcodes: ", repr(self.options.exitcodes)
- print "user: ", repr(self.options.user)
+ print("zdctl/zdrun options:")
+ print("schemafile: ", repr(self.options.schemafile))
+ print("configfile: ", repr(self.options.configfile))
+ print("zdrun: ", repr(self.options.zdrun))
+ print("python: ", repr(self.options.python))
+ print("program: ", repr(self.options.program))
+ print("backofflimit:", repr(self.options.backofflimit))
+ print("daemon: ", repr(self.options.daemon))
+ print("forever: ", repr(self.options.forever))
+ print("sockname: ", repr(self.options.sockname))
+ print("exitcodes: ", repr(self.options.exitcodes))
+ print("user: ", repr(self.options.user))
umask = self.options.umask
if not umask:
# Here we're just getting the current umask so we can report it:
- umask = os.umask(0777)
+ umask = os.umask(0o777)
os.umask(umask)
- print "umask: ", oct(umask)
- print "directory: ", repr(self.options.directory)
- print "logfile: ", repr(self.options.logfile)
+ print("umask: ", oct(umask))
+ print("directory: ", repr(self.options.directory))
+ print("logfile: ", repr(self.options.logfile))
def show_python(self):
- print "Python info:"
+ print("Python info:")
version = sys.version.replace("\n", "\n ")
- print "Version: ", version
- print "Platform: ", sys.platform
- print "Executable: ", repr(sys.executable)
- print "Arguments: ", repr(sys.argv)
- print "Directory: ", repr(os.getcwd())
- print "Path:"
+ print("Version: ", version)
+ print("Platform: ", sys.platform)
+ print("Executable: ", repr(sys.executable))
+ print("Arguments: ", repr(sys.argv))
+ print("Directory: ", repr(os.getcwd()))
+ print("Path:")
for dir in sys.path:
- print " " + repr(dir)
+ print(" " + repr(dir))
def show_all(self):
self.show_options()
- print
+ print()
self.show_python()
def help_show(self):
- print "show options -- show zdctl options"
- print "show python -- show Python version and details"
- print "show all -- show all of the above"
+ print("show options -- show zdctl options")
+ print("show python -- show Python version and details")
+ print("show all -- show all of the above")
def do_logtail(self, arg):
if not arg:
arg = self.options.logfile
if not arg:
- print "No default log file specified; use logtail <logfile>"
+ print("No default log file specified; use logtail <logfile>")
return
try:
helper = TailHelper(arg)
helper.tailf()
except KeyboardInterrupt:
- print
- except IOError, msg:
- print msg
- except OSError, msg:
- print msg
+ print()
+ except IOError as msg:
+ print(msg)
+ except OSError as msg:
+ print(msg)
def help_logtail(self):
- print "logtail [logfile] -- Run tail -f on the given logfile."
- print " A default file may exist."
- print " Hit ^C to exit this mode."
+ print("logtail [logfile] -- Run tail -f on the given logfile.")
+ print(" A default file may exist.")
+ print(" Hit ^C to exit this mode.")
def do_foreground(self, arg):
self.get_status()
pid = self.zd_pid
if pid:
- print "To run the program in the foreground, please stop it first."
+ print("To run the program in the foreground, please stop it first.")
return
program = self.options.program + self.options.args[1:]
- print " ".join(program)
+ print(" ".join(program))
sys.stdout.flush()
try:
os.spawnlp(os.P_WAIT, program[0], *program)
except KeyboardInterrupt:
- print
+ print()
def do_fg(self, arg):
self.do_foreground(arg)
def help_foreground(self):
- print "foreground -- Run the program in the forground."
- print "fg -- an alias for foreground."
+ print("foreground -- Run the program in the forground.")
+ print("fg -- an alias for foreground.")
def help_fg(self):
self.help_foreground()
@@ -559,7 +560,7 @@
bytes_added = newsz - sz
if bytes_added < 0:
sz = 0
- print "==> File truncated <=="
+ print("==> File truncated <==")
bytes_added = newsz
if bytes_added > 0:
self.f.seek(-bytes_added, 2)
Modified: zdaemon/branches/py3/src/zdaemon/zdoptions.py
===================================================================
--- zdaemon/branches/py3/src/zdaemon/zdoptions.py 2013-02-13 14:10:31 UTC (rev 129325)
+++ zdaemon/branches/py3/src/zdaemon/zdoptions.py 2013-02-13 14:14:00 UTC (rev 129326)
@@ -11,9 +11,8 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
-
"""Option processing for zdaemon and related code."""
-
+from __future__ import print_function
import os
import sys
import getopt
@@ -78,7 +77,7 @@
doc = "No help available."
elif doc.find("%s") > 0:
doc = doc.replace("%s", self.progname)
- print doc,
+ print(doc, end='')
sys.exit(0)
def usage(self, msg):
@@ -98,9 +97,9 @@
for n, cn in self.names_list[:]:
if n == name:
self.names_list.remove((n, cn))
- if self.default_map.has_key(name):
+ if name in self.default_map:
del self.default_map[name]
- if self.required_map.has_key(name):
+ if name in self.required_map:
del self.required_map[name]
if confname:
for n, cn in self.names_list[:]:
@@ -108,13 +107,13 @@
self.names_list.remove((n, cn))
if short:
key = "-" + short[0]
- if self.options_map.has_key(key):
+ if key in self.options_map:
del self.options_map[key]
if long:
key = "--" + long
if key[-1] == "=":
key = key[:-1]
- if self.options_map.has_key(key):
+ if key in self.options_map:
del self.options_map[key]
def add(self,
@@ -173,7 +172,7 @@
if rest not in ("", ":"):
raise ValueError("short option should be 'x' or 'x:'")
key = "-" + key
- if self.options_map.has_key(key):
+ if key in self.options_map:
raise ValueError("duplicate short option key '%s'" % key)
self.options_map[key] = (name, handler)
self.short_options.append(short)
@@ -185,7 +184,7 @@
if key[-1] == "=":
key = key[:-1]
key = "--" + key
- if self.options_map.has_key(key):
+ if key in self.options_map:
raise ValueError("duplicate long option key '%s'" % key)
self.options_map[key] = (name, handler)
self.long_options.append(long)
@@ -239,7 +238,7 @@
try:
self.options, self.args = getopt.getopt(
args, "".join(self.short_options), self.long_options)
- except getopt.error, msg:
+ except getopt.error as msg:
if raise_getopt_errs:
self.usage(msg)
@@ -253,7 +252,7 @@
if handler is not None:
try:
arg = handler(arg)
- except ValueError, msg:
+ except ValueError as msg:
self.usage("invalid value for %s %r: %s" % (opt, arg, msg))
if name and arg is not None:
if getattr(self, name) is not None:
@@ -269,12 +268,12 @@
name, handler = self.environ_map[envvar]
if name and getattr(self, name, None) is not None:
continue
- if os.environ.has_key(envvar):
+ if envvar in os.environ:
value = os.environ[envvar]
if handler is not None:
try:
value = handler(value)
- except ValueError, msg:
+ except ValueError as msg:
self.usage("invalid environment value for %s %r: %s"
% (envvar, value, msg))
if name and value is not None:
@@ -290,7 +289,7 @@
self.load_schema()
try:
self.load_configfile()
- except ZConfig.ConfigurationError, msg:
+ except ZConfig.ConfigurationError as msg:
self.usage(str(msg))
# Copy config options to attributes of self. This only fills
@@ -371,7 +370,7 @@
list_of_ints, default=[0, 2])
self.add("user", "runner.user", "u:", "user=")
self.add("umask", "runner.umask", "m:", "umask=", octal_type,
- default=022)
+ default=0o22)
self.add("directory", "runner.directory", "z:", "directory=",
existing_parent_directory)
@@ -382,7 +381,7 @@
if not arg:
return []
else:
- return map(int, arg.split(","))
+ return list(map(int, arg.split(",")))
def octal_type(arg):
return int(arg, 8)
@@ -416,12 +415,12 @@
# Stupid test program
z = ZDOptions()
z.add("program", "zdctl.program", "p:", "program=")
- print z.names_list
+ print(z.names_list)
z.realize()
names = z.names_list[:]
names.sort()
for name, confname in names:
- print "%-20s = %.56r" % (name, getattr(z, name))
+ print("%-20s = %.56r" % (name, getattr(z, name)))
if __name__ == "__main__":
__file__ = sys.argv[0]
Modified: zdaemon/branches/py3/src/zdaemon/zdrun.py
===================================================================
--- zdaemon/branches/py3/src/zdaemon/zdrun.py 2013-02-13 14:10:31 UTC (rev 129325)
+++ zdaemon/branches/py3/src/zdaemon/zdrun.py 2013-02-13 14:14:00 UTC (rev 129326)
@@ -135,7 +135,7 @@
except os.error:
continue
mode = st[ST_MODE]
- if mode & 0111:
+ if mode & 0o111:
break
else:
self.options.usage("can't find program %r on PATH %s" %
@@ -188,7 +188,7 @@
pass
try:
os.execv(self.filename, self.args)
- except os.error, err:
+ except os.error as err:
sys.stderr.write("can't exec %r: %s\n" %
(self.filename, err))
finally:
@@ -205,7 +205,7 @@
return "no subprocess running"
try:
os.kill(self.pid, sig)
- except os.error, msg:
+ except os.error as msg:
return str(msg)
return None
@@ -251,7 +251,7 @@
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
try:
sock.bind(tempname)
- os.chmod(tempname, 0700)
+ os.chmod(tempname, 0o700)
try:
os.link(tempname, sockname)
break
@@ -351,7 +351,7 @@
if self.options.directory:
try:
os.chdir(self.options.directory)
- except os.error, err:
+ except os.error as err:
self.logger.warn("can't chdir into %r: %s"
% (self.options.directory, err))
else:
@@ -396,8 +396,8 @@
self.delay = time.time() + self.options.backofflimit
try:
r, w, x = select.select(r, w, x, timeout)
- except select.error, err:
- if err[0] != errno.EINTR:
+ except select.error as err:
+ if err.args[0] != errno.EINTR:
raise
r = w = x = []
if self.waitstatus:
@@ -405,14 +405,14 @@
if self.commandsocket and self.commandsocket in r:
try:
self.dorecv()
- except socket.error, msg:
+ except socket.error as msg:
self.logger.exception("socket.error in dorecv(): %s"
% str(msg))
self.commandsocket = None
if self.mastersocket in r:
try:
self.doaccept()
- except socket.error, msg:
+ except socket.error as msg:
self.logger.exception("socket.error in doaccept(): %s"
% str(msg))
self.commandsocket = None
@@ -592,7 +592,7 @@
while msg:
sent = self.commandsocket.send(msg)
msg = msg[sent:]
- except socket.error, msg:
+ except socket.error as msg:
self.logger.warn("Error sending reply: %s" % str(msg))
@@ -685,7 +685,7 @@
def get_path():
"""Return a list corresponding to $PATH, or a default."""
path = ["/bin", "/usr/bin", "/usr/local/bin"]
- if os.environ.has_key("PATH"):
+ if "PATH" in os.environ:
p = os.environ["PATH"]
if p:
path = p.split(os.pathsep)
Added: zdaemon/branches/py3/tox.ini
===================================================================
--- zdaemon/branches/py3/tox.ini (rev 0)
+++ zdaemon/branches/py3/tox.ini 2013-02-13 14:14:00 UTC (rev 129326)
@@ -0,0 +1,25 @@
+[tox]
+#envlist = py26,py27,py33
+envlist = py26,py27
+
+[testenv]
+commands =
+ python setup.py test -q
+# without explicit deps, setup.py test will download a bunch of eggs into $PWD
+deps =
+ zdaemon
+
+[testenv:coverage]
+basepython =
+ python2.7
+commands =
+# The installed version messes up nose's test discovery / coverage reporting
+# So, we uninstall that from the environment, and then install the editable
+# version, before running nosetests.
+ pip uninstall -y zdaemon
+ pip install -e .
+ nosetests --with-xunit --with-xcoverage
+deps =
+ nose
+ coverage
+ nosexcover
More information about the Zodb-checkins
mailing list