Skip to content

Commit eb9c727

Browse files
committed
Initial draft of Python Scripts.
They are working for me in zopeache.webapp.
1 parent 26983f0 commit eb9c727

19 files changed

+587
-4
lines changed

.gitignore

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.installed.cfg
2+
3+
bin
4+
develop-eggs
5+
dist
6+
parts
7+
8+
src/*.egg-info
9+
10+
*.pyc

CHANGES.rst

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
=======
2+
CHANGES
3+
=======
4+
5+
0.1.0 (unreleased)
6+
------------------
7+
8+
- Initial release.
9+
10+
* A simple Python Script implementation behaving similar to Zope 2's version.

MANIFEST.in

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
include *.txt
2+
include *.rst
3+
include bootstrap.py
4+
include buildout.cfg
5+
recursive-include src/zopache/pagetemplate *.zcml *.py *.pt *.gif

README.md

-4
This file was deleted.

README.rst

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
======================
2+
Zopache Python Scripts
3+
======================
4+
5+
Zopache Python Scripts are a port of Zoep 2 Python scripts, which allows
6+
users to write Python functions via a Web UI.

bootstrap.py

+165
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
##############################################################################
2+
#
3+
# Copyright (c) 2006 Zope Foundation and Contributors.
4+
# All Rights Reserved.
5+
#
6+
# This software is subject to the provisions of the Zope Public License,
7+
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
8+
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
9+
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
10+
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
11+
# FOR A PARTICULAR PURPOSE.
12+
#
13+
##############################################################################
14+
"""Bootstrap a buildout-based project
15+
16+
Simply run this script in a directory containing a buildout.cfg.
17+
The script accepts buildout command-line options, so you can
18+
use the -c option to specify an alternate configuration file.
19+
"""
20+
21+
import os, shutil, sys, tempfile
22+
from optparse import OptionParser
23+
24+
tmpeggs = tempfile.mkdtemp()
25+
26+
usage = '''\
27+
[DESIRED PYTHON FOR BUILDOUT] bootstrap.py [options]
28+
29+
Bootstraps a buildout-based project.
30+
31+
Simply run this script in a directory containing a buildout.cfg, using the
32+
Python that you want bin/buildout to use.
33+
34+
Note that by using --setup-source and --download-base to point to
35+
local resources, you can keep this script from going over the network.
36+
'''
37+
38+
parser = OptionParser(usage=usage)
39+
parser.add_option("-v", "--version", help="use a specific zc.buildout version")
40+
41+
parser.add_option("-t", "--accept-buildout-test-releases",
42+
dest='accept_buildout_test_releases',
43+
action="store_true", default=False,
44+
help=("Normally, if you do not specify a --version, the "
45+
"bootstrap script and buildout gets the newest "
46+
"*final* versions of zc.buildout and its recipes and "
47+
"extensions for you. If you use this flag, "
48+
"bootstrap and buildout will get the newest releases "
49+
"even if they are alphas or betas."))
50+
parser.add_option("-c", "--config-file",
51+
help=("Specify the path to the buildout configuration "
52+
"file to be used."))
53+
parser.add_option("-f", "--find-links",
54+
help=("Specify a URL to search for buildout releases"))
55+
56+
57+
options, args = parser.parse_args()
58+
59+
######################################################################
60+
# load/install distribute
61+
62+
to_reload = False
63+
try:
64+
import pkg_resources, setuptools
65+
if not hasattr(pkg_resources, '_distribute'):
66+
to_reload = True
67+
raise ImportError
68+
except ImportError:
69+
ez = {}
70+
71+
try:
72+
from urllib.request import urlopen
73+
except ImportError:
74+
from urllib2 import urlopen
75+
76+
exec(urlopen('http://python-distribute.org/distribute_setup.py').read(), ez)
77+
setup_args = dict(to_dir=tmpeggs, download_delay=0, no_fake=True)
78+
ez['use_setuptools'](**setup_args)
79+
80+
if to_reload:
81+
reload(pkg_resources)
82+
import pkg_resources
83+
# This does not (always?) update the default working set. We will
84+
# do it.
85+
for path in sys.path:
86+
if path not in pkg_resources.working_set.entries:
87+
pkg_resources.working_set.add_entry(path)
88+
89+
######################################################################
90+
# Install buildout
91+
92+
ws = pkg_resources.working_set
93+
94+
cmd = [sys.executable, '-c',
95+
'from setuptools.command.easy_install import main; main()',
96+
'-mZqNxd', tmpeggs]
97+
98+
find_links = os.environ.get(
99+
'bootstrap-testing-find-links',
100+
options.find_links or
101+
('http://downloads.buildout.org/'
102+
if options.accept_buildout_test_releases else None)
103+
)
104+
if find_links:
105+
cmd.extend(['-f', find_links])
106+
107+
distribute_path = ws.find(
108+
pkg_resources.Requirement.parse('distribute')).location
109+
110+
requirement = 'zc.buildout'
111+
version = options.version
112+
if version is None and not options.accept_buildout_test_releases:
113+
# Figure out the most recent final version of zc.buildout.
114+
import setuptools.package_index
115+
_final_parts = '*final-', '*final'
116+
def _final_version(parsed_version):
117+
for part in parsed_version:
118+
if (part[:1] == '*') and (part not in _final_parts):
119+
return False
120+
return True
121+
index = setuptools.package_index.PackageIndex(
122+
search_path=[distribute_path])
123+
if find_links:
124+
index.add_find_links((find_links,))
125+
req = pkg_resources.Requirement.parse(requirement)
126+
if index.obtain(req) is not None:
127+
best = []
128+
bestv = None
129+
for dist in index[req.project_name]:
130+
distv = dist.parsed_version
131+
if _final_version(distv):
132+
if bestv is None or distv > bestv:
133+
best = [dist]
134+
bestv = distv
135+
elif distv == bestv:
136+
best.append(dist)
137+
if best:
138+
best.sort()
139+
version = best[-1].version
140+
if version:
141+
requirement = '=='.join((requirement, version))
142+
cmd.append(requirement)
143+
144+
import subprocess
145+
if subprocess.call(cmd, env=dict(os.environ, PYTHONPATH=distribute_path)) != 0:
146+
raise Exception(
147+
"Failed to execute command:\n%s",
148+
repr(cmd)[1:-1])
149+
150+
######################################################################
151+
# Import and run buildout
152+
153+
ws.add_entry(tmpeggs)
154+
ws.require(requirement)
155+
import zc.buildout.buildout
156+
157+
if not [a for a in args if '=' not in a]:
158+
args.append('bootstrap')
159+
160+
# if -c was provided, we push it back into args for buildout' main function
161+
if options.config_file is not None:
162+
args[0:0] = ['-c', options.config_file]
163+
164+
zc.buildout.buildout.main(args)
165+
shutil.rmtree(tmpeggs)

buildout.cfg

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[buildout]
2+
develop = .
3+
parts = test
4+
5+
[test]
6+
recipe = zc.recipe.testrunner
7+
eggs = zopache.pythonscript [test]
8+

setup.py

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
##############################################################################
2+
#
3+
# Copyright (c) 2013 Christopher Lozinski ([email protected]).
4+
# All Rights Reserved.
5+
#
6+
# This software is subject to the provisions of the Zope Public License,
7+
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
8+
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
9+
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
10+
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
11+
# FOR A PARTICULAR PURPOSE.
12+
#
13+
##############################################################################
14+
"""Setup for zopache.pythonscript package
15+
"""
16+
import os
17+
from setuptools import setup, find_packages
18+
19+
def read(*rnames):
20+
return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
21+
22+
setup(
23+
name='zopache.pythonscript',
24+
version='0.1.0dev',
25+
url='http://pypi.python.org/pypi/zopache.pythonscript',
26+
author='Christopher Lozinski',
27+
author_email='[email protected]',
28+
license='ZPL 2.1',
29+
classifiers=[
30+
'Development Status :: 4 - Beta',
31+
'Intended Audience :: Developers',
32+
'License :: OSI Approved :: Zope Public License',
33+
'Programming Language :: Python',
34+
'Operating System :: OS Independent',
35+
'Topic :: Internet :: WWW/HTTP',
36+
'Topic :: Software Development',
37+
'Framework :: Zope3',
38+
],
39+
description='content TTW python script function',
40+
long_description = (
41+
read('README.rst')
42+
+ '\n\n' +
43+
read('CHANGES.rst')
44+
),
45+
packages=find_packages('src'),
46+
package_dir={'': 'src'},
47+
namespace_packages=['zopache'],
48+
include_package_data=True,
49+
install_requires=[
50+
'setuptools',
51+
'zope.container',
52+
'zope.app.publication',
53+
'zope.formlib',
54+
'zope.interface',
55+
'zope.publisher',
56+
'zope.schema',
57+
'zope.security',
58+
'zope.size',
59+
'ZODB3',
60+
],
61+
extras_require=dict(
62+
test=[
63+
]),
64+
zip_safe=False,
65+
)

src/zopache/__init__.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# this is a namespace package
2+
try:
3+
import pkg_resources
4+
pkg_resources.declare_namespace(__name__)
5+
except ImportError:
6+
import pkgutil
7+
__path__ = pkgutil.extend_path(__path__, __name__)

src/zopache/pythonscript/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Make a package.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#
2+
# This file is necessary to make this directory a package.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<configure
2+
xmlns="http://namespaces.zope.org/zope"
3+
xmlns:browser="http://namespaces.zope.org/browser"
4+
>
5+
6+
<browser:addMenuItem
7+
class="zopache.pythonscript.pythonscript.PythonScript"
8+
title="Python Script"
9+
description="A simple, content-based Python Script"
10+
permission="zope.ManageContent"
11+
view="zopache.pythonscript.PythonScript"
12+
/>
13+
14+
<browser:addform
15+
schema="zopache.pythonscript.interfaces.IPythonScript"
16+
label="Add a Python Script"
17+
content_factory="zopache.pythonscript.pythonscript.PythonScript"
18+
name="zopache.pythonscript.PythonScript"
19+
permission="zope.ManageContent"
20+
/>
21+
22+
<browser:page
23+
for="zopache.pythonscript.interfaces.IPythonScript"
24+
name="edit.html"
25+
class=".pythonscript.EditForm"
26+
permission="zope.ManageContent"
27+
menu="zmi_views" title="Edit"
28+
/>
29+
30+
<browser:icon
31+
name="zmi_icon"
32+
for="zopache.pythonscript.interfaces.IPythonScript"
33+
file="pyscript.gif"
34+
/>
35+
36+
</configure>
184 Bytes
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
##############################################################################
2+
#
3+
# Copyright (c) 2013 Christopher Lozinski ([email protected]).
4+
# All Rights Reserved.
5+
#
6+
# This software is subject to the provisions of the Zope Public License,
7+
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
8+
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
9+
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
10+
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
11+
# FOR A PARTICULAR PURPOSE.
12+
#
13+
##############################################################################
14+
"""Define view component for Page Templates eval results."""
15+
import zope.formlib.form
16+
import zopache.pythonscript.interfaces
17+
18+
class EditForm(zope.formlib.form.EditForm):
19+
"""Edit form for Page Templates."""
20+
21+
form_fields = zope.formlib.form.Fields(
22+
zopache.pythonscript.interfaces.IPythonScript,
23+
render_context=True)
24+
25+
#def setUpWidgets(self, ignore_request=False):
26+
# self.adapters = {}
27+
# data = {}
28+
# self.widgets = zope.formlib.form.setUpWidgets(
29+
# self.form_fields, self.prefix, self.context, self.request,
30+
# data=data, form=self, adapters=self.adapters,
31+
# ignore_request=ignore_request)
32+

0 commit comments

Comments
 (0)