Skip to content
This repository has been archived by the owner on Jan 28, 2021. It is now read-only.

Commit

Permalink
Merge fanstatic branch
Browse files Browse the repository at this point in the history
  • Loading branch information
janjaapdriessen committed Jan 19, 2011
2 parents 63702db + c91d3d8 commit a7912cf
Show file tree
Hide file tree
Showing 16 changed files with 214 additions and 82 deletions.
40 changes: 39 additions & 1 deletion CHANGES.txt
Expand Up @@ -4,8 +4,46 @@ Changes
2.4 (unreleased)
----------------

- Nothing changed yet.
- z3c.testsetup has been removed in favor of manual registration of tests.
Tests have been moved to 'tests' subdirectory.
See tests.py for more information on how to register tests.

- The 'static' directory is no longer grokked and registered as a
DirectoryResource. It has been superseded by `fanstatic`_.

In order to update your current grok project to the most recent grokproject,
you need to register a fanstatic Library for the `static` directory.

Include the following code in ``resource.py``::

from fanstatic import Library
library = Library('$name_of_your_project', 'static')

in the setup.py of your project, add the following entry point::

'fanstatic.libraries': [
'$name_of_your_project = $name_of_your_project.resource:library',
]

Also add `zope.fanstatic` and `fanstatic` to `install_requires` in your
setup.py. If you are using z3c.autoinclude in your configure.zcml, the
registrations of zope.fanstatic will be picked up automatically. If you
do not use z3c.autoinclude, include zope.fanstatic in your configure.zcml.

- Split up zope.conf into zope.debug.conf and zope.deploy.conf, in order to
pick these up from the paster configs debug.ini and deploy.ini.

In debug/devmode, grok picks up changes in page templates and fanstatic
recalculates resources URLs.

In non-dev/deploy mode grok caches page templates and fanstatic caches
resource URLs.

The goal is to quickly see the difference between debug.ini and deploy.ini
without having to mess around in parts/etc.


.. _`fanstatic`: http://fanstatic.org

2.3 (2011-01-10)
----------------
Expand Down
45 changes: 34 additions & 11 deletions grokproject/template/buildout.cfg_tmpl
@@ -1,20 +1,22 @@
[buildout]
extends = ${version_info_url}
# XXX do not use groktoolkit trunk for release.
extends = http://svn.zope.org/repos/main/groktoolkit/trunk/grok.cfg
extends-cache = extends-cache
find-links = ${find_links_url}
include-site-packages = ${include_site_packages}
develop = .
unzip = true
parts =
app
daemon
debug_ini
deploy_ini
paster_ini_debug
paster_ini_deploy
i18n
mkdirs
site_zcml
test
zope_conf
zope_conf_debug
zope_conf_deploy
zpasswd
interactive_debugger
# For backward compatibility, telling buildout not to throw away
Expand All @@ -28,11 +30,22 @@ versions = versions
# unless you specify an eggs-directory option here.
${eggs_dir}
extensions += buildout.dumppickedversions
mr.developer
always-checkout = true
auto-checkout = grok
grokui.admin
zope.errorview

[sources]
grok = svn http://svn.zope.org/repos/main/grok/trunk
zope.errorview = svn http://svn.zope.org/repos/main/zope.errorview/trunk

[versions]
# Override versions here.
# This version pin can be removed after the next groktoolkit release.
collective.recipe.scriptgen = 0.2
grokcore.view = 2.3
grokui.base = 0.5
fanstatic = 0.10

[app]
recipe = z3c.recipe.scripts
Expand All @@ -50,14 +63,14 @@ arguments = serve $${buildout:parts-directory}/etc/deploy.ini
--daemon --pid-file=$${buildout:directory}/var/daemon.pid
--log-file=$${buildout:directory}/log/daemon.log

[debug_ini]
[paster_ini_debug]
recipe = collective.recipe.template
input = etc/debug.ini.in
output = $${buildout:parts-directory}/etc/debug.ini
host = 127.0.0.1
port = 8080

