Changeset 3142 in products


Ignore:
Timestamp:
Apr 19, 2011 9:06:50 AM (13 years ago)
Author:
vmaksymiv
Message:

pep8 fixes

Location:
quintagroup.catalogupdater/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • quintagroup.catalogupdater/trunk/quintagroup/catalogupdater/exportimport/catalogupdater.py

    r1761 r3142  
    3737 
    3838            self._logger.info('Updating %s columns for %s Catalog.' % ( 
    39                 updatecols, '/'.join(catalog.getPhysicalPath())) ) 
     39                updatecols, '/'.join(catalog.getPhysicalPath()))) 
    4040 
    4141            cu = queryUtility(ICatalogUpdater, name='catalog_updater') 
  • quintagroup.catalogupdater/trunk/quintagroup/catalogupdater/exportimport/tests/test_catalogupdate.py

    r1981 r3142  
    3939""" % (PLONEFOUR and '<object name="old_plexicon" remove="True"/>' or \ 
    4040                     '<object name="foo_vocabulary" remove="True"/>') 
    41               
    4241 
    4342 
     
    4746    def updateMetadata4All(self, catalog, columns): 
    4847        self._logger.info("%s:%s" % (catalog.id, columns)) 
    49      
     48 
    5049 
    5150class CatalogUpdaterZCMLLayer(test_exportimport.ZCatalogXMLAdapterTests.layer): 
     
    6564 
    6665    def _getTargetClass(self): 
    67         from quintagroup.catalogupdater.exportimport.catalogupdater import CatalogUpdaterXMLAdapter 
     66        from quintagroup.catalogupdater.exportimport.catalogupdater \ 
     67            import CatalogUpdaterXMLAdapter 
    6868        return CatalogUpdaterXMLAdapter 
    6969 
     
    7878    def getLastMessage(self): 
    7979        messages = getattr(self.logger, '_messages', []) 
    80         return messages[-1] or [None,]*3 
     80        return messages[-1] or [None, ] * 3 
    8181 
    8282    def test_body_set_update(self): 
     
    9090 
    9191        message = self.getLastMessage() 
    92         self.assertEqual( message[-1], "foo_catalog:['eggs', 'spam']", 
    93             "Not updated columns in catalog" ) 
     92        self.assertEqual(message[-1], "foo_catalog:['eggs', 'spam']", 
     93            "Not updated columns in catalog") 
     94 
    9495 
    9596def test_suite(): 
  • quintagroup.catalogupdater/trunk/quintagroup/catalogupdater/interfaces.py

    r1759 r3142  
    11from zope.interface import Interface 
     2 
    23 
    34class IUpdatableCatalog(Interface): 
     
    56        exportimport handler 
    67    """ 
     8 
    79 
    810class ICatalogUpdater(Interface): 
     
    1719                          metadata, which must be updated. 
    1820        """ 
    19  
  • quintagroup.catalogupdater/trunk/quintagroup/catalogupdater/tests.py

    r1866 r3142  
    55from zope.component import queryUtility 
    66from zope.component import provideAdapter 
    7  
    8 from Testing import ZopeTestCase as ztc 
    97 
    108from Products.Five import zcml 
     
    3735ptc.setupPloneSite() 
    3836 
     37 
    3938class TestUtility(TestCase): 
    4039 
    4140    def afterSetUp(self): 
    4241        self.loginAsPortalOwner() 
    43         self.my_doc = makeContent(self.portal, portal_type='Document', id='my_doc') 
     42        self.my_doc = makeContent(self.portal, portal_type='Document', 
     43                                  id='my_doc') 
    4444        self.catalog = getToolByName(self.portal, 'portal_catalog') 
    4545        self.logout() 
     
    5151        self.catalog.addColumn('test_column') 
    5252 
    53  
    5453    def addIndexerNew(self): 
    5554        @indexer(Interface) 
     
    5857        provideAdapter(test_column, name='test_column') 
    5958 
    60  
    6159    def addIndexerOld(self): 
    6260        def test_column(obj, portal, **kwargs): 
    6361            return obj.id 
    6462        registerIndexableAttribute("test_column", test_column) 
    65  
    6663 
    6764    def testSingleColumnUpdate(self): 
     
    9390        self.assertTrue(mydoc.Title == "My document", mydoc.Title) 
    9491 
    95         self.my_doc.setTitle('New my document') # catalog not updated 
     92        self.my_doc.setTitle('New my document')  # catalog not updated 
    9693        cu = queryUtility(ICatalogUpdater, name="catalog_updater") 
    9794        cu.updateMetadata4All(self.catalog, 'test_column') 
     
    10097        self.assertTrue(mydoc.Title == 'My document', 
    10198            "Other metadata updated: Title='%s'" % mydoc.Title) 
    102  
    10399 
    104100    def testAllRecordsUpdate(self): 
     
    110106        num_recs = len(self.catalog._catalog.data) 
    111107        allcat = self.catalog.unrestrictedSearchResults(path='/') 
    112         num_updated = sum([1 for b in allcat if b.test_column==b.id]) 
     108        num_updated = sum([1 for b in allcat if b.test_column == b.id]) 
    113109 
    114110        self.assertTrue(num_updated == num_recs, "Only %d records updated, " \ 
    115111            "must be - %d" % (num_updated, num_recs)) 
    116  
    117112 
    118113    def testTransaction(self): 
     
    121116        # savepoint patch 
    122117        global sp_commits 
    123         sp_commits = 1 # Starts from 1 to count last commit 
     118        sp_commits = 1  # Starts from 1 to count last commit 
    124119        orig_trsp = transaction.savepoint 
     120 
    125121        def dummy_savepoint(*args, **kwargs): 
    126122            global sp_commits 
     
    132128        num_recs = len(self.catalog.unrestrictedSearchResults(path='/')) 
    133129        num_subcommits = 3 
    134         self.catalog.threshold = num_recs/num_subcommits 
     130        self.catalog.threshold = num_recs / num_subcommits 
    135131 
    136132        cu = queryUtility(ICatalogUpdater, name="catalog_updater") 
    137133        cu.updateMetadata4All(self.catalog, 'test_column') 
    138134 
    139         self.assertTrue(sp_commits == num_subcommits, 
    140             "Wrong number of transaction subcommits: actual:%d, must be: %d" % ( 
    141             sp_commits, num_subcommits)) 
     135        self.assertTrue(sp_commits == num_subcommits, "Wrong number of " \ 
     136            "transaction subcommits: actual:%d, must be: %d" % (sp_commits, 
     137            num_subcommits)) 
    142138 
    143139        transaction.savepoint = orig_trsp 
    144          
    145140 
    146141 
  • quintagroup.catalogupdater/trunk/quintagroup/catalogupdater/utility.py

    r1981 r3142  
    1 import logging, types 
     1import logging 
     2import types 
    23import transaction 
    34from zope.interface import implements 
     
    67 
    78from Missing import MV 
    8 from Acquisition import aq_inner 
    99from Acquisition import aq_parent 
    1010 
     
    1818        as _old_IIndexableObjectWrapper 
    1919    IS_NEW = False 
    20 else:     
     20else: 
    2121    IS_NEW = True 
    2222 
     
    3333    def validate(self, cat, cols): 
    3434        # Validate catalog and column name 
    35         AVAIL_COLTYPES = list(types.StringTypes) + [types.ListType, types.TupleType] 
     35        AVAIL_COLTYPES = list(types.StringTypes) + [types.ListType, 
     36                                                    types.TupleType] 
    3637 
    3738        _cat = getattr(cat, '_catalog', None) 
     
    4041 
    4142        if not type(cols) in AVAIL_COLTYPES: 
    42             raise TypeError("'columns' parameter must be one of the following " \ 
    43                 "types: %s" % AVAIL_COLTYPES) 
     43            raise TypeError("'columns' parameter must be one of the " \ 
     44                "following types: %s" % AVAIL_COLTYPES) 
    4445        # Normalize columns 
    4546        if type(cols) in types.StringTypes: 
    46             cols = [cols,] 
     47            cols = [cols, ] 
    4748        # Check is every column present in the catalog 
    4849        for col in cols: 
    49             if not _cat.schema.has_key(col): 
    50                 raise AttributeError("'%s' - not presented column in %s catalog " % (col, cat)) 
     50            if not col in _cat.schema: 
     51                raise AttributeError("'%s' - not presented column in " \ 
     52                                     "%s catalog " % (col, cat)) 
    5153 
    5254        return _cat, cols 
    53  
    5455 
    5556    def getWrappedObjectNew(self, obj, portal, catalog): 
     
    5758        wrapper = None 
    5859        if not IIndexableObject.providedBy(obj): 
    59              # This is the CMF 2.2 compatible approach, which should be used going forward 
    60              wrapper = queryMultiAdapter((obj, catalog), IIndexableObject) 
     60            # This is the CMF 2.2 compatible approach, 
     61            # which should be used going forward 
     62            wrapper = queryMultiAdapter((obj, catalog), IIndexableObject) 
    6163        return wrapper and wrapper or obj 
    6264 
     
    7274        else: 
    7375            vars = {} 
    74          
     76 
    7577        w = getMultiAdapter((obj, portal), _old_IIndexableObjectWrapper) 
    7678        w.update(vars) 
    7779 
    7880        return w 
    79  
    8081 
    8182    def updateMetadata4All(self, catalog, columns): 
     
    8788        portal = getToolByName(catalog, 'portal_url').getPortalObject() 
    8889        root = aq_parent(portal) 
    89          
     90 
    9091        data = _catalog.data 
    9192        schema = _catalog.schema 
    9293        paths = _catalog.paths 
    93         getWrappedObject = IS_NEW and self.getWrappedObjectNew or self.getWrappedObjectOld 
     94        getWrappedObject = (IS_NEW and self.getWrappedObjectNew 
     95                                    or self.getWrappedObjectOld) 
    9496        # For subtransaction support 
    9597        threshold = getattr(catalog, 'threshold', 10000) 
     
    112114            for column in columns: 
    113115                # calculate the column value 
    114                 attr=getattr(obj, column, MV) 
    115                 if(attr is not MV and safe_callable(attr)): attr=attr() 
     116                attr = getattr(obj, column, MV) 
     117                if (attr is not MV and safe_callable(attr)): 
     118                    attr = attr() 
    116119                # Update metadata value 
    117120                indx = schema[column] 
     
    134137                    _v_total = 0 
    135138                    LOG.info('commiting subtransaction') 
    136  
  • quintagroup.catalogupdater/trunk/setup.py

    r1982 r3142  
    99      long_description=open("README.txt").read() + "\n" + 
    1010                       open(os.path.join("docs", "HISTORY.txt")).read(), 
    11       # Get more strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers 
    1211      classifiers=[ 
    1312        "Framework :: Plone", 
Note: See TracChangeset for help on using the changeset viewer.