[Checkins] SVN: z3c.extfile/trunk/ some cleanups, fix dependencies,
added product config, see CHANGES.txt
Bernd Dorn
bernd.dorn at lovelysystems.com
Tue May 15 09:41:34 EDT 2007
Log message for revision 75760:
some cleanups, fix dependencies, added product config, see CHANGES.txt
Changed:
A z3c.extfile/trunk/CHANGES.txt
U z3c.extfile/trunk/buildout.cfg
U z3c.extfile/trunk/setup.cfg
U z3c.extfile/trunk/setup.py
U z3c.extfile/trunk/src/z3c/extfile/README.txt
U z3c.extfile/trunk/src/z3c/extfile/browser/widget.py
U z3c.extfile/trunk/src/z3c/extfile/file/tests.py
U z3c.extfile/trunk/src/z3c/extfile/filter.py
U z3c.extfile/trunk/src/z3c/extfile/schema.py
U z3c.extfile/trunk/src/z3c/extfile/tests.py
U z3c.extfile/trunk/src/z3c/extfile/utility.py
-=-
Added: z3c.extfile/trunk/CHANGES.txt
===================================================================
--- z3c.extfile/trunk/CHANGES.txt (rev 0)
+++ z3c.extfile/trunk/CHANGES.txt 2007-05-15 13:41:32 UTC (rev 75760)
@@ -0,0 +1,10 @@
+=======================
+Changes for z3c.extfile
+=======================
+
+After 1.0.dev
+=============
+
+- Use product config z3c.extfile:storagedir to set the storage directory
+
+- Registration of utility is now logged on INFO
Property changes on: z3c.extfile/trunk/CHANGES.txt
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: z3c.extfile/trunk/buildout.cfg
===================================================================
--- z3c.extfile/trunk/buildout.cfg 2007-05-15 06:39:14 UTC (rev 75759)
+++ z3c.extfile/trunk/buildout.cfg 2007-05-15 13:41:32 UTC (rev 75760)
@@ -2,8 +2,6 @@
develop = .
parts = test
-find-links = http://download.zope.org/distribution/
-
[test]
recipe = zc.recipe.testrunner
-eggs = z3c.extfile
\ No newline at end of file
+eggs = z3c.extfile [test]
\ No newline at end of file
Modified: z3c.extfile/trunk/setup.cfg
===================================================================
--- z3c.extfile/trunk/setup.cfg 2007-05-15 06:39:14 UTC (rev 75759)
+++ z3c.extfile/trunk/setup.cfg 2007-05-15 13:41:32 UTC (rev 75760)
@@ -1,3 +1,2 @@
[egg_info]
-tag_build = .dev
tag_svn_revision = 1
Modified: z3c.extfile/trunk/setup.py
===================================================================
--- z3c.extfile/trunk/setup.py 2007-05-15 06:39:14 UTC (rev 75759)
+++ z3c.extfile/trunk/setup.py 2007-05-15 13:41:32 UTC (rev 75760)
@@ -2,7 +2,7 @@
setup(
name = "z3c.extfile",
- version = "0.1",
+ version = "0.1.1dev",
author = "Zope Contributors",
author_email = "zope3-dev at zope.org",
description = "Large file handling for zope3",
@@ -18,16 +18,18 @@
package_dir = {'':'src'},
namespace_packages = ['z3c'],
zip_safe = False,
- install_requires = [
- 'setuptools',
- 'zope.component',
- 'zope.interface',
- 'zope.publisher',
- 'zope.schema',
- 'zope.thread',
- 'zope.app.wsgi',
- 'zope.app.file',
- 'ZODB3'],
- dependency_links = [
- 'http://download.zope.org/distribution/'],
+ extras_require={"test":['zope.testing',
+ ]},
+ install_requires = ['setuptools',
+ 'zope.app.appsetup',
+ 'zope.app.file',
+ 'zope.app.form',
+ 'zope.app.wsgi',
+ 'zope.contenttype',
+ 'zope.formlib',
+ 'zope.i18nmessageid',
+ 'zope.publisher',
+ 'zope.schema',
+ 'zope.security'
+ ],
)
Modified: z3c.extfile/trunk/src/z3c/extfile/README.txt
===================================================================
--- z3c.extfile/trunk/src/z3c/extfile/README.txt 2007-05-15 06:39:14 UTC (rev 75759)
+++ z3c.extfile/trunk/src/z3c/extfile/README.txt 2007-05-15 13:41:32 UTC (rev 75760)
@@ -18,6 +18,13 @@
os.environ['EXTFILE_STORAGEDIR'] = '/tmp/filestorage'
+Or define the storage directory in zope.conf like this (this overrides
+the environment variable)::
+
+ <product-config z3c.extfile>
+ storagedir /tmp/filestorage
+ </product-config>
+
This causes a IHashDir utilitiy to be registered upon zope startup.
see hashdir.txt, property.txt
@@ -52,10 +59,10 @@
[pipeline:Paste.Main]
pipeline = fs main
-
+
[app:main]
paste.app_factory = zope.paste.application:zope_publisher_app_factory
-
+
[filter:fs]
paste.filter_factory = z3c.extfile.filter:filter_factory
directory = /path/to/hashdir/storage
Modified: z3c.extfile/trunk/src/z3c/extfile/browser/widget.py
===================================================================
--- z3c.extfile/trunk/src/z3c/extfile/browser/widget.py 2007-05-15 06:39:14 UTC (rev 75759)
+++ z3c.extfile/trunk/src/z3c/extfile/browser/widget.py 2007-05-15 13:41:32 UTC (rev 75760)
@@ -1,5 +1,4 @@
from zope.app.form.browser.textwidgets import FileWidget
-from z3c.extfile import hashdir
class ExtBytesWidget(FileWidget):
Modified: z3c.extfile/trunk/src/z3c/extfile/file/tests.py
===================================================================
--- z3c.extfile/trunk/src/z3c/extfile/file/tests.py 2007-05-15 06:39:14 UTC (rev 75759)
+++ z3c.extfile/trunk/src/z3c/extfile/file/tests.py 2007-05-15 13:41:32 UTC (rev 75760)
@@ -1,8 +1,9 @@
import doctest
import unittest
-from zope.testing.doctestunit import DocFileSuite, DocTestSuite
+from zope.testing.doctestunit import DocFileSuite
+
def test_suite():
-
+
return unittest.TestSuite(
(
DocFileSuite('file.txt',
Modified: z3c.extfile/trunk/src/z3c/extfile/filter.py
===================================================================
--- z3c.extfile/trunk/src/z3c/extfile/filter.py 2007-05-15 06:39:14 UTC (rev 75759)
+++ z3c.extfile/trunk/src/z3c/extfile/filter.py 2007-05-15 13:41:32 UTC (rev 75760)
@@ -1,6 +1,4 @@
import os.path
-import stat
-import cgi
from z3c.extfile import processor, hashdir
from cStringIO import StringIO
import mimetypes
@@ -40,13 +38,13 @@
def __init__(self, app, hd):
self.hd = hd
self.app = app
-
+
def start_response(self, status, headers_out, exc_info=None):
"""Intercept the response start from the filtered app."""
self.status = status
self.headers_out = headers_out
self.exc_info = exc_info
-
+
def __call__(self, env, start_response):
"""Facilitate WSGI API by providing a callable hook."""
self.env = env
@@ -54,7 +52,7 @@
return self.__iter__()
def __iter__(self):
-
+
result = self.app(self.env, self.start_response)
result_iter = result.__iter__()
doHandle = False
@@ -71,7 +69,7 @@
headers_out = dict(
[(k.lower(),v) for k,v in self.headers_out]
)
-
+
body = "".join(result_iter)
if body.startswith('z3c.extfile.digest:'):
digest = body[19:]
@@ -90,7 +88,7 @@
if digest is not None:
try:
size = self.hd.getSize(digest)
- headers_out['content-length'] = size
+ headers_out['content-length'] = size
f = self.hd.open(digest)
fw = self.env.get('wsgi.file_wrapper')
iter_out = fw(f, BLOCK_SIZE)
@@ -103,8 +101,8 @@
headers_out = headers_out.items()
self.real_start(self.status, headers_out, exc_info=self.exc_info)
return iter_out
-
-
+
+
def filter_factory(global_conf, **local_conf):
def filter(app):
return FSFilter(app, **local_conf)
Modified: z3c.extfile/trunk/src/z3c/extfile/schema.py
===================================================================
--- z3c.extfile/trunk/src/z3c/extfile/schema.py 2007-05-15 06:39:14 UTC (rev 75759)
+++ z3c.extfile/trunk/src/z3c/extfile/schema.py 2007-05-15 13:41:32 UTC (rev 75760)
@@ -1,6 +1,5 @@
from zope import schema, interface
from z3c.extfile import interfaces
-from zope.schema.interfaces import InvalidValue
class ExtBytesField(schema.Bytes):
@@ -9,4 +8,4 @@
def validate(self, value):
"""test if we have a file"""
return hasattr(value,'seek') and hasattr(value,'read')
-
+
Modified: z3c.extfile/trunk/src/z3c/extfile/tests.py
===================================================================
--- z3c.extfile/trunk/src/z3c/extfile/tests.py 2007-05-15 06:39:14 UTC (rev 75759)
+++ z3c.extfile/trunk/src/z3c/extfile/tests.py 2007-05-15 13:41:32 UTC (rev 75760)
@@ -20,6 +20,9 @@
DocFileSuite('browser/widget.txt',
optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS,
),
+ DocTestSuite('z3c.extfile.utility',
+ optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS,
+ ),
))
if __name__ == '__main__':
Modified: z3c.extfile/trunk/src/z3c/extfile/utility.py
===================================================================
--- z3c.extfile/trunk/src/z3c/extfile/utility.py 2007-05-15 06:39:14 UTC (rev 75759)
+++ z3c.extfile/trunk/src/z3c/extfile/utility.py 2007-05-15 13:41:32 UTC (rev 75760)
@@ -2,16 +2,66 @@
import os
import hashdir
import interfaces
+from zope.app.appsetup.product import getProductConfiguration
+import logging
+log = logging.getLogger('z3c.extfile')
+def getPath():
+
+ """returns the path of the storage directory
+
+ If not path is defined None is returned
+
+ >>> getPath() is None
+ True
+
+ If we have a evnironment variable it is returned. If the path does
+ not exist a ValueError is raised.
+
+ >>> os.environ['EXTFILE_STORAGEDIR'] = '/this/path/does/not/exist'
+ >>> getPath()
+ Traceback (most recent call last):
+ ...
+ ValueError: Extfile storage path does not exist:
+ '/this/path/does/not/exist'
+ >>> os.environ['EXTFILE_STORAGEDIR'] = os.path.dirname(__file__)
+ >>> getPath()
+ '.../z3c/extfile'
+
+ If we have a product configuration this is used.
+
+ >>> class Config(object):
+ ... mapping = {}
+ ... def getSectionName(self):
+ ... return 'z3c.extfile'
+ >>> config = Config()
+ >>> path = os.path.join(os.path.dirname(__file__), 'browser')
+ >>> config.mapping['storagedir'] = path
+ >>> from zope.app.appsetup.product import setProductConfigurations
+ >>> setProductConfigurations([config])
+ >>> getPath() is path
+ True
+ """
+
+ path = None
+ config = getProductConfiguration('z3c.extfile')
+ if config is not None:
+ path = config.get('storagedir')
+ path = path or os.environ.get('EXTFILE_STORAGEDIR')
+ if path is None:
+ return
+ if not os.path.exists(path):
+ raise ValueError, "Extfile storage path does not exist: %r" % path
+ return path
+
def bootStrapSubscriber(event):
"""create an IHashDir util if the EXTFILE_STORAGEDIR environment
- variable is present"""
-
- if os.environ.has_key('EXTFILE_STORAGEDIR'):
- path = os.environ.get('EXTFILE_STORAGEDIR')
- if not os.path.exists(path):
- raise ValueError, path
+ variable is present
+ """
+ path = getPath()
+ if path is not None:
hd = hashdir.HashDir(path)
component.provideUtility(hd, provides=interfaces.IHashDir)
+ log.info('Registered IHashDir utility with storagedir: %r' % path)
More information about the Checkins
mailing list