[deploy_ini]
[paster_ini_deploy]
recipe = collective.recipe.template
input = etc/deploy.ini.in
output = $${buildout:parts-directory}/etc/deploy.ini
Expand Down Expand Up @@ -91,14 +104,24 @@ eggs = ${egg}
defaults = ['-v']

[zope_conf]
recipe = collective.recipe.template
input = etc/zope.conf.in
output = $${buildout:parts-directory}/etc/zope.conf
filestorage = $${buildout:directory}/var/filestorage
blobstorage = $${buildout:directory}/var/blobstorage
logfiles = $${buildout:directory}/var/log
extra =
# 'extra' is copied verbatim. Use it for product config sections and so.
extra =

[zope_conf_debug]
<= zope_conf
recipe = collective.recipe.template
output = $${buildout:parts-directory}/etc/zope.debug.conf
devmode = on

[zope_conf_deploy]
<= zope_conf
recipe = collective.recipe.template
output = $${buildout:parts-directory}/etc/zope.deploy.conf
devmode = off

# This section is named so that the zpasswd utility is
# called `zpasswd`
Expand All @@ -115,7 +138,7 @@ recipe = z3c.recipe.scripts
eggs = ${egg}
entry-points =
interactive_debugger=grokcore.startup.startup:interactive_debug_prompt
arguments = zope_conf="$${zope_conf:output}"
arguments = zope_conf="$${zope_conf_debug:output}"

# The [data] and [log] parts are still in here to instruct buildout to not
# unintentionally throw away the parts/data and parts/log subdirectories
Expand Down
7 changes: 6 additions & 1 deletion grokproject/template/etc/debug.ini.in_tmpl
Expand Up @@ -7,14 +7,19 @@ host = $${:host}
port = $${:port}

[pipeline:main]
pipeline = accesslogging evalexception grok
pipeline = accesslogging fanstatic evalexception grok

[filter:accesslogging]
use = egg:Paste#translogger

[filter:evalexception]
use = egg:z3c.evalexception#ajax

[filter:fanstatic]
use = egg:fanstatic#fanstatic
versioning = true
recompute_hashes = true

[app:grok]
use = egg:grokcore.startup#debug
exempt-exceptions = zope.security.interfaces.IUnauthorized
Expand Down
11 changes: 9 additions & 2 deletions grokproject/template/etc/deploy.ini.in_tmpl
Expand Up @@ -7,18 +7,25 @@ host = $${:host}
port = $${:port}

[pipeline:main]
pipeline = accesslogging gzip grok
pipeline = accesslogging gzip fanstatic grok

[filter:accesslogging]
use = egg:Paste#translogger
setup_console_handler = false

[filter:fanstatic]
use = egg:fanstatic#fanstatic
bottom = true
versioning = true
minified = true
rollup = true
recompute_hashes = false

[filter:gzip]
use = egg:Paste#gzip

[app:grok]
use = egg:grokcore.startup
setup_console_handler = False

# Logging configuration

