Back to index

plone3  3.1.7
Classes | Functions | Variables
migrate_ptk Namespace Reference

Classes

class  Converter
class  Migrator
class  SimpleClassConverter

Functions

def setupDirectConversion
def setupDirectConversions
def _cleanupOwnership
def _copyUsers
def migrate

Variables

tuple TupleType = type(())
 migrate_ptk = migrate
dictionary ptk2cmf_conversions = {}
dictionary ptk2cmf_skip
tuple demo_conversions
int BEFORE_CONTENT_MOVE = 0
string content_product = 'PTKBase'

Function Documentation

def migrate_ptk._cleanupOwnership (   ob,
  res,
  cleanup_children 
) [private]
If the user name of the owner of the referenced object
is not found in its current user database but is found
in the local user database, this function changes the
ownership of the object to the local database.

Definition at line 176 of file migrate_ptk.py.

00176 
00177 def _cleanupOwnership(ob, res, cleanup_children):
00178     '''
00179     If the user name of the owner of the referenced object
00180     is not found in its current user database but is found
00181     in the local user database, this function changes the
00182     ownership of the object to the local database.
00183     '''
00184     try: changed = ob._p_changed
00185     except: changed = 0
00186 
00187     owner = getattr(ob, '_owner', None)
00188     if owner:
00189         udb, uid = owner
00190         #res.append('Owner of %s is %s!%s' % (
00191         #    '/'.join( ob.getPhysicalPath() ), '/'.join(udb), uid,))
00192         root = ob.getPhysicalRoot()
00193         try:
00194             db = root.unrestrictedTraverse(udb, None)
00195             user = db.getUserById(uid)
00196             if hasattr(ob, 'aq_inContextOf'):
00197                 ucontext = aq_parent(aq_inner(db))
00198                 if not ob.aq_inContextOf(ucontext):
00199                     # Not in the right context.
00200                     user = None
00201         except:
00202             user = None
00203         if user is None:
00204             # Try to change to a local database.
00205             p = ob
00206             old_udb = udb
00207             udb = None
00208             while p is not None:
00209                 if hasattr(p, 'acl_users'):
00210                     acl_users = p.acl_users
00211                     try:
00212                         user = acl_users.getUserById(uid)
00213                     except:
00214                         user = None
00215                     if user is not None:
00216                         # Found the right database.
00217                         udb = acl_users.getPhysicalPath()[1:]
00218                         break
00219                 p = aq_parent(aq_inner(p))
00220             if udb is not None:
00221                 ob._owner = udb, uid
00222                 res.append('Changed ownership of %s from %s!%s to %s!%s' %
00223                            ('/'.join( ob.getPhysicalPath() ),
00224                             '/'.join(old_udb), uid,
00225                             '/'.join(udb), uid,))
00226             else:
00227                 res.append('Could not fix the ownership of %s, '
00228                            'which is set to %s!%s' %
00229                            ('/'.join( ob.getPhysicalPath() ),
00230                             '/'.join(old_udb), uid,))
00231 
00232     if cleanup_children:
00233         if hasattr(ob, 'objectValues'):
00234             for subob in ob.objectValues():
00235                 _cleanupOwnership(subob, res, 1)
00236 
00237     # Deactivate object if possible.
00238     if changed is None: ob._p_deactivate()
00239 
00240     return res

Here is the caller graph for this function:

def migrate_ptk._copyUsers (   src_folder,
  dst_folder 
) [private]

Definition at line 241 of file migrate_ptk.py.

00241 
00242 def _copyUsers(src_folder, dst_folder):
00243     source = src_folder.acl_users
00244     target = dst_folder.acl_users
00245     for user in source.getUsers():
00246         target._addUser(name=user.name, password=user.__, confirm=user.__,
00247                         roles=user.roles, domains=user.domains, REQUEST=None)
00248 
00249 #
00250 # PTK to CMF Migration script.
00251 #
00252 

Here is the caller graph for this function:

def migrate_ptk.migrate (   self,
  src_path = '',
  dest_path = '',
  copy_users = 0,
  ownership_only = 0 
)

Definition at line 253 of file migrate_ptk.py.

