[Zope-Checkins] SVN: Zope/branches/tseaver-fix_wsgi/s added add user script and finder help like how repoze.zope2 added users
Nathan Van Gheem
vangheem at gmail.com
Sun May 30 13:53:01 EDT 2010
Log message for revision 112854:
added add user script and finder help like how repoze.zope2 added users
Changed:
U Zope/branches/tseaver-fix_wsgi/setup.py
A Zope/branches/tseaver-fix_wsgi/src/Zope2/utilities/adduser.py
A Zope/branches/tseaver-fix_wsgi/src/Zope2/utilities/finder.py
-=-
Modified: Zope/branches/tseaver-fix_wsgi/setup.py
===================================================================
--- Zope/branches/tseaver-fix_wsgi/setup.py 2010-05-30 16:37:42 UTC (rev 112853)
+++ Zope/branches/tseaver-fix_wsgi/setup.py 2010-05-30 17:53:01 UTC (rev 112854)
@@ -126,6 +126,7 @@
'runzope=Zope2.Startup.run:run',
'zopectl=Zope2.Startup.zopectl:run',
'zpasswd=Zope2.utilities.zpasswd:main',
+ 'addzope2user=Zope2.utilities.adduser:main'
],
},
)
Added: Zope/branches/tseaver-fix_wsgi/src/Zope2/utilities/adduser.py
===================================================================
--- Zope/branches/tseaver-fix_wsgi/src/Zope2/utilities/adduser.py (rev 0)
+++ Zope/branches/tseaver-fix_wsgi/src/Zope2/utilities/adduser.py 2010-05-30 17:53:01 UTC (rev 112854)
@@ -0,0 +1,32 @@
+##############################################################################
+#
+# This was yanked out of repoze.zope2
+#
+##############################################################################
+
+""" Add a Zope management user to the root Zope user folder """
+
+import sys
+from Zope2.utilities.finder import ZopeFinder
+
+def adduser(app, user, pwd):
+ import transaction
+ result = app.acl_users._doAddUser(user, pwd, ['Manager'], [])
+ transaction.commit()
+ return result
+
+def main(argv=sys.argv):
+ import sys
+ try:
+ user, pwd = argv[1], argv[2]
+ except IndexError:
+ print "%s <username> <password>" % argv[0]
+ sys.exit(255)
+ finder = ZopeFinder(argv)
+ finder.filter_warnings()
+ app = finder.get_app()
+ adduser(app, user, pwd)
+
+if __name__ == '__main__':
+ main()
+
Added: Zope/branches/tseaver-fix_wsgi/src/Zope2/utilities/finder.py
===================================================================
--- Zope/branches/tseaver-fix_wsgi/src/Zope2/utilities/finder.py (rev 0)
+++ Zope/branches/tseaver-fix_wsgi/src/Zope2/utilities/finder.py 2010-05-30 17:53:01 UTC (rev 112854)
@@ -0,0 +1,41 @@
+##############################################################################
+#
+# yanked from repoze.zope2
+#
+##############################################################################
+
+import os
+
+class ZopeFinder:
+ def __init__(self, argv):
+ self.cmd = argv[0]
+
+ def filter_warnings(self):
+ import warnings
+ warnings.simplefilter('ignore', Warning, append=True)
+
+ def get_app(self, config_file=None):
+ # given a config file, return a Zope application object
+ if config_file is None:
+ config_file = self.get_zope_conf()
+ from Zope2.Startup import options, handlers
+ import App.config
+ import Zope2
+ opts = options.ZopeOptions()
+ opts.configfile = config_file
+ opts.realize(args=[], doc="", raise_getopt_errs=0)
+ handlers.handleConfig(opts.configroot, opts.confighandlers)
+ App.config.setConfiguration(opts.configroot)
+ app = Zope2.app()
+ return app
+
+ def get_zope_conf(self):
+ # the default config file path is assumed to live in
+ # $instance_home/etc/zope.conf, and the console scripts that use this
+ # are assumed to live in $instance_home/bin; override if the
+ # environ contains "ZOPE_CONF".
+ ihome = os.path.dirname(os.path.abspath(os.path.dirname(self.cmd)))
+ default_config_file = os.path.join(ihome, 'etc', 'zope.conf')
+ zope_conf = os.environ.get('ZOPE_CONF', default_config_file)
+ return zope_conf
+
More information about the Zope-Checkins
mailing list