Changeset 2841 in products


Ignore:
Timestamp:
Sep 22, 2010 11:38:39 AM (9 years ago)
Author:
mylan
Message:

Added support of migration from qPloneGoogleSitemaps product
to quintagroup.plonegooglesitemaps with tests.
Also all views now registered on own browserlayer.

Merged revisions 3865,3867-3872,3874-3878 via svnmerge from
http://svn.quintagroup.com/products/quintagroup.plonegooglesitemaps/branches/migratioin_product

........

r3865 | mylan | 2010-09-15 20:54:50 +0300 (Wed, 15 Sep 2010) | 1 line


#230: Added module aliases - prevent breakage sitemap, created with qPloneGoogleSitemaps

........

r3867 | mylan | 2010-09-17 11:41:35 +0300 (Fri, 17 Sep 2010) | 1 line


#230: Added browserlayer and registered all sitemaps views and configlet view to it

........

r3868 | mylan | 2010-09-17 13:12:09 +0300 (Fri, 17 Sep 2010) | 1 line


#230: remove module aliases

........

r3869 | mylan | 2010-09-17 13:13:14 +0300 (Fri, 17 Sep 2010) | 1 line


#230: Added migration from qPloneGoogleSitemaps to quintagroup.plonegooglesitemaps

........

r3870 | mylan | 2010-09-17 14:02:47 +0300 (Fri, 17 Sep 2010) | 1 line


#230: Added upgrade/migration step by step reference.

........

r3871 | mylan | 2010-09-17 14:41:04 +0300 (Fri, 17 Sep 2010) | 1 line


#230: Fix tests after registering all views to the browser layer

........

r3872 | mylan | 2010-09-17 14:55:43 +0300 (Fri, 17 Sep 2010) | 1 line


#230: Added uninstallation browserlayer and updated install/uninstall tests

........

r3874 | mylan | 2010-09-20 13:12:26 +0300 (Mon, 20 Sep 2010) | 1 line


#230: Added test for browser layer uninstallation

........

r3875 | mylan | 2010-09-20 15:37:00 +0300 (Mon, 20 Sep 2010) | 1 line


#230: Fix cleanup during migration from the qPloneGoogleSitemaps

........

r3876 | mylan | 2010-09-20 15:38:18 +0300 (Mon, 20 Sep 2010) | 1 line


#230: Fix typos in GS profile and import step

........

r3877 | mylan | 2010-09-20 18:23:20 +0300 (Mon, 20 Sep 2010) | 1 line


#230: Added tests of migration from qPloneGoogleSitemap to quintagroup.plonegooglesitemap.

........

r3878 | mylan | 2010-09-22 14:17:07 +0300 (Wed, 22 Sep 2010) | 1 line


#230: some upgrade tests reorganization

........

Location:
quintagroup.plonegooglesitemaps/trunk
Files:
12 edited
4 copied

Legend:

Unmodified
Added
Removed
  • quintagroup.plonegooglesitemaps/trunk

    • Property svn:mergeinfo
      •  

        old new  
         1/quintagroup.plonegooglesitemaps/branches/migratioin_product:2826-2839 
        12/quintagroup.plonegooglesitemaps/branches/plone4:2549-2553 
        23/quintagroup.plonegooglesitemaps/branches/test_refactoring:2527-2536 
    • Property svnmerge-integrated changed from /quintagroup.plonegooglesitemaps/branches/migratioin_product:1-3864 /quintagroup.plonegooglesitemaps/branches/test_refactoring:1-3576 /quintagroup.plonegooglesitemaps/branches/plone4:1-3593 to /quintagroup.plonegooglesitemaps/branches/migratioin_product:1-3879 /quintagroup.plonegooglesitemaps/branches/test_refactoring:1-3576 /quintagroup.plonegooglesitemaps/branches/plone4:1-3593
  • quintagroup.plonegooglesitemaps/trunk/quintagroup/plonegooglesitemaps/README.txt

    r2426 r2841  
     1=============================== 
     2quintagroup.plonegooglesitemaps 
     3=============================== 
     4 
    15Plone Google Sitemaps product allows Plone websites to get better visibility for Google search engine by providing it with complete listing of URLs to website content. 
    26   
     
    1519Different Sitemap types index their own content and do not depend on other Sitemaps. 
    1620 
    17 Usage 
     21USAGE 
     22===== 
    1823 
    1924  To enable Google Sitemaps on your site: 
     
    2530  See more detailed instructions on Plone Google Sitemaps usage at http://projects.quintagroup.com/products/wiki/qPloneGoogleSitemaps 
    2631 
    27 Screencast 
     32MIGRATION 
     33========= 
     34 
     35   If you UPGRADE older version of quintagroup.plonegooglesitemaps package to newer: 
     36   -------------------------------------------------------------------------------- 
     37    1. In your zope instance configuration or buildout - replace old package version 
     38       with new one. 
     39    2. Run plone instance and reinstall package with Quickinstaller tool 
     40       ("Add-on Products" in plone control panel). 
     41 
     42   If your MIGRATE from Products.qPloneGoogleSitemaps to quintagroup.plonegooglesitemaps: 
     43   ------------------------------------------------------------------------------------- 
     44    1. Add to new plone instance/buildout both qPloneGoogleSitemaps product and 
     45       last version quintagroup.plonegooglesitemaps package. 
     46    2. Copy Data.fs from old Plone instance to new one. 
     47    3. Start your new zope instance/buildout. 
     48 
     49    _Following steps performs in the plone instance_ 
     50    4. With portal_migration (ZMI) - upgrade plone instance. 
     51    5. With Quickinstaller tool ("Add-on Products" in plone control panel) 
     52       deinstall old "Plone Google Sitemaps" product and install new version. 
     53    6. Go to *Import* tab in portal_setup tool (ZMI), choose. 
     54       Select "Migrate from qPloneGoogleSitemaps to quintagroup.plonegooglesitemaps" 
     55       profile from selection box and choose same-named import step and push 
     56       "Import selected steps" button. 
     57 
     58    _And last clean-up steps:_ 
     59    7. Remove qPloneGoogleSitemaps product from your zope instance/buildout 
     60       configuration. 
     61 
     62 
     63SCREENCAST 
     64========== 
    2865 
    2966  Watch Plone Google Sitemaps Screencasts at http://quintagroup.com/cms/screencasts/qplonegooglesitemaps to see how to use this products on your Plone instance. Learn about how to install and configure Sitemaps on your Plone instance, how to create new Google Sitemaps, and how to let Google know about them. 
    3067 
    31 Links 
     68LINKS 
     69===== 
    3270 
    3371  * See "Google Sitemaps": https://www.google.com/webmasters/sitemaps website for more information. 
     
    4482 
    4583 
    46 Authors 
     84AUTHORS 
     85======= 
    4786 
    4887  The product was developed by Quintagroup.com team: 
  • quintagroup.plonegooglesitemaps/trunk/quintagroup/plonegooglesitemaps/__init__.py

    r1617 r2841  
     1import sys 
    12from AccessControl import allow_module 
    23 
  • quintagroup.plonegooglesitemaps/trunk/quintagroup/plonegooglesitemaps/browser/configure.zcml

    r2517 r2841  
    1313      allowed_interface=".commonview.ISitemapView" 
    1414      permission="zope.Public" 
     15      layer="quintagroup.plonegooglesitemaps.interfaces.IGoogleSitemapsLayer" 
    1516    /> 
    1617 
     
    2223      allowed_interface=".commonview.ISitemapView" 
    2324      permission="zope.Public" 
     25      layer="quintagroup.plonegooglesitemaps.interfaces.IGoogleSitemapsLayer" 
    2426    /> 
    2527 
     
    3133      allowed_interface=".commonview.ISitemapView" 
    3234      permission="zope.Public" 
     35      layer="quintagroup.plonegooglesitemaps.interfaces.IGoogleSitemapsLayer" 
    3336    /> 
    3437 
     
    3942      allowed_interface=".configletview.IConfigletSettingsView" 
    4043      permission="cmf.ManagePortal" 
     44      layer="quintagroup.plonegooglesitemaps.interfaces.IGoogleSitemapsLayer" 
    4145    /> 
    4246 
  • quintagroup.plonegooglesitemaps/trunk/quintagroup/plonegooglesitemaps/config.py

    r2538 r2841  
    2727# DO REBUILDING catalog 
    2828# UPDATE_CATALOG = True 
     29 
     30SUPPORT_BLAYER = True 
     31try: 
     32    from plone import browserlayer 
     33except ImportError: 
     34    SUPPORT_BLAYER = False 
  • quintagroup.plonegooglesitemaps/trunk/quintagroup/plonegooglesitemaps/interfaces.py

    r2746 r2841  
    66 
    77from Products.DCWorkflow.interfaces import IAfterTransitionEvent 
     8from plone.browserlayer.interfaces import ILocalBrowserLayerType 
    89 
    910from quintagroup.plonegooglesitemaps import qPloneGoogleSitemapsMessageFactory as _ 
     
    1617class INewsSitemapProvider(Interface): 
    1718    """Marker interface for News sitemap provider.""" 
     19 
     20 
     21class IGoogleSitemapsLayer(ILocalBrowserLayerType): 
     22    """Marker interface that defines browser layer for the package.""" 
  • quintagroup.plonegooglesitemaps/trunk/quintagroup/plonegooglesitemaps/profiles.zcml

    r2602 r2841  
    22    xmlns="http://namespaces.zope.org/zope" 
    33    xmlns:genericsetup="http://namespaces.zope.org/genericsetup" 
     4    xmlns:zcml="http://namespaces.zope.org/zcml" 
    45    i18n_domain="quintagroup.plonegooglesitemaps"> 
    56 
     
    3738      /> 
    3839 
     40    <genericsetup:registerProfile 
     41      zcml:condition="installed Products.qPloneGoogleSitemaps" 
     42      name="migrate_qPGSM" 
     43      title="Migrate from qPloneGoogleSitemaps to quintagroup.plonegooglesitemaps" 
     44      directory="profiles/migrate_qPGSM" 
     45      description="" 
     46      provides="Products.GenericSetup.interfaces.EXTENSION" 
     47      /> 
     48 
    3949    <genericsetup:upgradeStep 
    4050      title="Upgrade Plone Google Sitemaps 1.0 to 1.1" 
  • quintagroup.plonegooglesitemaps/trunk/quintagroup/plonegooglesitemaps/setuphandlers.py

    r2595 r2841  
     1import sys 
    12import logging 
    23from zope.component import getSiteManager 
    34from zope.component import getGlobalSiteManager 
     5 
     6from Acquisition import aq_parent 
    47from Products.CMFCore.utils import getToolByName 
     8 
     9from config import SUPPORT_BLAYER 
    510from quintagroup.plonegooglesitemaps.content.newsextender import NewsExtender 
    611 
     
    3944        logger.log(logging.INFO, "Unregistered \"%s\" configlet." % conf_id) 
    4045 
     46def removeBrowserLayer(site): 
     47    """ Remove browser layer. 
     48    """ 
     49    if not SUPPORT_BLAYER: 
     50        return 
     51 
     52    from plone.browserlayer.utils import unregister_layer 
     53    from plone.browserlayer.interfaces import ILocalBrowserLayerType 
     54 
     55    name="quintagroup.plonegooglesitemaps" 
     56    site = getSiteManager(site) 
     57    registeredLayers = [r.name for r in site.registeredUtilities() 
     58                        if r.provided == ILocalBrowserLayerType] 
     59    if name in registeredLayers: 
     60        unregister_layer(name, site_manager=site) 
     61        logger.log(logging.INFO, "Unregistered \"%s\" browser layer." % name) 
    4162 
    4263def uninstall(context): 
     
    4869    unregisterSchemaExtenderAdapters(site) 
    4970    removeConfiglet(site) 
     71    removeBrowserLayer(site) 
     72 
     73 
     74def cleanup(site): 
     75    """Clean-up qPloneGoogleSitemaps artefacts.""" 
     76    old_product = "qPloneGoogleSitemaps" 
     77    # Get plone tools 
     78    pp = getToolByName(site, 'portal_properties') 
     79    skins = getToolByName(site, 'portal_skins') 
     80    controlpanel = getToolByName(site, 'portal_controlpanel') 
     81    # Remove old configlet from controlpanel 
     82    configlet_ids = [ai['id'] for ai in controlpanel.listActionInfos()] 
     83    if old_product in configlet_ids: 
     84        controlpanel.unregisterConfiglet(old_product) 
     85        logger.info("Unregistered '%s' configlet from "\ 
     86                    "portal_controlpanel tool." % old_product) 
     87    # Remove qPloneGoogleSitemaps skin layer 
     88    for skinName in skins.getSkinSelections(): 
     89        skin_paths = skins.getSkinPath(skinName).split(',')  
     90        paths = [l.strip() for l in skin_paths if not l == old_product] 
     91        if len(paths) < len(skin_paths): 
     92            logger.info("Removed '%s' from '%s' skin." % (old_product, skinName)) 
     93        skins.addSkinSelection(skinName, ','.join(paths)) 
     94 
     95def recriateSitemaps(smaps): 
     96    msg = "Recriation Sitemaps: " 
     97    if smaps: 
     98        logger.info(msg + "Process %s sitemaps." % ( 
     99                [sm.getPath() for sm in smaps])) 
     100        fields = ['id', 'sitemapType', 'portalTypes', 'states', 
     101                  'blackout_list','reg_exp', 'urls', 'pingTransitions'] 
     102        for smb in smaps: 
     103            # get sitemap properties 
     104            sm_path = smb.getPath() 
     105            sm = smb.getObject() 
     106            container = aq_parent(sm) 
     107            data = {} 
     108            for fn in fields: 
     109                data[fn] = sm.getField(fn).getAccessor(sm)() 
     110            # Replace old GoogleSitemap by new one with 
     111            # previous properties 
     112            container.manage_delObjects(data['id']) 
     113            container.invokeFactory("Sitemap", id=data['id']) 
     114            new_sm = getattr(container, data['id']) 
     115            new_sm.update(**data) 
     116            new_sm.at_post_create_script() 
     117            logger.info("Successfully replaced '%s' Sitemap" % sm_path) 
     118 
     119def getOldGSitemaps(site): 
     120    catalog = getToolByName(site, 'portal_catalog') 
     121    smaps = catalog(portal_type="Sitemap") 
     122    old_smb = [smb for smb in smaps \ 
     123               if 'qPloneGoogleSitemaps' in str(smb.getObject().__class__)] 
     124    return old_smb 
     125     
     126def migrate_qPGSM(context): 
     127    """ Clean-up qPloneGoogleSitemaps product artefacts and 
     128        recriate sitemaps from quintagroup.plonegooglesitemaps 
     129        package version 1.0. 
     130    """ 
     131    if context.readDataFile('gsm_migration.txt') is None: 
     132        return 
     133 
     134    site = context.getSite() 
     135    cleanup(site) 
     136    old_gsmaps = getOldGSitemaps(site) 
     137    if old_gsmaps: 
     138        recriateSitemaps(old_gsmaps) 
     139        logger.info("Successfully migrated old GoogleSitemaps.") 
     140    else: 
     141        logger.info("No old GoogleSitemaps found.") 
     142 
     143 
  • quintagroup.plonegooglesitemaps/trunk/quintagroup/plonegooglesitemaps/tests/base.py

    r2555 r2841  
    1111from zope.interface import Interface 
    1212from zope.component import testing 
     13from zope.interface import alsoProvides 
    1314from Testing import ZopeTestCase as ztc 
    1415 
     
    2728from quintagroup.plonegooglesitemaps.config import PROJECTNAME 
    2829from quintagroup.plonegooglesitemaps.config import ping_googlesitemap 
     30from quintagroup.plonegooglesitemaps.config import SUPPORT_BLAYER  
    2931from quintagroup.plonegooglesitemaps.browser import mobilesitemapview 
     32from quintagroup.plonegooglesitemaps.interfaces import IGoogleSitemapsLayer 
    3033 
    3134quintagroup.plonegooglesitemaps.config.testing = 1 
     
    7073        self.workflow = self.portal.portal_workflow 
    7174        self.orig_mobile_ifaces = None 
     75        alsoProvides(self.portal.REQUEST, IGoogleSitemapsLayer) 
    7276 
    7377    def patchMobile(self): 
  • quintagroup.plonegooglesitemaps/trunk/quintagroup/plonegooglesitemaps/tests/testInstallation.py

    r2747 r2841  
    103103        self.assertEqual(brain.gsm_stock, gsm_stock) 
    104104 
     105    def test_browser_layer(self): 
     106        if not SUPPORT_BLAYER: 
     107            return 
     108 
     109        from plone.browserlayer import utils 
     110        self.assert_(IGoogleSitemapsLayer in utils.registered_layers(), 
     111                     "Not registered 'IGoogleSitemapsLayer' browser layer") 
     112 
    105113 
    106114class TestGoogleSitemapsUninstallation(TestCase): 
     
    125133            'Configlet found after uninstallation') 
    126134 
     135    def test_browserlayer_uninstall(self): 
     136        if not SUPPORT_BLAYER: 
     137            return 
     138 
     139        from plone.browserlayer import utils 
     140        self.assertEqual(IGoogleSitemapsLayer in utils.registered_layers(), False, 
     141            "Still registered 'IGoogleSitemapsLayer' browser layer") 
     142 
    127143 
    128144def test_suite(): 
  • quintagroup.plonegooglesitemaps/trunk/quintagroup/plonegooglesitemaps/tests/testNewsSitemaps.py

    r2750 r2841  
    259259                            sitemapType="news") 
    260260        context = self.portal['news-sitemaps'] 
    261         self.nsmv = queryMultiAdapter((context, TestRequest()), name="news-sitemap.xml") 
     261        request = TestRequest() 
     262        alsoProvides(request, IGoogleSitemapsLayer) 
     263        self.nsmv = queryMultiAdapter((context, request), name="news-sitemap.xml") 
    262264 
    263265        self.brain = self.portal.portal_catalog(portal_type="Document")[0] 
  • quintagroup.plonegooglesitemaps/trunk/quintagroup/plonegooglesitemaps/tests/testUpgrade.py

    r2601 r2841  
    33# 
    44 
     5import logging  
    56from base import * 
    67from zope.component import getSiteManager 
     8from StringIO import StringIO 
    79 
    810from Products.CMFPlone.utils import _createObjectByType 
     
    1113from quintagroup.plonegooglesitemaps import config 
    1214from quintagroup.plonegooglesitemaps import upgrades as gsm_upgrades 
     15from quintagroup.plonegooglesitemaps import setuphandlers as sh 
    1316from quintagroup.canonicalpath.interfaces import ICanonicalPath 
    1417from quintagroup.canonicalpath.interfaces import ICanonicalLink 
     
    104107            self.setup.setLastVersionForProfile(self.profile, orig_ver) 
    105108 
     109try: 
     110    from Products.qPloneGoogleSitemaps.content.sitemap import Sitemap as OldSitemap 
     111except ImportError: 
     112    PRESENT_OLD_PRODUCT = False 
     113else: 
     114    PRESENT_OLD_PRODUCT = True 
     115     
     116class TestMigrationFromProduct(TestCase): 
     117 
     118    def afterSetUp(self): 
     119        super(TestMigrationFromProduct, self).afterSetUp() 
     120        self.patch_logger() 
     121        self.gs = self.portal.portal_setup 
     122        self.profile = u'profile-quintagroup.plonegooglesitemaps:migrate_qPGSM' 
     123        self.step = "migrate_qPGSM" 
     124 
     125    def patch_logger(self): 
     126        logger = logging.Logger("test:GSM", logging.NOTSET) 
     127        self.log = StringIO() 
     128        self.thndlr = logging.StreamHandler(self.log) 
     129        self.thndlr.setLevel(logging.DEBUG) 
     130        self.thndlr.setFormatter(logging.Formatter("%(message)s")) 
     131        logger.addHandler(self.thndlr) 
     132 
     133        self.orig_logger = sh.logger 
     134        sh.logger = logger 
     135 
     136    def beforeTearDown(self): 
     137        sh.logger = self.orig_logger 
     138 
     139    def chkLog(self, chkstr): 
     140        self.thndlr.flush() 
     141        self.log.seek(0) 
     142        logs = self.log.getvalue().split('\n') 
     143        return chkstr in logs 
     144 
     145    def testRemoveOldConfiglet(self): 
     146        chk_str = "Unregistered 'qPloneGoogleSitemaps' "\ 
     147                  "configlet from portal_controlpanel tool." 
     148        # 1. No qPloneGoogleSitemaps configlet 
     149        self.gs.runImportStepFromProfile(self.profile, self.step) 
     150        self.assert_(not self.chkLog(chk_str), self.log.getvalue()) 
     151        # 2. qPloneGoogleSitemaps configlet in portal 
     152        self.portal.portal_controlpanel.registerConfiglet( 
     153            id="qPloneGoogleSitemaps", name="qPloneGoogleSitemaps", 
     154            action="string:") 
     155        self.gs.runImportStepFromProfile(self.profile, self.step) 
     156        self.assert_(self.chkLog(chk_str), self.log.getvalue()) 
     157 
     158    def testRemoveOldSkinLayer(self): 
     159        chk_str = "Removed 'qPloneGoogleSitemaps' from 'Plone Default' skin." 
     160        # 1. No qPloneGoogleSitemaps layer in portal_skins 
     161        self.gs.runImportStepFromProfile(self.profile, self.step) 
     162        self.assert_(not self.chkLog(chk_str), self.log.getvalue()) 
     163        # 2. qPloneGoogleSitemaps layer in portal_skins 
     164        skins = self.portal.portal_skins 
     165        skinpath = 'qPloneGoogleSitemaps,' + skins.getSkinPath("Plone Default") 
     166        skins._getSelections()["Plone Default"] = skinpath 
     167        self.gs.runImportStepFromProfile(self.profile, self.step) 
     168        self.assert_(self.chkLog(chk_str), self.log.getvalue()) 
     169 
     170    def testRecriateOldSitemaps(self): 
     171        chk_str = "Successfully replaced '/%s/sitemap.xml' Sitemap" \ 
     172                  % self.portal.id 
     173        # 1. No old sitemap present in portal 
     174        self.gs.runImportStepFromProfile(self.profile, self.step) 
     175        self.assert_(not self.chkLog(chk_str), self.log.getvalue()) 
     176        # 2. Add old sitemap object in to portal 
     177        self.portal.invokeFactory("Sitemap", 'sitemap.xml') 
     178        self.assert_('sitemap.xml' in self.portal.objectIds(), self.portal.objectIds()) 
     179        sm = self.portal['sitemap.xml'] 
     180        sm.__class__ = OldSitemap 
     181        self.gs.runImportStepFromProfile(self.profile, self.step) 
     182        self.assert_(self.chkLog(chk_str), self.log.getvalue()) 
     183         
    106184 
    107185def test_suite(): 
     
    109187    suite = TestSuite() 
    110188    suite.addTest(makeSuite(TestUpgrade)) 
     189    if PRESENT_OLD_PRODUCT: 
     190        suite.addTest(makeSuite(TestMigrationFromProduct)) 
     191 
    111192    return suite 
    112193 
Note: See TracChangeset for help on using the changeset viewer.