[Checkins] SVN: Zope3/trunk/src/zope/ Removed
zope.app.fssync.fsbundle since it is no longer needed. Fixed a typo.
Uwe Oestermeier
uwe_oestermeier at iwm-kmrc.de
Wed Feb 7 06:49:01 EST 2007
Log message for revision 72418:
Removed zope.app.fssync.fsbundle since it is no longer needed. Fixed a typo.
Changed:
U Zope3/trunk/src/zope/app/fssync/configure.zcml
D Zope3/trunk/src/zope/app/fssync/fsbundle.py
D Zope3/trunk/src/zope/app/fssync/main.py
U Zope3/trunk/src/zope/app/fssync/tests/test_committer.py
D Zope3/trunk/src/zope/app/fssync/tests/test_fsbundle.py
U Zope3/trunk/src/zope/fssync/command.py
U Zope3/trunk/src/zope/fssync/fsmerger.py
U Zope3/trunk/src/zope/fssync/metadata.py
U Zope3/trunk/src/zope/fssync/server/entryadapter.py
-=-
Modified: Zope3/trunk/src/zope/app/fssync/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/fssync/configure.zcml 2007-02-07 11:45:40 UTC (rev 72417)
+++ Zope3/trunk/src/zope/app/fssync/configure.zcml 2007-02-07 11:48:58 UTC (rev 72418)
@@ -25,7 +25,7 @@
/>
<fssync:adapter
- factory="zope.fssync.server.entryadapter.DefaultFileAdpater"
+ factory="zope.fssync.server.entryadapter.DefaultFileAdapter"
/>
Deleted: Zope3/trunk/src/zope/app/fssync/fsbundle.py
===================================================================
--- Zope3/trunk/src/zope/app/fssync/fsbundle.py 2007-02-07 11:45:40 UTC (rev 72417)
+++ Zope3/trunk/src/zope/app/fssync/fsbundle.py 2007-02-07 11:48:58 UTC (rev 72418)
@@ -1,149 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2003 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-"""High-level class to support bundle management on an fssync checkout.
-
-$Id$
-"""
-__docformat__ = 'restructuredtext'
-
-import os
-
-from zope.fssync.copier import ObjectCopier
-from zope.fssync.fssync import FSSync
-from zope.fssync.fsutil import Error
-from zope.fssync.metadata import Metadata
-
-BUNDLE_TYPE = "zope.app.services.bundle.Bundle"
-FOLDER_TYPE = "zope.app.component.site.SiteManagementFolder"
-
-
-class FSBundle(object):
-
- def __init__(self):
- self.metadata = Metadata()
- self.sync = FSSync(metadata=self.metadata)
-
- # bundle operations
-
- def create(self, path, type, factory, source=None):
- if os.path.exists(path):
- raise Error("%r already exists", path)
- dir, name = os.path.split(path)
- self.check_name(name)
- self.check_directory(dir)
- self.check_directory_known(dir)
- if source is not None:
- self.check_source(source, BUNDLE_TYPE, FOLDER_TYPE)
- if type is None and factory is None:
- srctype, srcfactory = self.metadata.gettypeinfo(source)
- if srctype == FOLDER_TYPE:
- factory = type = BUNDLE_TYPE
- else:
- # source is already a bundle; create the same type
- type = srctype
- factory = srcfactory
- elif factory is None and type is None:
- factory = type = BUNDLE_TYPE
- if source is None:
- self.sync.mkdir(path)
- else:
- copier = ObjectCopier(self.sync)
- copier.copy(source, path, children=True)
- self.settypeinfo(path, type, factory)
-
- def unpack(self, source, target):
- # source identifies the bundle to unpack
- # target identifies a location to unpack to
- if os.path.exists(target):
- target_dir = target
- # compute target name from prefix of source
- pass
- target = os.path.join(target_dir, target_name)
- else:
- target_dir, target_name = os.path.split(target)
- self.check_source(source, BUNDLE_TYPE)
- self.check_directory_known(target_dir)
- # ...
- self.settypeinfo(target, FOLDER_TYPE, FOLDER_TYPE)
-
- # helper methods
-
- def settypeinfo(self, path, type, factory):
- entry = self.metadata.getentry(path)
- assert entry.get("flag") == "added"
- # override any existing type and factory
- entry["factory"] = factory
- entry["type"] = type
- self.metadata.flush()
-
- def check_source(self, source, *allowed_types):
- # make sure the source is a site-management folder or a bundle
- if not os.path.exists(source):
- raise Error("%r does not exist", source)
- if not os.path.isdir(source):
- raise Error("%r must be a directory", source)
- self.check_directory_known(os.path.dirname(source))
- self.check_directory_known(source)
- type, factory = self.metadata.gettypeinfo(source)
- if type == BUNDLE_TYPE:
- pass
- elif type == FOLDER_TYPE:
- pass
- else:
- # don't know; play it safe
- raise Error(
- "%r doesn't appear to be a bundle or site-management folder",
- source)
-
- def check_directory(self, dir):
- if dir:
- if not os.path.exists(dir):
- raise Error("%r does not exist", dir)
- if not os.path.isdir(dir):
- raise Error("%r is not a directory", dir)
- # else: os.curdir assumed
-
- def check_directory_known(self, dir):
- dir = dir or os.curdir
- entry = self.metadata.getentry(dir)
- if not entry:
- raise Error("nothing known about", dir)
-
- def check_name(self, name):
- if name.count("-") != 1:
- raise Error("%r is not a legal bundle name", name)
- basename, version = name.split("-")
- self.check_version(version)
-
- def check_version(self, s):
- parseBundleVersion(s)
-
-
-def parseBundleVersion(s):
- parts = s.split(".")
- if len(parts) not in (3, 4):
- raise Error("%r is not a valid bundle version", s)
- try:
- n0 = int(parts[0])
- n1 = int(parts[1])
- n2 = int(parts[2])
- except ValueError:
- raise Error("%r is not a valid bundle version", s)
- try:
- p3 = int(parts[3])
- except IndexError:
- p3 = None
- except ValueError:
- p3 = parts[3]
- return (n0, n1, n2, p3)
Deleted: Zope3/trunk/src/zope/app/fssync/main.py
===================================================================
--- Zope3/trunk/src/zope/app/fssync/main.py 2007-02-07 11:45:40 UTC (rev 72417)
+++ Zope3/trunk/src/zope/app/fssync/main.py 2007-02-07 11:48:58 UTC (rev 72418)
@@ -1,107 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2003 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-"""Zope 3 bundle management utility.
-
-Command line syntax summary:
-
-%(program)s create BUNDLE SOURCE
-%(program)s unpack BUNDLE TARGET
-
-``%(program)s help'' prints the global help (this message)
-``%(program)s help command'' prints the local help for the command
-"""
-"""
-$Id$
-"""
-__docformat__ = 'restructuredtext'
-
-from zope.fssync.command import Command, Usage
-
-from zope.app.fssync.fsbundle import FSBundle
-
-
-def main():
- """Main program.
-
- The return value is the suggested `sys.exit()` status code:
- ``0`` or ``None`` for success
- ``2`` for command line syntax errors
- ``1`` or other for later errors
- """
- cmd = Command(usage=__doc__)
- for func, aliases, short, long in command_table:
- cmd.addCommand(func.__name__, func, short, long, aliases)
-
- return cmd.main()
-
-
-def create(opts, args):
- """%(program)s create BUNDLE SOURCE
-
- Create a bundle from a site management folder or another bundle.
- The bundle will only be created if the container is a site
- management folder. BUNDLE must be a valid bundle name.
-
- The contents of SOURCE are copied into the newly created bundle,
- and are scheduled for addition to the database. The new bundle
- can be manipulated using ``zsync add`` and ``zsync revert`` (and just
- editing the contents) as needed before committing it to the
- database.
- """
- factory = None
- type = None
- for opt, arg in opts:
- if opt in ("-f", "--factory"):
- if factory:
- raise Usage("-f/--factory can only be given once")
- factory = arg
- elif opt in ("-t", "--type"):
- if type:
- raise Usage("-t/--type can only be given once")
- type = arg
- source = None
- if len(args) == 1:
- path = args[0]
- elif len(args) == 2:
- path, source = args
- else:
- raise Usage("create requires exactly one path")
- fs = FSBundle()
- fs.create(path, type, factory, source)
-
-
-def unpack(opts, args):
- """%(program)s unpack bundle [dest]
-
-
- """
- if len(args) < 1:
- raise Usage("unpack requires a bundle")
- if len(args) > 2:
- raise Usage("unpack allows at most two args")
- source = args[0]
- if len(args) == 1:
- target = os.curdir
- else:
- target = args[1]
- fs = FSBundle()
- fs.unpack(source, target)
-
-
-command_table = [
- # name is taken from the function name
- # function, aliases, short opts, long opts
- (create, "", "f:t:", "factory= type="),
- (unpack, "", "", ""),
- ]
Modified: Zope3/trunk/src/zope/app/fssync/tests/test_committer.py
===================================================================
--- Zope3/trunk/src/zope/app/fssync/tests/test_committer.py 2007-02-07 11:45:40 UTC (rev 72417)
+++ Zope3/trunk/src/zope/app/fssync/tests/test_committer.py 2007-02-07 11:48:58 UTC (rev 72418)
@@ -30,7 +30,7 @@
from zope.filerepresentation.interfaces import IDirectoryFactory
from zope.fssync import fsutil
-from zope.fssync.server.entryadapter import DefaultFileAdpater
+from zope.fssync.server.entryadapter import DefaultFileAdapter
from zope.fssync.tests.mockmetadata import MockMetadata
from zope.fssync.tests.tempfiles import TempFiles
from zope.fssync.server.entryadapter import DirectoryAdapter
@@ -95,7 +95,7 @@
zope.interface.implements(IContainmentRoot)
-class DictAdapter(DefaultFileAdpater):
+class DictAdapter(DefaultFileAdapter):
def setBody(self, body):
old = self.context
@@ -119,7 +119,7 @@
# Set up FSRegistryUtility
zope.component.provideUtility(fsRegistry)
- provideSynchronizer(None, DefaultFileAdpater)
+ provideSynchronizer(None, DefaultFileAdapter)
# Set up temporary name administration
TempFiles.setUp(self)
@@ -168,7 +168,7 @@
def test_getSerializer(self):
obj = Sample()
adapter = syncer.getSerializer(obj)
- self.assertEqual(adapter.__class__, DefaultFileAdpater)
+ self.assertEqual(adapter.__class__, DefaultFileAdapter)
class TestCommitterModule(TestBase):
Deleted: Zope3/trunk/src/zope/app/fssync/tests/test_fsbundle.py
===================================================================
--- Zope3/trunk/src/zope/app/fssync/tests/test_fsbundle.py 2007-02-07 11:45:40 UTC (rev 72417)
+++ Zope3/trunk/src/zope/app/fssync/tests/test_fsbundle.py 2007-02-07 11:48:58 UTC (rev 72418)
@@ -1,185 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2003 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-"""Tests of the filesystem side of the bundle management code.
-
-$Id$
-"""
-
-import os
-import shutil
-import sys
-import unittest
-
-from cStringIO import StringIO
-
-from zope.fssync.fsutil import Error
-from zope.app.fssync.fsbundle import FSBundle, parseBundleVersion
-
-
-try:
- from tempfile import mkdtemp
-except ImportError:
- # Define a (limited) version of mkdtemp() for compatibility:
- import tempfile
- def mkdtemp(suffix=""):
- fn = tempfile.mktemp(suffix)
- fn = os.path.realpath(fn)
- os.mkdir(fn, 0700)
- return fn
-
-
-class FSBundleTestCase(unittest.TestCase):
-
- def setUp(self):
- self.fsbundle = FSBundle()
- self.metadata = self.fsbundle.metadata
- self.sync = self.fsbundle.sync
- self.tmpdir = mkdtemp("-fssync")
-
- def tearDown(self):
- shutil.rmtree(self.tmpdir)
-
- # helper functions
-
- def create_site(self):
- for dirparts in [("@@Zope",),
- ("++etc++site",),
- ("++etc++site", "site-folder"),
- ]:
- dn = os.path.join(self.tmpdir, *dirparts)
- os.mkdir(dn)
- self.etcdir = os.path.join(self.tmpdir, "++etc++site")
- self.write_text(
- "http://gandalf@localhost:8080/++etc++site\n",
- "@@Zope", "Root")
- self.add_metadata(
- self.etcdir,
- path="/++etc++site",
- type="zope.app.component.site.LocalSiteManager",
- factory="zope.app.component.site.LocalSiteManager")
- self.add_metadata(
- os.path.join(self.etcdir, "site-folder"),
- path="/++etc++site/site-folder",
- type="zope.app.component.site.SiteManagementFolder",
- factory="zope.app.component.site.SiteManagementFolder")
- self.metadata.flush()
-
- def add_metadata(self, name, **kw):
- d = self.metadata.getentry(name)
- d.update(kw)
-
- def write_text(self, text, *nameparts):
- fn = os.path.join(self.tmpdir, *nameparts)
- f = open(fn, "w")
- try:
- f.write(text)
- finally:
- f.close()
-
- def quiet_call(self, func, *args, **kw):
- """Call a function, dropping stdout to avoid console spewage."""
- sio = StringIO()
- old_stdout = sys.stdout
- try:
- sys.stdout = sio
- return func(*args, **kw)
- finally:
- sys.stdout = old_stdout
-
- def make_bundle(self, type=None, factory=None):
- source = os.path.join(self.etcdir, "site-folder")
- target = os.path.join(self.etcdir, "bundle-1.0.0")
- self.quiet_call(self.fsbundle.create, target, type, factory, source)
- return source, target
-
- # tests
-
- def test_simple_create(self):
- self.create_site()
- source, target = self.make_bundle()
- # Now poke at the new bundle and make sure we got everything
- # right:
- sm = self.metadata.getentry(source)
- tm = self.metadata.getentry(target)
- self.assertEqual(tm["path"], "/++etc++site/bundle-1.0.0")
- bundle_type = tm["type"]
- bundle_factory = tm["factory"]
- self.assert_(bundle_type != sm["type"])
- self.assert_(bundle_factory != sm["factory"])
- self.assertEqual(self.metadata.getnames(target), [])
- # Make sure a second call won't clobber the existing bundle:
- # add content to original so we can check that it didn't get copied:
- self.write_text("# Dummy Python module.\n"
- "1/0\n",
- "++etc++site", "site-folder", "dummy.py")
- self.add_metadata(os.path.join(self.etcdir, "site-folder", "dummy.py"),
- path="/++etc++site/default/sample",
- type="zope.app.module.manager.ModuleManager",
- factory="zope.app.module.manager.ModuleManager")
- self.metadata.flush()
- self.assertRaises(Error, self.fsbundle.create,
- target, "foo", "bar", source)
- tm = self.metadata.getentry(target)
- self.assert_(bundle_type == tm["type"])
- self.assert_(bundle_factory == tm["factory"])
- self.assertEqual(self.metadata.getnames(target), [])
- self.assert_(not os.path.exists(os.path.join(
- self.etcdir, "bundle-1.0.0", "dummy.py")))
-
- def test_create_with_factory(self):
- self.create_site()
- source, target = self.make_bundle(factory="foo")
- sm = self.metadata.getentry(source)
- tm = self.metadata.getentry(target)
- self.assert_(tm["type"] != sm["type"])
- self.assertEqual(tm["factory"], "foo")
-
- def test_create_with_type(self):
- self.create_site()
- source, target = self.make_bundle(type="bar")
- sm = self.metadata.getentry(source)
- tm = self.metadata.getentry(target)
- self.assertEqual(tm["type"], "bar")
- self.assert_(tm["factory"] != sm["factory"])
-
- def test_create_with_type_and_factory(self):
- self.create_site()
- source, target = self.make_bundle(type="bar", factory="foo")
- tm = self.metadata.getentry(target)
- self.assertEqual(tm["factory"], "foo")
- self.assertEqual(tm["type"], "bar")
-
-
-class VersionParserTestCase(unittest.TestCase):
- """Tests of the parse_version() helper function."""
-
- # We use a separate class for this since there's no need for the
- # setUp() done by the FSBundle test class.
-
- def test_parse_version(self):
- self.assertEqual(parseBundleVersion("1.0.0"), (1, 0, 0, None))
- self.assertEqual(parseBundleVersion("2.3.4"), (2, 3, 4, None))
- self.assertEqual(parseBundleVersion("1.0.0.1"), (1, 0, 0, 1))
- self.assertEqual(parseBundleVersion("1.0.0.a1"), (1, 0, 0, "a1"))
- self.assertEqual(parseBundleVersion("1.0.0.a"), (1, 0, 0, "a"))
- # illegal bundle version numbers:
- for s in ("42", "42.43", "1.0.a2", "1.0.0a1", "0.0.0.0.0",
- "a.1.2", "b", "1.c.0", "1.2.3.a4.5"):
- self.assertRaises(Error, parseBundleVersion, s)
-
-
-def test_suite():
- suite = unittest.makeSuite(FSBundleTestCase)
- suite.addTest(unittest.makeSuite(VersionParserTestCase))
- return suite
Modified: Zope3/trunk/src/zope/fssync/command.py
===================================================================
--- Zope3/trunk/src/zope/fssync/command.py 2007-02-07 11:45:40 UTC (rev 72417)
+++ Zope3/trunk/src/zope/fssync/command.py 2007-02-07 11:48:58 UTC (rev 72418)
@@ -117,7 +117,11 @@
def usage(self, file, text):
text = str(text)
- print >>file, text % {"program": self.program}
+ try:
+ text = text % {"program": self.program}
+ except:
+ pass
+ print >>file, text
def help(self, opts, args):
"""%(program)s help [COMMAND ...]
Modified: Zope3/trunk/src/zope/fssync/fsmerger.py
===================================================================
--- Zope3/trunk/src/zope/fssync/fsmerger.py 2007-02-07 11:45:40 UTC (rev 72417)
+++ Zope3/trunk/src/zope/fssync/fsmerger.py 2007-02-07 11:48:58 UTC (rev 72418)
@@ -111,6 +111,9 @@
def merge_dirs(self, localdir, remotedir, flag=None, special=False):
"""Merge remote directory into local directory."""
+
+ #uo: How do we handle unicode filenames?
+
lentrynames = self.metadata.getnames(localdir)
rentrynames = self.metadata.getnames(remotedir)
lentry = self.metadata.getentry(localdir)
@@ -208,8 +211,19 @@
if fsutil.nczope in names:
del names[fsutil.nczope]
- ncnames = names.keys()
- ncnames.sort()
+ # TODO: We must find a better way to avoid
+ # the problem that unicode paths and str paths occur together
+ # in the names dict
+
+ for k, v in names.items():
+ if not isinstance(k, unicode):
+ del names[k]
+ k = unicode(k, encoding='utf-8')
+ if not isinstance(v, unicode):
+ v = unicode(v, encoding='utf-8')
+ names[k] = v
+
+ ncnames = sorted(names.keys())
for ncname in ncnames:
name = names[ncname]
self.merge(join(localdir, name), join(remotedir, name))
Modified: Zope3/trunk/src/zope/fssync/metadata.py
===================================================================
--- Zope3/trunk/src/zope/fssync/metadata.py 2007-02-07 11:45:40 UTC (rev 72417)
+++ Zope3/trunk/src/zope/fssync/metadata.py 2007-02-07 11:48:58 UTC (rev 72418)
@@ -178,27 +178,12 @@
def load_entries_path(path):
f = open(path, 'rb')
- ch = EntriesHandler()
try:
- try:
- parse(f, ch)
- except FoundXMLPickle:
- pass
- else:
- return ch.entries
+ return load_entries(f.read())
finally:
f.close()
- # found an XML pickle; load that instead
- from zope.xmlpickle import loads
- f = open(path, 'rb')
- try:
- return loads(f.read())
- finally:
- f.close()
-
-
class EntriesHandler(ContentHandler):
def __init__(self):
self.first = True
Modified: Zope3/trunk/src/zope/fssync/server/entryadapter.py
===================================================================
--- Zope3/trunk/src/zope/fssync/server/entryadapter.py 2007-02-07 11:45:40 UTC (rev 72417)
+++ Zope3/trunk/src/zope/fssync/server/entryadapter.py 2007-02-07 11:48:58 UTC (rev 72418)
@@ -18,12 +18,12 @@
from zope.fssync.server.interfaces import IObjectFile, IContentDirectory
from zope.interface import implements
-from zope.xmlpickle import dumps #toxml
+from zope.xmlpickle import toxml # dumps
# TODO: This is a bug; we shouldn't depend on these packages at all.
# Need to restructure.
from zope.proxy import removeAllProxies
-#from zope.app.fssync import fspickle
+from zope.app.fssync import fspickle
class AttrMapping(object):
"""Convenience object implementing a mapping on selected object attributes
@@ -65,7 +65,8 @@
"""Convenience Base class for ObjectEntry adapter implementations."""
def __init__(self, context):
- self.context = context
+ self.context = removeAllProxies(context)
+ # TODO: for now, remove all proxies.
def extra(self):
"See IObjectEntry"
@@ -82,24 +83,20 @@
class_ = self.context.__class__
return "%s.%s" % (class_.__module__, class_.__name__)
-class DefaultFileAdpater(ObjectEntryAdapter):
+class DefaultFileAdapter(ObjectEntryAdapter):
"""Default File-system representation for objects."""
implements(IObjectFile)
- def __init__(self, context):
- # TODO: for now, remove all proxies.
- ObjectEntryAdapter.__init__(self, removeAllProxies(context))
-
def getBody(self):
"See IObjectFile"
#uo: why was fspickle used here? To keep references to locatable objects?
- #s = fspickle.dumps(self.context)
- #return toxml(s)
+ s = fspickle.dumps(self.context)
+ return toxml(s)
#If we use zope.xmlpickle.dumps we always get the xml elements in a fixed order
- return dumps(self.context)
+ #return dumps(self.context)
def setBody(self, body):
"See IObjectFile"
More information about the Checkins
mailing list