[CMF-checkins] CVS: CMF/CMFDefault/Extensions - Upgrade.py:1.3 migrate_ptk.py:1.2 update_discussion.py:1.2

Yvo Schubbe cvs-admin at zope.org
Mon Dec 1 08:56:14 EST 2003


Update of /cvs-repository/CMF/CMFDefault/Extensions
In directory cvs.zope.org:/tmp/cvs-serv16302/CMFDefault/Extensions

Modified Files:
	Upgrade.py migrate_ptk.py update_discussion.py 
Log Message:
some code modernization:
- death to string module
- death to apply
- import and whitespace cleanup


=== CMF/CMFDefault/Extensions/Upgrade.py 1.2 => 1.3 ===
--- CMF/CMFDefault/Extensions/Upgrade.py:1.2	Thu Jan 10 11:26:23 2002
+++ CMF/CMFDefault/Extensions/Upgrade.py	Mon Dec  1 08:55:44 2003
@@ -1,21 +1,21 @@
 ##############################################################################
 #
 # Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
-# 
+#
 # This software is subject to the provisions of the Zope Public License,
 # Version 2.0 (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
-# 
+#
 ##############################################################################
 """
     Utility functions for upgrading CMFDefault-based sites.
 """
 
 from Acquisition import aq_inner
-import string
+
 
 def upgrade_decor_skins( self ):
     """
@@ -38,10 +38,10 @@
         try:
 
             skins_tool._delObject( deleted )
-        
+
         except AttributeError:
             pass
-        
+
         else:
             log.append( 'Deleted CMFDecor skin directory: %s' % deleted )
 
@@ -56,4 +56,4 @@
             log.append( 'Updated CMFDecor skin directory to CMFDefault: %s'
                       % moved )
 
-    return string.join( log, '\n' )
+    return '\n'.join(log)


=== CMF/CMFDefault/Extensions/migrate_ptk.py 1.1 => 1.2 ===
--- CMF/CMFDefault/Extensions/migrate_ptk.py:1.1	Mon Jun 11 15:22:13 2001
+++ CMF/CMFDefault/Extensions/migrate_ptk.py	Mon Dec  1 08:55:44 2003
@@ -1,8 +1,5 @@
-
-
 from Acquisition import aq_base, aq_inner, aq_parent
-from ZODB.PersistentMapping import PersistentMapping
-from string import join
+from Globals import PersistentMapping
 import sys
 
 
@@ -28,7 +25,7 @@
         self.skipped = []
 
     def migrateObjectManager(self, src_folder, dst_folder, place=()):
-        self.visited_folders.append(join(place, '/'))
+        self.visited_folders.append( '/'.join(place) )
         for id, s_ob in src_folder.objectItems():
             d_ob = getattr(dst_folder, id, None)
             to_store = self.migrateObject(id, s_ob, d_ob, dst_folder,
@@ -44,7 +41,7 @@
                     to_store._owner = owner
 
     def migrateDiscussionContainer(self, src_folder, dst_folder, place=()):
-        self.visited_folders.append(join(place, '/'))
+        self.visited_folders.append( '/'.join(place) )
         dst_container = getattr(dst_folder, '_container', None)
         if dst_container is None:
             dst_container = dst_folder._container = PersistentMapping()
@@ -70,7 +67,7 @@
         descend_ok = 1
         base_ob = aq_base(s_ob)
         to_store = None
-        pathname = join(place, '/')
+        pathname = '/'.join(place)
         if self.skip.has_key(id):
             # Don't migrate objects by this name, but we can still
             # migrate subobjects.
@@ -118,7 +115,7 @@
         self._klass = to_class
         self._descend = descend
         self._show_dup = show_dup
-    
+
     def allowDescendChildren(self):
         return self._descend
 
@@ -148,7 +145,7 @@
             # Clear the children.
             newob._container = PersistentMapping()
         return newob
-        
+
 TupleType = type(())
 
 def setupDirectConversion(old_prod, new_prod, modname, classname,
@@ -190,7 +187,7 @@
     if owner:
         udb, uid = owner
         #res.append('Owner of %s is %s!%s' % (
-        #    join(ob.getPhysicalPath(), '/'), join(udb, '/'), uid,))
+        #    '/'.join( ob.getPhysicalPath() ), '/'.join(udb), uid,))
         root = ob.getPhysicalRoot()
         try:
             db = root.unrestrictedTraverse(udb, None)
@@ -222,15 +219,15 @@
             if udb is not None:
                 ob._owner = udb, uid
                 res.append('Changed ownership of %s from %s!%s to %s!%s' %
-                           (join(ob.getPhysicalPath(), '/'),
-                            join(old_udb, '/'), uid,
-                            join(udb, '/'), uid,))
+                           ('/'.join( ob.getPhysicalPath() ),
+                            '/'.join(old_udb), uid,
+                            '/'.join(udb), uid,))
             else:
                 res.append('Could not fix the ownership of %s, '
                            'which is set to %s!%s' %
-                           (join(ob.getPhysicalPath(), '/'),
-                            join(old_udb, '/'), uid,))
-                
+                           ('/'.join( ob.getPhysicalPath() ),
+                            '/'.join(old_udb), uid,))
+
     if cleanup_children:
         if hasattr(ob, 'objectValues'):
             for subob in ob.objectValues():
@@ -238,7 +235,7 @@
 
     # Deactivate object if possible.
     if changed is None: ob._p_deactivate()
-    
+
     return res
 
 def _copyUsers(src_folder, dst_folder):
@@ -287,11 +284,11 @@
         <p>Converted content:</p><pre>%s</pre>
         <p>Fixed up ownership:</p><pre>%s</pre>
         </body></html>
-        ''' % (join(m.warnings, '</li>\n<li>'),
-               join(m.visited_folders, '</li>\n<li>'),
-               join(m.skipped, '</li>\n<li>'),
-               join(m.copied, '\n'),
-               join(ownership_res, '\n'),
+        ''' % ('</li>\n<li>'.join(m.warnings),
+               '</li>\n<li>'.join(m.visited_folders),
+               '</li>\n<li>'.join(m.skipped),
+               '\n'.join(m.copied),
+               '\n'.join(ownership_res),
                )
 
 migrate_ptk = migrate
@@ -338,7 +335,7 @@
     content_product = 'PTKBase'
 else:
     content_product = 'PTKDemo'
-    
+
 
 setupDirectConversions(content_product, 'CMFDefault', demo_conversions,
                        ptk2cmf_conversions)


=== CMF/CMFDefault/Extensions/update_discussion.py 1.1 => 1.2 ===
--- CMF/CMFDefault/Extensions/update_discussion.py:1.1	Thu Jun 14 16:27:46 2001
+++ CMF/CMFDefault/Extensions/update_discussion.py	Mon Dec  1 08:55:44 2003
@@ -1,9 +1,7 @@
-import string
-
 from Products.CMFCore.TypesTool import FactoryTypeInformation
 from Products.CMFDefault import DiscussionItem
 
-def update_discussion( self, split=string.split ):
+def update_discussion(self):
     """
      1. Install (if it isn't there already) a type information
         object for DiscussionItems, so that they can get actions,
@@ -18,7 +16,7 @@
 
           - Items which are replies to sibling items have the sibling's
             ID as their 'in_reply_to'.
-        
+
         The representation we are converting from was:
 
           - Items which are replies to the containing content object
@@ -34,10 +32,8 @@
     types_tool = self.portal_types
     if not getattr( types_tool, 'Discussion Item', None ):
 
-        fti = apply( FactoryTypeInformation
-                   , ()
-                   , DiscussionItem.factory_type_information[0]
-                   )
+        fti = FactoryTypeInformation(
+                                **DiscussionItem.factory_type_information[0] )
         types_tool._setObject( 'Discussion Item', fti )
         a( 'Added type object for DiscussionItem' )
 
@@ -54,11 +50,11 @@
         talkback = object.aq_parent
         path = item.getPath()
         in_reply_to = object.in_reply_to
-        
+
         if in_reply_to is None: # we've been here already
             continue
 
-        irt_elements = split( in_reply_to, '/' )
+        irt_elements = in_reply_to.split('/')
 
         if len( irt_elements ) == 1:
             if talkback._container.get( irt_elements[0] ):
@@ -79,6 +75,6 @@
         object.reindexObject()
 
         a( path )
-    
-    return string.join( log, '\n' )
+
+    return '\n'.join(log)
 




More information about the CMF-checkins mailing list