[Checkins] SVN: z3c.offlinepack/trunk/ Pack ZODB databases without running Zope or ZEO

Ross Patterson me at rpatterson.net
Tue Sep 25 22:28:16 EDT 2007


Log message for revision 80081:
  Pack ZODB databases without running Zope or ZEO
  

Changed:
  A   z3c.offlinepack/trunk/.cvsignore
  A   z3c.offlinepack/trunk/EXTERNALS.txt
  A   z3c.offlinepack/trunk/README.txt
  A   z3c.offlinepack/trunk/buildout.cfg
  A   z3c.offlinepack/trunk/paster.cfg
  A   z3c.offlinepack/trunk/setup.cfg
  A   z3c.offlinepack/trunk/setup.py
  A   z3c.offlinepack/trunk/z3c/
  A   z3c.offlinepack/trunk/z3c/__init__.py
  A   z3c.offlinepack/trunk/z3c/offlinepack/
  A   z3c.offlinepack/trunk/z3c/offlinepack/README.txt
  A   z3c.offlinepack/trunk/z3c/offlinepack/__init__.py
  A   z3c.offlinepack/trunk/z3c/offlinepack/tests.py

-=-
Added: z3c.offlinepack/trunk/.cvsignore
===================================================================
--- z3c.offlinepack/trunk/.cvsignore	                        (rev 0)
+++ z3c.offlinepack/trunk/.cvsignore	2007-09-26 02:28:16 UTC (rev 80081)
@@ -0,0 +1,4 @@
+.installed.cfg
+bin
+develop-eggs
+parts

Added: z3c.offlinepack/trunk/EXTERNALS.txt
===================================================================
--- z3c.offlinepack/trunk/EXTERNALS.txt	                        (rev 0)
+++ z3c.offlinepack/trunk/EXTERNALS.txt	2007-09-26 02:28:16 UTC (rev 80081)
@@ -0,0 +1,4 @@
+#
+# applied by: svn propset svn:externals -F ./EXTERNALS.txt .
+#
+bootstrap svn://svn.zope.org/repos/main/zc.buildout/trunk/bootstrap

Added: z3c.offlinepack/trunk/README.txt
===================================================================
--- z3c.offlinepack/trunk/README.txt	                        (rev 0)
+++ z3c.offlinepack/trunk/README.txt	2007-09-26 02:28:16 UTC (rev 80081)
@@ -0,0 +1,40 @@
+;-*- rST -*-
+
+==================
+Pack ZODBs Offline
+==================
+
+Pack a ZODB storage without running any part of the Zope application
+server.  Only an appropriate version of Zope for the ZODB storage is
+required.  Use on a copy of a ZODB storage.  Do not run on a ZODB
+storage currently in use.
+
+Install the distribution:
+
+  $ python setup.py install
+
+Then use the offlinepack script to pack a copy of your ZODB:
+
+  $ offlinepack /path/to/Data-copy.fs
+
+zc.buildout
+-----------
+
+A buildout.cfg is included that will install the offlinepack script
+to the buildout.  The buildout makes it possible to quickly use the
+offlinepack script without modifying your python installation.
+
+  $ python bootsrtap/bootsrtap.py -v
+  $ bin/buildout -v
+  $ bin/offlinepack /path/to/Data-copy.fs
+
+The buildout.cfg file can also be modified to use a specific version
+of ZODB3.  This is uesful if you need to use offlinepack without
+migrating the ZODB to a newer version of ZODB3.  Add the version
+specifier to the offlinepack section of buildout.cfg.  For example, to
+use offlinepack with Zope 2.9, use the following offlinepack section.
+
+    [offlinepack]
+    recipe = zc.recipe.egg:scripts
+    eggs = z3c.offlinepack
+        ZODB3<3.7-dev

Added: z3c.offlinepack/trunk/buildout.cfg
===================================================================
--- z3c.offlinepack/trunk/buildout.cfg	                        (rev 0)
+++ z3c.offlinepack/trunk/buildout.cfg	2007-09-26 02:28:16 UTC (rev 80081)
@@ -0,0 +1,12 @@
+[buildout]
+develop = .
+parts = offlinepack test
+
+[offlinepack]
+recipe = zc.recipe.egg:scripts
+eggs = z3c.offlinepack
+    ZODB3<3.7-dev
+
+[test]
+recipe = zc.recipe.testrunner
+eggs = z3c.offlinepack [test]