Expand Down
9 changes: 7 additions & 2 deletions grokproject/template/setup.py_tmpl
Expand Up @@ -21,8 +21,13 @@ ${long_description|nothing}""",
install_requires=['setuptools',
'grok',
'grokui.admin',
'z3c.testsetup',
'fanstatic',
'zope.fanstatic',
'grokcore.startup',${install_requires|nothing}
# Add extra requirements here
],
)
entry_points={
'fanstatic.libraries': [
'${project_lowercase} = ${project_lowercase}.resource:library',
]
})
5 changes: 4 additions & 1 deletion grokproject/template/src/+package+/app.py_tmpl
@@ -1,7 +1,10 @@
import grok

from ${package} import resource

class ${app_class_name}(grok.Application, grok.Container):
pass

class Index(grok.View):
pass # see app_templates/index.pt
def update(self):
resource.style.need()
Expand Up @@ -7,5 +7,6 @@
<p>Your Grok application is up and running.
Edit <code>${package}/app_templates/index.pt</code> to change
this page.</p>
<img tal:attributes="src static/evencaveman.jpg"/>
</body>
</html>
10 changes: 0 additions & 10 deletions grokproject/template/src/+package+/tests.py_tmpl

This file was deleted.

Empty file.
@@ -1,9 +1,6 @@
Do a functional doctest test on the app.
========================================

.. :doctest:
.. :layer: ${package}.tests.browser_layer

Let's first create an instance of ${app_class_name} at the top level:

>>> from ${package}.app import ${app_class_name}
Expand Down Expand Up @@ -32,15 +29,14 @@ Check some basic information about the page you visit:
>>> print browser.contents
<html>
<head>
<link rel="stylesheet" type="text/css" href="http://localhost/fanstatic/grokexample/style.css" />
<base href="http://localhost/app/@@index" />
<BLANKLINE>
</head>
<body>
<h1>Congratulations!</h1>
<BLANKLINE>
<p>Your Grok application is up and running.
Edit <code>${package}/app_templates/index.pt</code> to change
this page.</p>
<img src="http://localhost/fanstatic/${project_lowercase}/evencaveman.jpg" />
</body>
</html>
<BLANKLINE>
@@ -0,0 +1,31 @@
import unittest

from zope.component import queryMultiAdapter
from zope.publisher.browser import TestRequest

from zope.fanstatic.testing import ZopeFanstaticBrowserLayer

import ${package}.tests
from ${package}.app import ${app_class_name}

# In this file we create a unittest, a functional unittest.

class MyTestCase(unittest.TestCase):

def test_foo(self):
self.assertEqual(1, 1)

browser_layer = ZopeFanstaticBrowserLayer(${package}.tests)

class MyFunctionalTestCase(unittest.TestCase):

layer = browser_layer

def test_foo(self):
index = queryMultiAdapter((${app_class_name}(), TestRequest()), name='index')
self.assertNotEqual(index, None)

# There is no view called 'index2'
index2 = queryMultiAdapter((${app_class_name}(), TestRequest()), name='index2')
self.assertEqual(index2, None)

28 changes: 28 additions & 0 deletions grokproject/template/src/+package+/tests/tests.py_tmpl
@@ -0,0 +1,28 @@
# The tests in test_${project_lowercase}.py are picked up by zope.testrunner.

# When decorating a unittest.TestCase or doctest with a layer, the layer is
# used to group tests and execute setup and teardown of the grok environment
# for the test to run in.

import unittest
import doctest

from zope.fanstatic.testing import ZopeFanstaticBrowserLayer

import ${package}.tests

browser_layer = ZopeFanstaticBrowserLayer(${package}.tests)

def test_suite():
suite = unittest.TestSuite()

app_test = doctest.DocFileSuite('app.txt', # Add more doctest files here.
optionflags = (
doctest.ELLIPSIS +
doctest.NORMALIZE_WHITESPACE +
doctest.REPORT_NDIFF),
globs={'getRootFolder': browser_layer.getRootFolder})
app_test.layer = browser_layer

suite.addTest(app_test)
return suite
3 changes: 2 additions & 1 deletion grokproject/templates.py
Expand Up @@ -72,6 +72,7 @@ def check_vars(self, vars, cmd):
# Escape values that go in site.zcml.
vars[var_name] = xml.sax.saxutils.quoteattr(vars[var_name])
vars['app_class_name'] = vars['project'].capitalize()
vars['project_lowercase'] = vars['project'].lower()

# Handling the version.cfg file.
version_url = vars.get('version_url')
Expand Down Expand Up @@ -127,7 +128,7 @@ def download(self, url):
sys.exit(1)
except IOError, e:
# Some serious problem: no connect to server...
print "Error: cannot download required %s" % version_info_url
print "Error: cannot download required %s" % url
print "Server may be down. Please try again later."
sys.exit(1)
return contents
Expand Down
10 changes: 3 additions & 7 deletions grokproject/utils.py
@@ -1,14 +1,10 @@
from base64 import urlsafe_b64encode
from paste.script.templates import var
from random import randint
import subprocess
import codecs
import logging
import os
import pkg_resources
import shutil
import sys
import tempfile
from base64 import urlsafe_b64encode

from paste.script.templates import var

try:
from hashlib import sha1
Expand Down

0 comments on commit a7912cf

Please sign in to comment.