Skip to content

Commit

Permalink
Fix mkwsgiinstance to run under Py3.
Browse files Browse the repository at this point in the history
  • Loading branch information
hannosch committed May 13, 2017
1 parent 1eee860 commit 1458389
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 43 deletions.
4 changes: 2 additions & 2 deletions buildout.cfg
Expand Up @@ -58,7 +58,7 @@ eggs = ZServer

[zopepy]
recipe = zc.recipe.egg
interpreter = ${tox:env}
interpreter = zopepy
eggs = Zope2


Expand Down Expand Up @@ -131,7 +131,7 @@ eggs =
[allpy]
recipe = zc.recipe.egg
eggs = ${alltests:eggs}
interpreter = all${tox:env}
interpreter = allpy


[sphinx]
Expand Down
67 changes: 30 additions & 37 deletions src/Zope2/utilities/copyzopeskel.py
Expand Up @@ -65,8 +65,6 @@
import sys
import getopt

CVS_DIRS = [os.path.normcase("CVS"), os.path.normcase(".svn")]


def main():
try:
Expand Down Expand Up @@ -180,49 +178,43 @@ def copyskel(sourcedir, targetdir, uid, gid, **replacements):
os.chdir(sourcedir)
try:
try:
os.path.walk(os.curdir, copydir,
(targetdir, replacements, uid, gid))
for root, dirs, files in os.walk(os.curdir):
copydir(root, dirs, files, targetdir, replacements, uid, gid)
finally:
os.chdir(pwd)
except (IOError, OSError) as msg:
sys.stderr.write(msg)
sys.exit(1)


def copydir(args, sourcedir, names):
targetdir, replacements, uid, gid = args
# Don't recurse into CVS directories:
for name in names[:]:
if os.path.normcase(name) in CVS_DIRS:
names.remove(name)
elif os.path.isfile(os.path.join(sourcedir, name)):
# Copy the file:
sn, ext = os.path.splitext(name)
if os.path.normcase(ext) == ".in":
dst = os.path.join(targetdir, sourcedir, sn)
if os.path.exists(dst):
continue
copyin(os.path.join(sourcedir, name), dst, replacements, uid,
gid)
if uid is not None:
os.chown(dst, uid, gid)
else:
src = os.path.join(sourcedir, name)
dst = os.path.join(targetdir, src)
if os.path.exists(dst):
continue
shutil.copyfile(src, dst)
shutil.copymode(src, dst)
if uid is not None:
os.chown(dst, uid, gid)
def copydir(sourcedir, dirs, files, targetdir, replacements, uid, gid):
for name in dirs:
dn = os.path.abspath(os.path.join(targetdir, sourcedir, name))
if not os.path.exists(dn):
os.mkdir(dn)
shutil.copymode(os.path.join(sourcedir, name), dn)
if uid is not None:
os.chown(dn, uid, gid)

for name in files:
sn, ext = os.path.splitext(name)
if os.path.normcase(ext) == ".in":
dst = os.path.join(targetdir, sourcedir, sn)
if os.path.exists(dst):
continue
copyin(os.path.join(sourcedir, name), dst, replacements, uid,
gid)
if uid is not None:
os.chown(dst, uid, gid)
else:
# Directory:
dn = os.path.join(targetdir, sourcedir, name)
if not os.path.exists(dn):
os.mkdir(dn)
shutil.copymode(os.path.join(sourcedir, name), dn)
if uid is not None:
os.chown(dn, uid, gid)
src = os.path.join(sourcedir, name)
dst = os.path.abspath(os.path.join(targetdir, src))
if os.path.exists(dst):
continue
shutil.copyfile(src, dst)
shutil.copymode(src, dst)
if uid is not None:
os.chown(dst, uid, gid)


def copyin(src, dst, replacements, uid, gid):
Expand All @@ -246,5 +238,6 @@ def usage(stream, msg=None):
program = os.path.basename(sys.argv[0])
stream.write(__doc__ % {"program": program})


if __name__ == '__main__':
main()
5 changes: 3 additions & 2 deletions src/Zope2/utilities/mkwsgiinstance.py
Expand Up @@ -189,7 +189,7 @@ def write_inituser(fn, user, password):
import binascii
from hashlib import sha1 as sha
fp = open(fn, "w")
pw = binascii.b2a_base64(sha(password).digest())[:-1]
pw = binascii.b2a_base64(sha(password.encode('utf-8')).digest())[:-1]
fp.write('%s:{SHA}%s\n' % (user, pw))
fp.close()
os.chmod(fn, 0o644)
Expand All @@ -209,7 +209,7 @@ def get_zope2path(python):
""" Get Zope2 path from selected Python interpreter.
"""
zope2file = ''
p = os.popen('"%s" -c"import Zope2; print Zope2.__file__"' % python)
p = os.popen('"%s" -c"import Zope2; print(Zope2.__file__)"' % python)
try:
zope2file = p.readline()[:-1]
finally:
Expand All @@ -220,5 +220,6 @@ def get_zope2path(python):
zope2file = Zope2.__file__
return os.path.abspath(os.path.dirname(os.path.dirname(zope2file)))


if __name__ == "__main__":
main()
8 changes: 6 additions & 2 deletions util.py
@@ -1,6 +1,10 @@
from ConfigParser import RawConfigParser
import os

try:
from configparser import RawConfigParser
except ImportError:
from ConfigParser import RawConfigParser

HERE = os.path.abspath(os.path.dirname(__file__))


Expand Down Expand Up @@ -31,7 +35,7 @@ def generate(in_, out):
continue
requirements.append('%s==%s\n' % (name, pin))

with open(out_file, 'wb') as fd:
with open(out_file, 'w') as fd:
fd.write(zope_requirement)
for req in sorted(requirements):
fd.write(req)
Expand Down

0 comments on commit 1458389

Please sign in to comment.