Added: z3c.offlinepack/trunk/paster.cfg
===================================================================
--- z3c.offlinepack/trunk/paster.cfg	                        (rev 0)
+++ z3c.offlinepack/trunk/paster.cfg	2007-09-26 02:28:16 UTC (rev 80081)
@@ -0,0 +1,15 @@
+[pastescript]
+namespace_package = z3c
+description = Pack ZODB databases without running Zope or ZEO
+author = Ross Patterson
+author_email = me at rpatterson.net
+license_name = GPL
+url = http://svn.zope.org/z3c.offlinepack
+version = 0.1
+plus = +
+zip_safe = True
+keywords = 
+egg = z3c.offlinepack
+long_description = 
+dot = .
+

Added: z3c.offlinepack/trunk/setup.cfg
===================================================================
--- z3c.offlinepack/trunk/setup.cfg	                        (rev 0)
+++ z3c.offlinepack/trunk/setup.cfg	2007-09-26 02:28:16 UTC (rev 80081)
@@ -0,0 +1,3 @@
+[egg_info]
+tag_build = dev
+tag_svn_revision = true

Added: z3c.offlinepack/trunk/setup.py
===================================================================
--- z3c.offlinepack/trunk/setup.py	                        (rev 0)
+++ z3c.offlinepack/trunk/setup.py	2007-09-26 02:28:16 UTC (rev 80081)
@@ -0,0 +1,42 @@
+from setuptools import setup, find_packages
+import sys, os
+
+version = '0.1'
+
+setup(name='z3c.offlinepack',
+      version=version,
+      description="Pack ZODB databases without running Zope or ZEO",
+      long_description="""\
+Pack a ZODB storage without running any part of the Zope application
+server.  Only an appropriate version of Zope for the ZODB storage is
+required.  Use on a copy of a ZODB storage.  Do not run on a ZODB
+storage currently in use.""",
+      # Get more strings from http://www.python.org/pypi?%3Aaction=list_classifiers
+      classifiers=[
+        "Framework :: Plone",
+        "Framework :: Zope2",
+        "Framework :: Zope3",
+        "Programming Language :: Python",
+        "Topic :: Software Development :: Libraries :: Python Modules",
+        ],
+      keywords='',
+      author='Ross Patterson',
+      author_email='me at rpatterson.net',
+      url='http://svn.zope.org/z3c.offlinepack',
+      license='GPL',
+      packages=find_packages(exclude=['ez_setup']),
+      namespace_packages=['z3c'],
+      include_package_data=True,
+      zip_safe=True,
+      install_requires=[
+          'setuptools',
+          # -*- Extra requirements: -*-
+          'ZODB3', 'zope.dottedname'
+      ],
+      extras_require=dict(test=['zc.buildout', 'zc.recipe.egg']),
+      entry_points="""
+      # -*- Entry points: -*-
+      [console_scripts]
+      offlinepack = z3c.offlinepack:main
+      """,
+      )

Added: z3c.offlinepack/trunk/z3c/__init__.py
===================================================================
--- z3c.offlinepack/trunk/z3c/__init__.py	                        (rev 0)
+++ z3c.offlinepack/trunk/z3c/__init__.py	2007-09-26 02:28:16 UTC (rev 80081)
@@ -0,0 +1,6 @@
+# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
+try:
+    __import__('pkg_resources').declare_namespace(__name__)
+except ImportError:
+    from pkgutil import extend_path
+    __path__ = extend_path(__path__, __name__)

Added: z3c.offlinepack/trunk/z3c/offlinepack/README.txt
===================================================================
--- z3c.offlinepack/trunk/z3c/offlinepack/README.txt	                        (rev 0)
+++ z3c.offlinepack/trunk/z3c/offlinepack/README.txt	2007-09-26 02:28:16 UTC (rev 80081)
@@ -0,0 +1,33 @@
+;-*- Doctest -*-
+==================
+Pack ZODBs Offline
+==================
+
+Pack a ZODB storage without running any part of the Zope application
+server.  Only an appropriate version of Zope for the ZODB storage is
+required.  Use on a copy of a ZODB storage.  Do not run on a ZODB
+storage currently in use.
+
+Start with a FileStorage that has versions that would be removed on
+pack.
+
+    >>> import ZODB, ZODB.FileStorage, transaction
+    >>> db = ZODB.DB(ZODB.FileStorage.FileStorage(data_fs))
+    >>> conn = db.open()
+    >>> conn.root()['foo'] = 'foo'
+    >>> transaction.commit()
+    >>> conn.root()['foo'] = 'bar'
+    >>> transaction.commit()
+    >>> conn.close()
+    >>> db.close()
+
+The size after packing will be smaller than the size after packing.
+
+    >>> import os
+    >>> initial_size = os.path.getsize(data_fs)
+
+    >>> import z3c.offlinepack
+    >>> z3c.offlinepack.pack_paths([data_fs])
+
+    >>> os.path.getsize(data_fs) < initial_size
+    True

