Question

We have two zope servers running our company's internal site. One is the live site and one is the dev site. I'm working on writing a python script that moves everything from the dev server to the live server. Right now the process involves a bunch of steps that are done in the zope management interface. I need to make all that automatic so that running one script handles it all. One thing I need to do is export one folder from the live server so that I can reimport it back into the live site after the update. How can I do this from a python script?

We're using Zope 2.8 and python 2.3.4

Was it helpful?

Solution

You can try to use the functions manage_exportObject and manage_importObject located in the file $ZOPE_HOME/lib/python/OFS/ObjectManager.py

Let say we install two Zope 2.8 instances located at:

  • /tmp/instance/dev for the development server (port 8080)
  • /tmp/instance/prod for the production server (port 9090)

In the ZMI of the development server, I have created two folders /MyFolder1 and /MyFolder2 containing some page templates. The following Python script exports each folder in .zexp files, and imports them in the ZMI of the production instance:

#!/usr/bin/python
import urllib
import shutil

ids_to_transfer = ['MyFolder1', 'MyFolder2']

for id in ids_to_transfer:
    urllib.urlopen('http://admin:password_dev@localhost:8080/manage_exportObject?id=' + id)

    shutil.move('/tmp/instance/dev/var/' + id + '.zexp', '/tmp/instance/prod/import/' + id + '.zexp')

    urllib.urlopen('http://admin:password_prod@localhost:9090/manage_delObjects?ids=' + id)
    urllib.urlopen('http://admin:password_prod@localhost:9090/manage_importObject?file=' + id + '.zexp')

OTHER TIPS

To make this more general and allow copying folders not in the root directory I would do something like this:

#!/usr/bin/python
import urllib
import shutil

username_dev = 'admin'
username_prod = 'admin'
password_dev = 'password_dev'
password_prod = 'password_prod'
url_dev = 'localhost:8080'
url_prod = 'localhost:9090'

paths_and_ids_to_transfer = [('level1/level2/','MyFolder1'), ('level1/','MyFolder2')]

for path, id in ids_to_transfer:
    urllib.urlopen('http://%s:%s@%s/%smanage_exportObject?id=%s' % (username_dev, password_dev, url_dev, path, id))

    shutil.move('/tmp/instance/dev/var/' + id + '.zexp', '/tmp/instance/prod/import/' + id + '.zexp')

    urllib.urlopen('http://%s:%s@%s/%smanage_delObjects?ids=%s' % (username_prod, password_prod, url_prod, path, id))
    urllib.urlopen('http://%s:%s@%s/%smanage_importObject?file=%s.zexp' % (username_prod, password_prod, url_prod, path, id))

If I had the rep I would add this to the other answer but alas... If someone wants to merge them, please go ahead.

If you really move everything you could probably just move the Data.fs instead. But otherwise the import/export above is a good way.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top