00253 
00254 def migrate(self, src_path='', dest_path='', copy_users=0, ownership_only=0):
00255     if not src_path or not dest_path:
00256         return '''
00257         <html><body><form action="%s" method="POST">
00258         <h2>Migrate PTK content to CMF site</h2>
00259         <p>Path (not including server URL) to PTK instance (source):
00260         <input type="text" name="src_path"></p>
00261         <p>Path (not including server URL) to CMF site (destination):
00262         <input type="text" name="dest_path"></p>
00263         <p>Copy users:
00264         <input type="checkbox" name="copy_users" value="1"></p>
00265         <input type="submit" name="submit" value="Migrate">
00266         <input type="submit" name="ownership_only"
00267         value="Just clean up ownership">
00268         </form></body></html>
00269         ''' % self.REQUEST['URL']
00270     root = self.getPhysicalRoot()
00271     dst_folder = root.restrictedTraverse(dest_path)
00272     if not ownership_only:
00273         src_folder = root.restrictedTraverse(src_path)
00274         if copy_users:
00275             _copyUsers(src_folder, dst_folder)
00276         m = Migrator(ptk2cmf_conversions, ptk2cmf_skip)
00277         m.migrateObjectManager(src_folder, dst_folder)
00278     ownership_res = []
00279     _cleanupOwnership(dst_folder, ownership_res, 1)
00280     return '''
00281         <html><body><p>Finished migration.</p>
00282         <p>Warnings (if any):<ul><li>%s</li></ul></p>
00283         <p>Visited folders:<ul><li>%s</li></ul></p>
00284         <p>Skipped:<ul><li>%s</li></ul></p>
00285         <p>Converted content:</p><pre>%s</pre>
00286         <p>Fixed up ownership:</p><pre>%s</pre>
00287         </body></html>
00288         ''' % ('</li>\n<li>'.join(m.warnings),
00289                '</li>\n<li>'.join(m.visited_folders),
00290                '</li>\n<li>'.join(m.skipped),
00291                '\n'.join(m.copied),
00292                '\n'.join(ownership_res),
00293                )

Here is the call graph for this function:

def migrate_ptk.setupDirectConversion (   old_prod,
  new_prod,
  modname,
  classname,
  conversions,
  descend = 1,
  show_dup = 1 
)

Definition at line 152 of file migrate_ptk.py.

00152 
00153                           conversions, descend=1, show_dup=1):
00154     try:
00155         old_module = sys.modules['Products.' + old_prod + '.' + modname]
00156         new_module = sys.modules['Products.' + new_prod + '.' + modname]
00157         old_class = getattr(old_module, classname)
00158         new_class = getattr(new_module, classname)
00159         conversions[old_class] = SimpleClassConverter(new_class, descend,
00160                                                       show_dup)
00161     except:
00162         print 'Failed to set up conversion', old_prod, new_prod, modname, classname
00163         import traceback
00164         traceback.print_exc()
00165 

Here is the caller graph for this function:

def migrate_ptk.setupDirectConversions (   old_prod,
  new_prod,
  modnames,
  conversions 
)

Definition at line 166 of file migrate_ptk.py.

00166 
00167 def setupDirectConversions(old_prod, new_prod, modnames, conversions):
00168     for info in modnames:
00169         if type(info) is TupleType:
00170             modname, classname = info
00171         else:
00172             modname = classname = info
00173         setupDirectConversion(old_prod, new_prod, modname, classname,
00174                               conversions)
00175 

Here is the call graph for this function:


Variable Documentation

Definition at line 332 of file migrate_ptk.py.

string migrate_ptk.content_product = 'PTKBase'

Definition at line 335 of file migrate_ptk.py.

Initial value:
00001 (
00002     'Document',
00003     'NewsItem',
00004     'Image',
00005     'File',
00006     'Link',
00007     'Favorite',
00008     'DiscussionItem',
00009     ('DiscussionItem', 'DiscussionItemContainer'),
00010     )

Definition at line 320 of file migrate_ptk.py.

Definition at line 294 of file migrate_ptk.py.

Definition at line 301 of file migrate_ptk.py.

Initial value:
00001 {
00002     'portal_actions':0,
00003     'portal_catalog':0,
00004     'portal_discussion':0,
00005     'portal_memberdata':0,
00006     'portal_membership':0,
00007     'portal_properties':0,
00008     'portal_registration':0,
00009     'portal_skins':1,
00010     'portal_types':0,
00011     'portal_undo':0,
00012     'portal_url':0,
00013     'portal_workflow':0,
00014     'MailHost':0,
00015     'cookie_authentication':0,
00016     }

Definition at line 303 of file migrate_ptk.py.

tuple migrate_ptk.TupleType = type(())

Definition at line 149 of file migrate_ptk.py.