Hi,

  I don't like the zmi (or any web interface) for this kind of operation, i 
prefer scripting them. Check the two attached files.

How to use it ?
push them on the server
cd path/tomyscripts
zopepy recatalog.py -c path/to/etc/zope.conf --recatalog --commit

zopepy is a python interpreter with all zope modules in its PYTHONPATH 
common.py is used in production on our servers
recatalog.py is a kind of template adapted to fit your needs (not tested, but 
should work) I m using this to perform migrations of datas (objects)

-- 
JeanMichel FRANCOIS
Makina Corpus

Le Thursday 09 October 2008 22:20:05 Laurence Rowe, vous avez écrit :

> This is only a timeout and nothing to worry about. Either connect
> directly to the zope instance to perform the recatalog or just leave it
> and wait. You can tell it's done when python is no longer using all your
> cpu.
>
> Laurence
>
> Ignacio Valdes wrote:
> > Hello all, Linux Medical News http://www.linuxmednews.com is a quite
> > large Squishdot based website. I am attempting to re-catalog all
> > postings which is a fairly lengthy process. When I try to do this, it
> > works for a period of time then gives this message:
> >
> > Proxy Error
> >
> > The proxy server received an invalid response from an upstream server.
> > The proxy server could not handle the request POST /.
> >
> > Reason: Error reading from remote server
> >
> > Apache/2.2.6 (Fedora) Server at linuxmednews.com Port 80
> >
> > What should I do?
> >
> > -- IV
> > _______________________________________________
> > Zope maillist  -  Zope@zope.org
> > http://mail.zope.org/mailman/listinfo/zope
> > **   No cross posts or HTML encoding!  **
> > (Related lists -
> >  http://mail.zope.org/mailman/listinfo/zope-announce
> >  http://mail.zope.org/mailman/listinfo/zope-dev )
>
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://mail.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists -
>  http://mail.zope.org/mailman/listinfo/zope-announce
>  http://mail.zope.org/mailman/listinfo/zope-dev )


#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright (C) 2008, Mathieu PASQUET <[EMAIL PROTECTED]> aka kiorky
# Copyright (C) 2008, Jeanmichel Francois <[EMAIL PROTECTED]> aka toutpt
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

import os
import sys
import logging

from Testing.makerequest import makerequest
import Zope2

def connect(zopeconf):
    """options is an options optparser object."""
    os.environ['ZOPE_COMPATIBLE_STARTUP'] = " "
    os.environ['ZOPE_CONFIG'] = zopeconf
    app = makerequest(Zope2.app())
    logger = logging.getLogger('20080624 migration')
    from AccessControl import getSecurityManager
    from AccessControl.SecurityManagement import newSecurityManager
    from AccessControl.SecurityManagement import setSecurityManager

    plone = app.anticancer.get('www.anticancer.fr')
    user = plone.acl_users.getUser('webmestre').__of__(plone.acl_users)
    newSecurityManager(app, plone.acl_users.getUser('webmestre'))
    import Products
    return plone, user

def initLogging():
    # logging to stdout
    logging.root.setLevel(logging.INFO)
    lformatter = logging.Formatter("%(asctime)s %(name)-1s %(levelname)-2s - %(message)s")
    lhandler = logging.StreamHandler(sys.stdout)
    lhandler.setFormatter(lformatter)
    logging.root.addHandler(lhandler)

#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright (C) 2008, Mathieu PASQUET <[EMAIL PROTECTED]> aka kiorky
# Copyright (C) 2008, Jeanmichel Francois <[EMAIL PROTECTED]> aka toutpt
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

import sys
import logging
import transaction
import pdb

from Acquisition import aq_base
from optparse import OptionParser
from DateTime import DateTime
from common import connect, initLogging

initLogging()

logger = logging.getLogger("migration")
parser = OptionParser()
parser.add_option("-c",
                  action="store", dest="zopeconf", default="parts/guerir2-1/etc/zope.conf",
                  help="Zope.conf path")
parser.add_option("--all",
                  action="store_true", dest="all", default=False,
                  help="Launch all migrations")
parser.add_option("--commit",
                  action="store_true", dest="commit", default=False,
                  help="Commits the changes done on the database. default is False")
parser.add_option("--defaultprofile",
                  action="store_true", dest="defaultprofile", default=False,
                  help="apply the default profilee")
parser.add_option("--profile",
                  action="store", dest="profile", default="",
                  help="'dev','preprod','prod', 'mpa', 'makinanantes'  can be specify. profile is apply at the end of the script")
parser.add_option("--pdb",
                  action="store_true", dest="pdb", default=False,
                  help="Start on a pdb (even an ipython pdb:))")
parser.add_option("--recatalog",
                  action="store_true", dest="recatalog", default=False,
                  help="refresh my portal_catalog")


(options, args) = parser.parse_args()

def profile(plone, p="default"):
    """apply anticancer profile.
    p argument must be in ('default', 'dev', 'preprod', 'prod', 'mpa')
    """
    l = logging.getLogger('profile')
    setup_tool = plone.portal_setup
    old_context = setup_tool.getImportContextID()
    profile_toimport = "profile-Products.AntiCancerProfiles:anticancer_%s"%p
    l.info('apply profile: %s'%profile_toimport)
    setup_tool.setImportContext(profile_toimport)
    setup_tool.runAllImportSteps()
    setup_tool.setImportContext(old_context)
    l.info('profile applied')


def recatalog(plone):
    catalog = plone.portal_catalog
    #clear and rebuild
    catalog.refresh(clear=1)
    #or just reindex some indexes
    catalog.manage_reindexIndex(ids=['getId','created'])

def main():
    if not options.profile in ('', 'default', 'dev', 'preprod', 'prod', 'mpa', 'makinanantes'):
        parser.print_help()
        sys.exit(0)

    if not options.zopeconf:
        parser.print_help()
        sys.exit(0)

    else:
        plone, user = connect(options.zopeconf)
        del logging.root.handlers[1]
        lhandler = logging.FileHandler('migration.log')
        lhandler.setFormatter(logging.Formatter("%(asctime)s %(name)-1s %(levelname)-2s - %(message)s"))
        logging.root.addHandler(lhandler)

        if options.pdb:
            pdb.set_trace()

        if options.defaultprofile or options.all:
            profile(plone, p="default")

        if options.profile:
            profile(plone, p=options.profile)

        if options.recatalog or options.all:
            recatalog(plone)

        if options.commit:
            transaction.commit()
_______________________________________________
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )

Reply via email to