Added: z3c.offlinepack/trunk/z3c/offlinepack/__init__.py
===================================================================
--- z3c.offlinepack/trunk/z3c/offlinepack/__init__.py	                        (rev 0)
+++ z3c.offlinepack/trunk/z3c/offlinepack/__init__.py	2007-09-26 02:28:16 UTC (rev 80081)
@@ -0,0 +1,60 @@
+#!/usr/bin/python
+"""Pack a ZODB storage without running any part of the Zope application
+server.  Only an appropriate version of Zope for the ZODB storage is
+required.  Use on a copy of a ZODB storage.  Do not run on a ZODB
+storage currently in use."""
+
+usage="usage: %prog [options] PATH..."
+
+import sys, os, logging, time, optparse
+
+import zope.dottedname.resolve
+import ZODB.FileStorage, ZODB.serialize
+
+parser = optparse.OptionParser(usage=usage, description=__doc__,
+                               version='0.1')
+days = optparse.make_option(
+    '-d', '--days', type="int", default=0,
+    help=("remove revisions more than DAYS old "
+          "[default: %default]"))
+parser.add_option(days)
+
+def storage_callback(option, opt_str, value, parser, *args, **kwargs):
+         setattr(parser.values, option.dest,
+                 zope.dottedname.resolve.resolve(value))
+storage = optparse.make_option(
+    '-s', '--storage', metavar='DOTTED', type="string",
+    default=ZODB.FileStorage.FileStorage,
+    action='callback', callback=storage_callback,
+    help=("use the storage constructor at DOTTED "
+          "[default: ZODB.FileStorage.FileStorage]"))
+parser.add_option(storage)
+
+logger = logging.getLogger('fspack')
+
+def pack_paths(paths, days=days.default, storage=storage.default):
+    delta = days*86400
+    for path in paths:
+        pack(path, delta, constructor=storage)
+
+def pack(path, delta=days.default*86400, constructor=storage.default):
+    storage = constructor(path)
+    start = time.time()
+    storage.pack(start-delta, ZODB.serialize.referencesf)
+    storage.close()
+    logger.info('%s has been packed in %.3f seconds'
+                % (path, time.time()-start))
+
+def main(parser=parser):
+    logging.basicConfig(level=logging.INFO)
+
+    options, args = parser.parse_args()
+    if not args:
+        parser.error("at least one PATH is required")
+
+    pack_paths(paths=args, **options.__dict__)
+
+    logging.shutdown()
+
+if __name__ == '__main__':
+    main()

Added: z3c.offlinepack/trunk/z3c/offlinepack/tests.py
===================================================================
--- z3c.offlinepack/trunk/z3c/offlinepack/tests.py	                        (rev 0)
+++ z3c.offlinepack/trunk/z3c/offlinepack/tests.py	2007-09-26 02:28:16 UTC (rev 80081)
@@ -0,0 +1,19 @@
+import unittest, os, tempfile, shutil
+from zope.testing import doctest
+
+def setUp(test):
+    test.globs['temp_dir'] = temp_dir = tempfile.mkdtemp()
+    test.globs['data_fs'] = data_fs = os.path.join(
+        temp_dir, 'Data.fs')
+    
+def tearDown(test):
+    shutil.rmtree(test.globs['temp_dir'])
+
+def test_suite():
+    return doctest.DocFileSuite(
+        'README.txt',
+        setUp=setUp, tearDown=tearDown,
+        optionflags=doctest.REPORT_NDIFF)
+
+if __name__ == '__main__':
+    unittest.main(defaultTest='test_suite')



More information about the Checkins mailing list