Commit ad48234f authored by Andreas Jung's avatar Andreas Jung

merged console-scripts branch

parents a548f168 e034091a
...@@ -48,30 +48,6 @@ setup(name='Zope2', ...@@ -48,30 +48,6 @@ setup(name='Zope2',
packages=find_packages('src'), packages=find_packages('src'),
package_dir={'': 'src'}, package_dir={'': 'src'},
data_files=[
('skel', ['skel/README.txt']),
('skel/bin', ['skel/bin/runzope.bat.in',
'skel/bin/runzope.in',
'skel/bin/zopectl.bat.in',
'skel/bin/zopectl.in',
'skel/bin/zopeservice.py.in',
]),
('skel/etc', ['skel/etc/site.zcml',
'skel/etc/zope.conf.in',
]),
('skel/etc/package-includes', []),
('skel/Extensions', ['skel/Extensions/README.txt']),
('skel/import', ['skel/import/README.txt',
'skel/import/ZopeTutorialExamples.zexp',
]),
('skel/lib/python', ['skel/lib/python/README.txt.in' ]),
('skel/log', ['skel/log/README.txt']),
('skel/Products', ['skel/Products/__init__.py',
'skel/Products/README.txt',
]),
('skel/var', ['skel/var/README.txt']),
],
ext_modules=[ ext_modules=[
# AccessControl # AccessControl
...@@ -265,4 +241,10 @@ setup(name='Zope2', ...@@ -265,4 +241,10 @@ setup(name='Zope2',
include_package_data=True, include_package_data=True,
zip_safe=False, zip_safe=False,
entry_points={
'console_scripts' : [
'mkzopeinstance=Zope2.utilities.mkzopeinstance:main',
'zpasswd=Zope2.utilities.zpasswd:main',
]
},
) )
This directory contains utility scripts and modules that augment Zope.
To get detailed usage information, run any of these scripts without arguments:
load_site.py -- Load a Zope site from files and directories
This script illustrates used of the Zope RPC mechanism,
ZPublisher.Client. It provides some examples of pitfalls
and their work-arounds.
check_catalog.py -- Perform some consistency tests on a ZCatalog instance
mkzopeinstance.py -- create a Zope instance home
copyzopeskel.py -- copy a Zope instance home skeleton directory to target
mkzeoinstance.py -- create a ZEO instance home
requestprofiler.py -- parse and analyze the Zope "detailed" log file
zpasswd.py -- generate "access" or "inituser" files for use with Zope
compilezpy.py -- compile all .py files to .pyc files in the current
directory and below
decompilezpy.py -- remove all .py[co] files in the current directory
and below
#!/usr/bin/env python2.4
##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
"""Script to check consistency of a ZCatalog
$Id$
"""
import Zope2
import os,sys,re,getopt
from types import IntType
from BTrees.IIBTree import IISet,difference,intersection
def checkCatalog(path,indexes):
""" perform some consistency checks on a ZCatalog instance"""
root = Zope2.app()
try:
catalog = root.unrestrictedTraverse(path)
except AttributeError:
print 'Error: catalog object not found'
sys.exit(1)
# get Catalog instance
_cat = catalog._catalog
# check Catalog internal BTrees
l_data = list(_cat.data.keys())
l_data.sort()
l_uids = list(_cat.uids.values())
l_uids.sort()
l_paths = list(_cat.data.keys())
l_paths.sort()
print "Checking catalog internal BTrees"
print "\tINFO: Mapping data: %d entries" % len(l_data)
print "\tINFO: Mapping uids: %d entries" % len(l_uids)
print "\tINFO: Mapping paths: %d entries" % len(l_paths)
if l_data == l_uids:
print "\tOK: Mapping data equals Mapping uids"
else:
print "\tERR: Mapping data does not equal Mapping uids"
if l_data == l_paths:
print "\tOK: Mapping data equals Maaping paths"
else:
print "\tERR: Mapping data does not equal Maaping paths"
# check BTrees of indexes
for id,idx in _cat.indexes.items():
if indexes and not idx.meta_type in indexes: continue
print "Checking index '%s' (type: %s)" % (id, idx.meta_type)
if idx.meta_type in ['FieldIndex','KeywordIndex']:
# check forward entries
RIDS = IISet()
for key, rids in idx._index.items():
if isinstance(rids,IntType):
RIDS.insert( rids )
else:
map(RIDS.insert , rids.keys())
diff = difference(RIDS, IISet(_cat.data.keys()))
if len(diff)!=0:
print '\tERR: Problem with forward entries'
print '\tERR: too much forward entries:', diff
else:
print '\tOK: Forward entries (%d entries)' % (len(RIDS))
elif idx.meta_type in ['PathIndex']:
RIDS = IISet()
for rids in map(None,idx._index.values()):
map(RIDS.insert , rids.values()[0])
diff = difference(RIDS, IISet(_cat.data.keys()))
if len(diff)!=0:
print '\tERR: Problem with forward entries'
print '\tERR: too much forward entries:', diff
else:
print '\tOK: Forward entries (%d entries)' % (len(RIDS))
if idx.meta_type in ['FieldIndex','KeywordIndex','PathIndex']:
# check backward entries
RIDS = IISet(idx._unindex.keys())
diff = difference(RIDS, IISet(_cat.data.keys()))
if len(diff)!=0:
print '\tERR: Problem with backward entries'
print '\tERR: too much backward entries:', diff
else:
print '\tOK: Backward entries (%d entries)' % (len(RIDS))
def usage():
print "Usage: %s [--FieldIndex|KeywordIndex|PathIndex] /path/to/ZCatalog" % \
os.path.basename(sys.argv[0])
print
print "This scripts checks the consistency of the internal"
print "BTrees of a ZCatalog and its indexes."
sys.exit(1)
def main():
opts,args = getopt.getopt(sys.argv[1:],'h',\
['help','FieldIndex','KeywordIndex','PathIndex'])
indexes = []
for o,v in opts:
if o in ['-h','--help']: usage()
if o in ['--FieldIndex','--KeywordIndex','--PathIndex']:
indexes.append(o[2:])
checkCatalog(args,indexes)
if __name__=='__main__':
main()
#!/usr/bin/env python2.4
##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
import compileall, os, sys
class Shutup:
def write(*args): pass # :)
class NoteErr:
wrote = 0
def write(self, *args):
self.wrote = 1
apply(stderr.write, args)
def compile_non_test(dir):
"""Byte-compile all modules except those in test directories."""
success = compileall.compile_dir(dir, maxlevels=0)
try:
names = os.listdir(dir)
except os.error:
print "Can't list", dir
names = []
names.sort()
for name in names:
fullname = os.path.join(dir, name)
if (name != os.curdir and name != os.pardir and
os.path.isdir(fullname) and not os.path.islink(fullname) and
name != 'test' and name != 'tests' and name != 'skins'):
success = success and compile_non_test(fullname)
return success
print
print '-'*78
print 'Compiling python modules'
stdout = sys.stdout
stderr = sys.stderr
try:
try:
success = 0
sys.stdout = Shutup()
sys.stderr = NoteErr()
success = compile_non_test(os.getcwd())
finally:
success = success and not sys.stderr.wrote
sys.stdout = stdout
sys.stderr = stderr
except:
success = 0
import traceback
traceback.print_exc()
if not success:
print
print '!' * 78
print 'There were errors during Python module compilation.'
print '!' * 78
print
sys.exit(1)
#!/usr/bin/env python2.4
##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
"""%(program)s: Create a target directory from a skeleton directory.
usage: %(program)s [options]
Options:
-h/--help -- print this help text
-s/--sourcedir -- the skeleton source directory
-t/--targetdir -- the directory to which the skeleton files will be copied
-u/--uid -- the username/uid of the user who will own the target files
-g/--gid -- the groupname/gid of the group who will own the target files
-r/--replace -- specify replacement value for .in file
This script may be used to install a custom Zope instance home
skeleton directory. It is most useful when used to install a skeleton
which does not follow the standard 'one-directory-as-instance-home'
paradigm used by the stock Zope source install.
The value of --targetdir should be the directory where you would like to copy
the skeleton hierarchy. For many packagers, this will be "/" or "/usr"
or "/usr/local".
The value of --sourcedir should be a directory which contains a custom skeleton
hierarchy. For many packagers, the skeleton source directory may contain
directories like "usr" and "bin" and these directories will contain files
and other directories, comprising an installation hierarchy suitable for your
platform.
The skeleton source hierarchy may contain any kind of file. Files
in the skeleton hierarchy that end with a ".in" extension will go through
textual substitution before they are placed in the target directory. When
they are placed in the target directory, the ".in" extension is removed.
Specify textual replacement values by passing one or more --replace= options
to the script. The value of each replace option needs to be
in the following format: --replace=key:value. 'key' is the value that
will be replaced (minus the "<<" and ">>" values expected by the
replacement). 'value' is the value that should be used for replacement.
Files which do not have an ".in" extension are copied without substitution.
All file mode bits from files/dirs in the skeleton source directory are copied
along with the file/directory itself. If the --uid and/or --gid flags are
used, all directories and files created by this script will be provided with
this owner and/or group. Otherwise, the uid and group owner of the files will
be the executing user's. Existing directory structures and files are left
unchanged. If a file already exists in the target directory, it is left
unchanged and the source file is not copied. If a directory already exists in
the target directory, its ownership information and mode bit settings are left
unchanged.
"""
import os
import shutil
import sys
import getopt
def main():
try:
opts, args = getopt.getopt(sys.argv[1:],
"hs:t:u:g:r:",
["help", "sourcedir=", "targetdir=", "uid=", "gid=",
"replace="]
)
except getopt.GetoptError, msg:
usage(sys.stderr, msg)
sys.exit(2)
script = os.path.abspath(sys.argv[0])
sourcedir = None
targetdir = None
uid = None
gid = None
replacements = {}
for opt, arg in opts:
if opt in ("-h", "--help"):
usage(sys.stdout)
sys.exit()
if opt in ("-s", "--sourcedir"):
sourcedir = os.path.abspath(os.path.expanduser(arg))
if not sourcedir:
usage(sys.stderr, "sourcedir must not be empty")
sys.exit(2)
if opt in ("-t", "--targetdir"):
targetdir = os.path.abspath(os.path.expanduser(arg))
if not targetdir:
usage(sys.stderr, "targetdir must not be empty")
sys.exit(2)
if opt in ("-u", "--uid"):
if not arg:
usage(sys.stderr, "uid must not be empty")
sys.exit(2)
try:
if os.getuid() != 0:
usage(sys.stderr, "You must be root to specify a uid")
sys.exit(2)
try:
uid = int(arg)
except:
try:
import pwd
uid = pwd.getpwnam(arg)[2]
if not gid:
gid = pwd.getpwnam(arg)[3]
except KeyError:
usage(sys.stderr,
"The user indicated by uid does not exist on "
"your system")
sys.exit(2)
except (ImportError, AttributeError):
usage(sys.stderr,
"Your system does not support the gid or uid options")
sys.exit(2)
if opt in ("-g", "--gid"):
if not arg:
usage(sys.stderr, "gid must not be empty")
sys.exit(2)
try:
if os.getuid() != 0:
usage(sys.stderr, "You must be root to specify a gid")
sys.exit(2)
try:
gid = int(arg)
except:
try:
import pwd
gid = pwd.getpwnam(arg)[3]
except KeyError:
usage(sys.stderr,
"The user indicated by gid does not exist on "
"your system")
sys.exit(2)
except (ImportError, AttributeError):
usage(sys.stderr,
"Your system does not support the gid or uid options")
sys.exit(2)
if opt in ("-r", "--replace"):
if not arg:
continue
k, v = arg.split(':', 1)
replacements[k] = v
if not sourcedir:
usage(sys.stderr, "Must specify sourcedir")
sys.exit(2)
if not targetdir:
usage(sys.stderr, "Must specify targetdir")
sys.exit(2)
copyskel(sourcedir, targetdir, uid, gid, **replacements)
def copyskel(sourcedir, targetdir, uid, gid, **replacements):
""" This is an independent function because we'd like to
import and call it from mkzopeinstance """
# Create the top of the instance:
if not os.path.exists(targetdir):
os.makedirs(targetdir)
# This is fairly ugly. The chdir() makes path manipulation in the
# walk() callback a little easier (less magical), so we'll live
# with it.
pwd = os.getcwd()
os.chdir(sourcedir)
try:
try:
os.path.walk(os.curdir, copydir,
(targetdir, replacements, uid, gid))
finally:
os.chdir(pwd)
except (IOError, OSError), msg:
print >>sys.stderr, msg
sys.exit(1)
CVS_DIRS = [os.path.normcase("CVS"), os.path.normcase(".svn")]
def copydir((targetdir, replacements, uid, gid), sourcedir, names):
# 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)
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)
def copyin(src, dst, replacements, uid, gid):
ifp = open(src)
text = ifp.read()
ifp.close()
for k in replacements:
text = text.replace("<<%s>>" % k, replacements[k])
ofp = open(dst, "w")
ofp.write(text)
ofp.close()
shutil.copymode(src, dst)
if uid is not None:
os.chown(dst, uid, gid)
def usage(stream, msg=None):
if msg:
print >>stream, msg
print >>stream
program = os.path.basename(sys.argv[0])
print >>stream, __doc__ % {"program": program}
if __name__ == '__main__':
main()
#!/usr/bin/env python2.4
##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
import os
import sys
def main(dirname):
os.path.walk(dirname, rmpycs, None)
def rmpycs(arg, dirname, names):
for name in names:
path = os.path.join(dirname, name)
if ( name.endswith('.pyc') or name.endswith('.pyo') and
os.path.isfile(path) ):
os.unlink(path)
if __name__ == '__main__':
main(sys.argv[1])
# Script to fix the header files to ZPL 2.1
import os
for dirpath, dirnames, filenames in os.walk('.'):
for fname in filenames:
base,ext = os.path.splitext(fname)
if not ext in ('.py', '.c', '.h'): continue
fullname = os.path.join(dirpath, fname)
if '.svn' in fullname: continue
data = open(fullname).read()
changed = False
if 'Version 2.1 (ZPL)' in data:
data = data.replace('Version 2.1 (ZPL)', 'Version 2.1 (ZPL)')
changed = True
if '(c) 2002 Zope Corporation' in data:
data = data.replace('(c) 2002 Zope Corporation', '(c) 2002 Zope Corporation')
changed = True
print fullname, changed
if changed:
open(fullname, 'w').write(data)
import optparse
import os
import os.path
import sys
import re
here = os.path.abspath(os.path.dirname(__file__))
# I would use string.Template, but it's just too hard to change it to
# respect only ${brace} syntax instead of both that and $name syntax.
TOKEN_RE = re.compile(r'\$\{([\.\w/-]+)\}')
def rewrite(repltext, **kw):
def replace(match):
return kw[match.group(1)]
return TOKEN_RE.sub(replace, repltext)
def mkinstance(conf):
sandbox = conf['sandbox']
for dir in ('bin', 'etc', 'var', 'Products', 'import', 'log'):
path = os.path.join(sandbox, dir)
if not os.path.exists(path):
os.makedirs(path)
try:
# this is (stupidly) required by the zdrun key in the <runner>
# section of zeo.conf
import zdaemon
conf['zdaemon_pkgdir'] = zdaemon.__path__[0]
except ImportError:
conf['zdaemon_pkgdir'] = '{unknown}'
zope_conf = conf['zope_conf']
site_zcml = conf['site_zcml']
for source, target in (
('zope2.ini', 'zope2.ini'),
(site_zcml, 'site.zcml'),
(zope_conf, 'zope.conf'),
('apache2.conf', 'apache2.conf'),
('zeo.conf', 'zeo.conf'),
):
template = open(os.path.join(here, 'etc', source), 'r').read()
result = rewrite(template, **conf)
targetfile = os.path.join(sandbox, 'etc', target)
if not os.path.exists(targetfile):
open(targetfile, 'w').write(result)
template = open(os.path.join(here, 'etc', 'zope2.wsgi'), 'r').read()
result = rewrite(template, **conf)
targetfile = os.path.join(sandbox, 'bin', 'zope2.wsgi')
if not os.path.exists(targetfile):
open(targetfile, 'w').write(result)
os.chmod(targetfile, 0755)
def main(argv=sys.argv):
""" Console script target """
parser = optparse.OptionParser(
usage='%prog [OPTIONS]'
)
parser.add_option('-s', '--sandbox', action='store', dest='sandbox',
default='.', help='Create the instance in this directory')
parser.add_option('-p', '--zope-port', action='store', dest='zope_port',
default='8080', help='Zope HTTP port')
parser.add_option('-j', '--zeo-port', action='store', dest='zeo_port',
default='8100', help='ZEO server port number')
parser.add_option('-z', '--use-zeo', action='store_true', dest='use_zeo',
default=False, help='Use ZEO to house main storage')
options, args = parser.parse_args(argv)
try:
# Zope 2.10+ (Five 1.5.3?+)
from Products.Five.fivedirectives import IRegisterPackageDirective
options.site_zcml = 'zope-2.10+-site.zcml'
except ImportError:
# Zope 2.9 (or Five before 1.5.3?)
options.site_zcml = 'zope-2.9-site.zcml'
if options.use_zeo:
options.zope_conf = 'zope-zeoclient.conf'
else:
options.zope_conf = 'zope-nonzeoclient.conf'
options.python = sys.executable
conf = options.__dict__
sandbox = conf['sandbox']
conf['sandbox'] = os.path.abspath(os.path.normpath(os.path.expanduser(
sandbox)))
mkinstance(conf)
#!/usr/bin/env python2.4
##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
"""Load a Zope site from a collection of files or directories
"""
usage=""" [options] url file .....
where options are:
-D
For HTML documents, replace the start of the content, up to
and including the opening body tag with a DTML var tag that
inserts the standard header. Also replace the closing body
and html tag with a DTML var tag that inserts the standard
footer.
-I
For each index.html, add an index_html that redirects.
-p path
Path to ZPublisher. If not provided, load_site will
make an attempt to figure it out.
-u user:password
Credentials
-v
Run in verbose mode.
-9
Use *old* zope method names.
"""
import sys, getopt, os, string
ServerError=''
verbose=0
old=0
doctor=0
index_html=0
def main():
user, password = 'superuser', '123'
opts, args = getopt.getopt(sys.argv[1:], 'p:u:DIv9')
global verbose
global old
global doctor
global index_html
havepath=None
for o, v in opts:
if o=='-p':
d, f = os.path.split(v)
if f=='ZPublisher': sys.path.insert(0,d)
else: sys.path.insert(0,v)
havepath=1
elif o=='-u':
v = string.split(v,':')
user, password = v[0], string.join(v[1:],':')
elif o=='-D': doctor=1
elif o=='-I': index_html=1
elif o=='-v': verbose=1
elif o=='-9': old=1
if not args:
print sys.argv[0]+usage
sys.exit(1)
if not havepath:
here=os.path.split(sys.argv[0])[0]
if os.path.exists(os.path.join(here,'ZPublisher')):
sys.path.insert(0,here)
else:
here=os.path.split(here)[0]
here=os.path.join(here,'lib','python')
if os.path.exists(os.path.join(here,'ZPublisher')):
sys.path.insert(0,here)
url=args[0]
files=args[1:]
import ZPublisher.Client
global ServerError
ServerError=ZPublisher.Client.ServerError
object=ZPublisher.Client.Object(url, username=user, password=password)
for f in files: upload_file(object, f)
def call(f, *args, **kw):
# Call a function ignoring redirect bci errors.
try: apply(f,args, kw)
except ServerError, v:
if str(v)[:1] != '3':
raise sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2]
def upload_file(object, f):
if os.path.isdir(f): return upload_dir(object, f)
dir, name = os.path.split(f)
root, ext = os.path.splitext(name)
if ext in ('file', 'dir'): ext=''
else:
ext=string.lower(ext)
if ext and ext[0] in '.': ext=ext[1:]
if ext and globals().has_key('upload_'+ext):
if verbose: print 'upload_'+ext, f
return globals()['upload_'+ext](object, f)
if verbose: print 'upload_file', f, ext
call(object.manage_addFile, id=name, file=open(f,'rb'))
def upload_dir(object, f):
if verbose: print 'upload_dir', f
dir, name = os.path.split(f)
call(object.manage_addFolder, id=name)
object=object.__class__(object.url+'/'+name,
username=object.username,
password=object.password)
for n in os.listdir(f):
upload_file(object, os.path.join(f,n))
# ----- phd -----
# Modified by Oleg Broytmann <phd2@earthling.net>
from sgmllib import SGMLParser
def join_attrs(attrs):
attr_list = []
for attrname, value in attrs:
attr_list.append('%s="%s"' % (attrname, string.strip(value)))
if attr_list:
s = " " + string.join(attr_list, " ")
else:
s = ""
return s
class HeadParser(SGMLParser):
def __init__(self):
SGMLParser.__init__(self)
self.seen_starthead = 0
self.seen_endhead = 0
self.seen_startbody = 0
self.head = ""
self.title = ""
self.accumulator = ""
def handle_data(self, data):
if data:
self.accumulator = self.accumulator + data
def handle_charref(self, ref):
self.handle_data("&#%s;" % ref)
def handle_entityref(self, ref):
self.handle_data("&%s;" % ref)
def handle_comment(self, data):
if data:
self.accumulator = self.accumulator + "<!--%s-->" % data
def start_head(self, attrs):
if not self.seen_starthead:
self.seen_starthead = 1
self.head = ""
self.title = ""
self.accumulator = ""
def end_head(self):
if not self.seen_endhead:
self.seen_endhead = 1
self.head = self.head + self.accumulator
self.accumulator = ""
def start_title(self, attrs):
self.head = self.head + self.accumulator
self.accumulator = ""
def end_title(self):
self.title = self.accumulator
self.accumulator = ""
def start_body(self, attrs):
if not self.seen_startbody:
self.seen_startbody = 1
self.accumulator = ""
def end_body(self): pass # Do not put </BODY> and </HTML>
def end_html(self): pass # into output stream
# Pass other tags unmodified
def unknown_starttag(self, tag, attrs):
self.accumulator = self.accumulator + "<%s%s>" % (string.upper(tag), join_attrs(attrs))
def unknown_endtag(self, tag):
self.accumulator = self.accumulator + "</%s>" % string.upper(tag)
def parse_html(infile):
parser = HeadParser()
while 1:
line = infile.readline()
if not line: break
parser.feed(line)
parser.close()
infile.close()
return (string.strip(parser.title), string.strip(parser.head),
string.strip(parser.accumulator))
def upload_html(object, f):
dir, name = os.path.split(f)
f=open(f)
if doctor:
title, head, body = parse_html(f)
if old:
body = ("<!--#var standard_html_header-->\n\n" +
body + "\n\n<!--#var standard_html_footer-->")
else:
body = ("<dtml-var standard_html_header>\n\n" +
body + "\n\n<dtml-var standard_html_footer>")
else:
if old: f=f.read()
title, head, body = '', '', f
if old:
call(object.manage_addDocument, id=name, file=body)
if index_html and name in ('index.html', 'index.htm'):
call(object.manage_addDocument, id='index_html',
file=('<!--#raise Redirect-->'
'<!--#var URL1-->/%s'
'<!--#/raise-->' % name
))
else:
call(object.manage_addDTMLDocument, id=name, title=title, file=body)
if index_html and name in ('index.html', 'index.htm'):
call(object.manage_addDTMLMethod, id='index_html',
file=('<dtml-raise Redirect>'
'<dtml-var URL1>/%s'
'</dtml-raise>' % name
))
# Now add META and other tags as property
if head:
object=object.__class__(object.url+'/'+name,
username=object.username,
password=object.password)
call(object.manage_addProperty,
id="loadsite-head", type="text", value=head)
# ----- /phd -----
upload_htm=upload_html
def upload_dtml(object, f):
dir, name = os.path.split(f)
f=open(f)
if old:
f=f.read()
call(object.manage_addDocument, id=name, file=f)
else:
call(object.manage_addDTMLMethod, id=name, file=f)
def upload_gif(object, f):
dir, name = os.path.split(f)
call(object.manage_addImage, id=name, file=open(f,'rb'))
upload_jpg=upload_gif
upload_png=upload_gif
if __name__=='__main__': main()
#!/usr/bin/env python2.4
##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
import os
import sys
mydir = os.path.dirname(os.path.abspath(sys.argv[0]))
zopehome = os.path.dirname(mydir)
softwarehome = os.path.join(zopehome, "lib", "python")
if softwarehome not in sys.path:
sys.path.insert(0, softwarehome)
from ZEO.mkzeoinst import ZEOInstanceBuilder
if __name__ == "__main__":
ZEOInstanceBuilder().run()
#!/usr/bin/env python2.4
##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
"""%(program)s: Create a Zope instance home.
usage: %(program)s [options]
Options:
-h/--help -- print this help text
-d/--dir -- the dir in which the instance home should be created
-u/--user NAME:PASSWORD -- set the user name and password of the initial user
-s/--skelsrc -- the dir from which skeleton files should be copied
When run without arguments, this script will ask for the information necessary
to create a Zope instance home.
"""
import getopt
import os
import shutil
import sys
import copyzopeskel
def main():
try:
opts, args = getopt.getopt(sys.argv[1:],
"hu:d:s:",
["help", "user=", "dir=", "skelsrc="]
)
except getopt.GetoptError, msg:
usage(sys.stderr, msg)
sys.exit(2)
script = os.path.abspath(sys.argv[0])
user = None
password = None
skeltarget = None
skelsrc = None
for opt, arg in opts:
if opt in ("-d", "--dir"):
skeltarget = os.path.abspath(os.path.expanduser(arg))
if not skeltarget:
usage(sys.stderr, "dir must not be empty")
sys.exit(2)
if opt in ("-s", "--skelsrc"):
skelsrc = os.path.abspath(os.path.expanduser(arg))
if not skelsrc:
usage(sys.stderr, "skelsrc must not be empty")
sys.exit(2)
if opt in ("-h", "--help"):
usage(sys.stdout)
sys.exit()
if opt in ("-u", "--user"):
if not arg:
usage(sys.stderr, "user must not be empty")
sys.exit(2)
if not ":" in arg:
usage(sys.stderr, "user must be specified as name:password")
sys.exit(2)
user, password = arg.split(":", 1)
if not skeltarget:
# interactively ask for skeltarget and initial user name/passwd.
# cant set custom instancehome in interactive mode, we default
# to skeltarget.
skeltarget = instancehome = os.path.abspath(
os.path.expanduser(get_skeltarget())
)
instancehome = skeltarget
zopehome = os.path.dirname(os.path.dirname(script))
softwarehome = os.path.join(zopehome, "src")
configfile = os.path.join(instancehome, 'etc', 'zope.conf')
if skelsrc is None:
# default to using stock Zope skeleton source
skelsrc = os.path.join(os.path.dirname(__file__), "skel")
inituser = os.path.join(instancehome, "inituser")
if not (user or os.path.exists(inituser)):
user, password = get_inituser()
# we need to distinguish between python.exe and pythonw.exe under
# Windows. Zope is always run using 'python.exe' (even for services),
# however, it may be installed via pythonw.exe (as a sub-process of an
# installer). Thus, sys.executable may not be the executable we use.
# We still provide both PYTHON and PYTHONW, but PYTHONW should never
# need be used.
psplit = os.path.split(sys.executable)
exedir = os.path.join(*psplit[:-1])
pythonexe = os.path.join(exedir, 'python.exe')
pythonwexe = os.path.join(exedir, 'pythonw.exe')
if ( os.path.isfile(pythonwexe) and os.path.isfile(pythonexe) and
(sys.executable in [pythonwexe, pythonexe]) ):
# we're using a Windows build with both python.exe and pythonw.exe
# in the same directory
PYTHON = pythonexe
PYTHONW = pythonwexe
else:
# we're on UNIX or we have a nonstandard Windows setup
PYTHON = PYTHONW = sys.executable
kw = {
"PYTHON":PYTHON,
"PYTHONW":PYTHONW,
"INSTANCE_HOME": instancehome,
"SOFTWARE_HOME": softwarehome,
"ZOPE_HOME": zopehome,
}
copyzopeskel.copyskel(skelsrc, skeltarget, None, None, **kw)
if user and password:
write_inituser(inituser, user, password)
def usage(stream, msg=None):
if msg:
print >>stream, msg
print >>stream
program = os.path.basename(sys.argv[0])
print >>stream, __doc__ % {"program": program}
def get_skeltarget():
print 'Please choose a directory in which you\'d like to install'
print 'Zope "instance home" files such as database files, configuration'
print 'files, etc.'
print
while 1:
skeltarget = raw_input("Directory: ").strip()
if skeltarget == '':
print 'You must specify a directory'
continue
else:
break
return skeltarget
def get_inituser():
import getpass
print 'Please choose a username and password for the initial user.'
print 'These will be the credentials you use to initially manage'
print 'your new Zope instance.'
print
user = raw_input("Username: ").strip()
if user == '':
return None, None
while 1:
passwd = getpass.getpass("Password: ")
verify = getpass.getpass("Verify password: ")
if verify == passwd:
break
else:
passwd = verify = ''
print "Password mismatch, please try again..."
return user, passwd
def write_inituser(fn, user, password):
import binascii
try:
from hashlib import sha1 as sha
except:
from sha import new as sha
fp = open(fn, "w")
pw = binascii.b2a_base64(sha(password).digest())[:-1]
fp.write('%s:{SHA}%s\n' % (user, pw))
fp.close()
os.chmod(fn, 0644)
if __name__ == "__main__":
main()
##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
"""
A utility to perform external reindex operations for ZCatalogs
Usage:
zopectl run reindex_catalog.py [options]
Use --help to get a list of all options.
Author: Andreas Jung (andreas@andreas-jung.com)
$Id$
"""
import sys
from optparse import OptionParser
import transaction
from Products.ZCatalog.ProgressHandler import StdoutHandler
def path2catalog(path):
""" lookup catalog by path """
catalog = app.restrictedTraverse(path, None)
if not catalog:
raise ValueError('No catalog found at %s' % path)
return catalog
def getHandler(options):
""" return a progress handler """
if options.silent:
return None
else:
return StdoutHandler(options.steps)
def listIndexes(options, args):
""" print a list of all indexes to stdout """
catalog = path2catalog(options.catalog)
indexes = catalog._catalog.indexes
print 'Listing of all indexes at %s' % options.catalog
print
for id, idx in indexes.items():
print '%-20s %-50s %d' % (id, idx.meta_type, idx.numObjects())
def reindexIndexes(optioons, args):
""" reindex given list of indexes """
catalog = path2catalog(options.catalog)
handler = getHandler(options)
for id in args:
print 'Reindexing index %s at %s' % (id, options.catalog)
catalog.reindexIndex(id, None, handler)
transaction.commit()
def refreshMetadata(options, args):
""" reindex metadata """
catalog = path2catalog(options.catalog)
handler = getHandler(options)
print 'Refresh metadata at %s' % options.catalog
catalog.refreshMetadata(handler)
transaction.commit()
def reindexAll(options, args):
""" reindex complete catalog """
catalog = path2catalog(options.catalog)
handler = getHandler(options)
print 'Reindexing complete ZCatalog at %s' % options.catalog
catalog.refreshCatalog(options.clearCatalog, handler)
transaction.commit()
if __name__ == '__main__':
parser = OptionParser()
parser.add_option('-c', '--catalog', dest='catalog',
help='path to ZCatalog')
parser.add_option('-i', '--indexes', action="store_true", dest="listIndexes",
help='list all indexes')
parser.add_option('-C', '--clear', action="store_true", dest="clearCatalog", default=False,
help='clear catalog before reindexing the complete catalog (--all only)')
parser.add_option('-a', '--all', action="store_true", dest="reindexAll",
help='reindex the complete catalog and update all metadata')
parser.add_option('-r', '--reindex', action="store_true", dest="reindexIndexes",
help='reindex specified indexes')
parser.add_option('-m', '--metadata', action="store_true", dest="refreshMetadata",
help='refresh all metadata')
parser.add_option('-n', '--steps', dest="steps", default=100, type="int",
help='log progress every N objects')
parser.add_option('-s', '--silent', action="store_true", dest="silent", default=False,
help='do not log reindexing progress to stdout')
options,args = parser.parse_args()
if options.listIndexes: listIndexes(options, args)
if options.reindexIndexes: reindexIndexes(options, args)
if options.refreshMetadata: refreshMetadata(options, args)
if options.reindexAll: reindexAll(options, args)
This diff is collapsed.
...@@ -8,6 +8,7 @@ SOFTWARE_HOME="<<SOFTWARE_HOME>>" ...@@ -8,6 +8,7 @@ SOFTWARE_HOME="<<SOFTWARE_HOME>>"
PYTHONPATH="$SOFTWARE_HOME:$PYTHONPATH" PYTHONPATH="$SOFTWARE_HOME:$PYTHONPATH"
export PYTHONPATH INSTANCE_HOME SOFTWARE_HOME export PYTHONPATH INSTANCE_HOME SOFTWARE_HOME
ZOPE_RUN="$SOFTWARE_HOME/Zope2/Startup/run.py" ZOPE2PATH=`${PYTHON} -c "import os, Zope2; print os.path.dirname(Zope2.__file__)" `
ZOPE_RUN="$ZOPE2PATH/Startup/run.py"
exec "$PYTHON" "$ZOPE_RUN" -C "$CONFIG_FILE" "$@" exec "$PYTHON" "$ZOPE_RUN" -C "$CONFIG_FILE" "$@"
...@@ -8,6 +8,7 @@ SOFTWARE_HOME="<<SOFTWARE_HOME>>" ...@@ -8,6 +8,7 @@ SOFTWARE_HOME="<<SOFTWARE_HOME>>"
PYTHONPATH="$SOFTWARE_HOME:$PYTHONPATH" PYTHONPATH="$SOFTWARE_HOME:$PYTHONPATH"
export PYTHONPATH INSTANCE_HOME SOFTWARE_HOME export PYTHONPATH INSTANCE_HOME SOFTWARE_HOME
ZDCTL="$SOFTWARE_HOME/Zope2/Startup/zopectl.py" ZOPE2PATH=`${PYTHON} -c "import os, Zope2; print os.path.dirname(Zope2.__file__)" `
ZDCTL="$ZOPE2PATH/Startup/zopectl.py"
exec "$PYTHON" "$ZDCTL" -C "$CONFIG_FILE" "$@" exec "$PYTHON" "$ZDCTL" -C "$CONFIG_FILE" "$@"
This diff is collapsed.
#!/usr/bin/env python2.4
##############################################################################
#
# Copyright (c) 2001,2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
"""Zope user bootstrap system
Usage: %(PROGRAM)s [options] filename
If this program is called without command-line options, it will prompt
for all necessary information. The available options are:
-u / --username=
Set the username to be used for the initial user or the emergency user
-p / --password=
Set the password
-e / --encoding=
Set the encryption/encoding rules. Defaults to SHA-1. OPTIONAL
-d / --domains=
Set the domain names that the user user can log in from. Defaults to
any. OPTIONAL.
-h / --help
Print this help text and exit.
Filename is required and should be the name of the file to store the
information in (usually "inituser" or "access").
"""
import sys, sha, binascii, random, getopt, getpass, os
try:
from crypt import crypt
except ImportError:
crypt = None
PROGRAM = sys.argv[0]
COMMASPACE = ', '
def generate_salt():
"""Generate a salt value for the crypt function."""
salt_choices = ("ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789./")
return random.choice(salt_choices)+random.choice(salt_choices)
def generate_passwd(password, encoding):
encoding=encoding.upper()
if encoding == 'SHA':
pw = '{SHA}' + binascii.b2a_base64(sha.new(password).digest())[:-1]
elif encoding == 'CRYPT':
pw = '{CRYPT}' + crypt(password, generate_salt())
elif encoding == 'CLEARTEXT':
pw = password
else:
raise ValueError('Unsupported encoding: %s' % encoding)
return pw
def write_generated_password(home, ac_path, username):
pw_choices = ("ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789!")
acfile=open(ac_path, 'w')
pw = ''
for i in range(8):
pw = pw + random.choice(pw_choices)
acfile.write('%s:%s\n' % (username, generate_passwd(pw, 'SHA')))
acfile.close()
os.chmod(ac_path, 0644)
return pw
def write_access(home, user='', group=''):
ac_path=os.path.join(home, 'access')
if not os.path.exists(ac_path):
print '-'*78
print 'creating default access file'
pw = write_generated_password(home, ac_path, 'emergency')
print """Note:
The emergency user name and password are 'emergency'
and '%s'.
You can change the emergency name and password with the
zpasswd script. To find out more, type:
%s zpasswd.py
""" % (pw, sys.executable)
import do; do.ch(ac_path, user, group)
def get_password():
while 1:
password = getpass.getpass("Password: ")
verify = getpass.getpass("Verify password: ")
if verify == password:
return password
else:
password = verify = ''
print "Password mismatch, please try again..."
def write_inituser(home, user='', group=''):
ac_path=os.path.join(home, 'inituser')
if not os.path.exists(ac_path):
print '-'*78
print 'creating default inituser file'
pw = write_generated_password(home, ac_path, 'admin')
print """Note:
The initial user name and password are 'admin'
and '%s'.
You can change the name and password through the web
interface or using the 'zpasswd.py' script.
""" % pw
import do; do.ch(ac_path, user, group)
def usage(code, msg=''):
print >> sys.stderr, __doc__ % globals()
if msg:
print >> sys.stderr, msg
sys.exit(code)
def main():
shortopts = 'u:p:e:d:h'
longopts = ['username=',
'password=',
'encoding=',
'domains=',
'help']
try:
opts, args = getopt.getopt(sys.argv[1:], shortopts, longopts)
except getopt.error, msg:
usage(1, msg)
# Defaults
username = password = None
domains = ''
encoding = 'SHA'
for opt, arg in opts:
if opt in ('-h', '--help'):
usage(0)
elif opt in ('-u', '--username'):
username = arg
elif opt in ('-p', '--password'):
password = arg
elif opt in ('-e', '--encoding'):
encoding = arg
elif opt in ('-d', '--domains'):
domains = ':' + arg
# Extra command line arguments?
if len(args) == 0:
usage(1, 'filename is required')
elif len(args) == 1:
access_file = open(args[0], 'w')
else:
usage(1, 'Extra command line arguments: ' + COMMASPACE.join(args))
if opts:
# There were some command line args, so verify
if username is not None and password is None:
password = get_password()
else:
# No command line args, so prompt
while 1:
username = raw_input("Username: ")
if username != '':
break
password = get_password()
while 1:
print """
Please choose a format from:
SHA - SHA-1 hashed password (default)
CRYPT - UNIX-style crypt password
CLEARTEXT - no protection
"""
encoding = raw_input("Encoding: ")
if encoding == '':
encoding = 'SHA'
break
if encoding.upper() in ['SHA', 'CRYPT', 'CLEARTEXT']:
break
domains = raw_input("Domain restrictions: ")
if domains:
domains = ":" + domains
# Done with prompts and args
access_file.write(username + ":" +
generate_passwd(password, encoding) +
domains)
# If called from the command line
if __name__=='__main__':
main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment