quick search:
 

change skinpath after moving site

Submitted by: robert
Last Edited: 2004-10-14

Category: CMF

Average rating is: 5.0 out of 5 (2 ratings)

Description:
The path to a skin directory is "hardwired" into its directory view.
If you move the site to an other server say for developing reasons you have to manualy update all the dirpaths info.
This script does it for you
-------------
"2002/08/16 Updated, to be more general.


Source (Text):
## Script (Python) "setDirpath"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=
##title=
##
import string

#get possible skins
newDirs=container.manage_addProduct['CMFCore'].manage_listAvailableDirectories()

#we can not use os.sep so we must look ourselfs what
# the path separator is
if newDirs[0].find('/') > -1:
  newSep = '/'
else:
  newSep = '\\'



objs = context.objectItems('Filesystem Directory View')
for n,o in objs:
  found = 0
  path = o.getDirPath()
  if path.find('/') > -1:
    sep = '/'
  else:
    sep = '\\'
  #look for new path by comparing the last 2 elements
  dArr = string.split(path,sep)
  for i in range(len(newDirs)):
    # if we found the directory skip the rest
    if found:
      continue
    ndArr = string.split(newDirs[i],newSep)
    if string.lower(ndArr[-1]) != string.lower(dArr[-1]):
      continue
    if string.lower(ndArr[-2]) != string.lower(dArr[-2]):
      continue
    # if we land here, we found the real one
    found = 1
    o.manage_properties(dirpath = newDirs[i])
  if(found == 0):
    print path, ' not found'

print 'finished'
return printed

Comments:

Thanks! by mark - 2004-10-14
Thank you.  I was looking for this solution for a while.


Wonderful! by cleath - 2004-10-14
I tried and it works great!!
http://localhost:8080/cfu/portal_skins/setSkinDirPath

(run it on your portal_skins)


Excellent, thank you! by Norbert - 2006-02-03
I extended it a bit more. If you have multiple CMF sites, run the script below from your root directory.

import string

#get possible skins
newDirs=container.manage_addProduct['CMFCore'].manage_listAvailableDirectories()

#we can not use os.sep so we must look ourselfs what
# the path separator is
if newDirs[0].find('/') > -1:
  newSep = '/'
else:
  newSep = '\\'


portals= context.objectItems('CMF Site')
for portal,p in portals:
  print '--- ' + p.id + ' ---'

  objs = p.portal_skins.objectItems('Filesystem Directory View')
  for n,o in objs:
    found = 0
    path = o.getDirPath()
    if path.find('/') > -1:
      sep = '/'
    else:
      sep = '\\'
    #look for new path by comparing the last 2 elements
    dArr = string.split(path,sep)
    for i in range(len(newDirs)):
      # if we found the directory skip the rest
      if found:
        continue
      ndArr = string.split(newDirs[i],newSep)
      if string.lower(ndArr[-1]) != string.lower(dArr[-1]):
        continue
      if string.lower(ndArr[-2]) != string.lower(dArr[-2]):
        continue
      # if we land here, we found the real one
      found = 1
      o.manage_properties(dirpath = newDirs[i])
    if(found == 0):
      print path, ' not found'
    else:
      print o.id

  print''

print 'finished'
return printed
 
Please clarify... by benr - 2006-02-03
Norbert - could you please elaborate on 
"run the script below from your root directory". 

Is this create a new external method and test, 
add script and run from command line, or what?

(I'm a little new to this... ;o)

Thanks!

-Ben