Changeset 1187 in tailor


Ignore:
Timestamp:
06/25/06 16:32:56 (7 years ago)
Author:
lele@…
Hash name:
20060625143256-97f81-d947ea871fb04712bd3b31d25fbca56cd4171e07
Message:

Fix repository instantiation
Don't use the logger, since we don't have one yet. The caller
will log something for us. Moved (and tested) the bzr specific
code into the pertaining unit.

Location:
vcpx
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • vcpx/repository/__init__.py

    r1185 r1187  
    3030        """ 
    3131 
    32         from vcpx.source import InvocationError 
     32        from vcpx import TailorException 
    3333 
    3434        kind = name[:name.index(':')] 
     
    4040            subclass = getattr(concrete, subclassname, klass) 
    4141        except SyntaxError, e: 
    42             self.log.exception("Cannot import %r from %r", kind, modname) 
    43             raise InvocationError("Cannot import %r: %s" % (kind, e)) 
    44         except (AttributeError, ImportError), e: 
    45             self.log.critical("Cannot import %r from %r", kind, modname) 
    46             if kind == 'bzr': 
    47                 from sys import version_info 
    48                 if version_info < (2,4): 
    49                     self.log.warning("Bazaar-NG backend requires Python 2.4") 
    50             raise InvocationError("%r is not a known VCS kind: %s" % 
    51                                   (self.kind, e)) 
     42            raise TailorException("Cannot import %r: %s" % (kind, e)) 
     43        except (AttributeError, ImportError, AssertionError), e: 
     44            raise TailorException("%r is not a known VCS kind: %s" % (kind, e)) 
    5245        instance = super(Repository, klass).__new__(subclass, name, 
    5346                                                    project, which) 
     
    168161        """ 
    169162 
    170         from vcpx.source import InvocationError 
     163        from vcpx import TailorException 
    171164 
    172165        wdname = self.kind.capitalize() + 'WorkingDir' 
     
    177170        except SyntaxError, e: 
    178171            self.log.exception("Cannot import %r from %r", wdname, modname) 
    179             raise InvocationError("Cannot import %r: %s" % (wdname, e)) 
     172            raise TailorException("Cannot import %r: %s" % (wdname, e)) 
    180173        except (AttributeError, ImportError), e: 
    181174            self.log.critical("Cannot import %r from %r", wdname, modname) 
    182             if self.kind == 'bzr': 
    183                 from sys import version_info 
    184                 if version_info < (2,4): 
    185                     self.log.warning("Bazaar-NG backend requires Python 2.4") 
    186             raise InvocationError("%r is not a known VCS kind: %s" % 
     175            raise TailorException("%r is not a known VCS kind: %s" % 
    187176                                  (self.kind, e)) 
    188177 
  • vcpx/tests/tailor.py

    r1180 r1187  
    255255from unittest import TestCase 
    256256from cStringIO import StringIO 
     257from vcpx import TailorException 
    257258from vcpx.config import Config 
    258259from vcpx.tailor import Tailorizer 
     
    358359    "Test the BazaarNG source backend" 
    359360 
     361    def testBazaarngAndPython23(self): 
     362        "Test we detect early when running under Python < 2.4" 
     363 
     364        from sys import version_info 
     365 
     366        if version_info < (2,4): 
     367            try: 
     368                self.tailorize('bazaarng2darcs') 
     369            except TailorException, e: 
     370                self.assert_("Bazaar-NG backend requires Python 2.4" 
     371                             in str(e)) 
     372            else: 
     373                self.fail("Expected a specific TailorException") 
     374 
    360375    def testBazaarngToDarcs(self): 
    361376        "Test bazaar-ng to darcs" 
    362377 
    363         self.tailorize('bazaarng2darcs') 
     378        try: 
     379            self.tailorize('bazaarng2darcs') 
     380        except TailorException, e: 
     381            from sys import version_info 
     382 
     383            if version_info < (2,4): 
     384                # Under python 2.3 we expect an exception here, but 
     385                # different from the above: since we are still in a 
     386                # single python session importing the bzr stuff does 
     387                # not raise the same error, because from the python 
     388                # runtime pov the module is already loaded and thus 
     389                # the second import does not fail. The repository 
     390                # class will then instantiate the raw Repository 
     391                # class, not the specific bzr one. Still, when asked 
     392                # for a working dir, it will fail again 
     393                self.assert_("object has no attribute 'BzrWorkingDir'" 
     394                             in str(e)) 
     395            else: 
     396                raise 
     397 
    364398 
    365399 
  • vcpx/repository/bzr.py

    r1179 r1187  
    1414 
    1515__docformat__ = 'reStructuredText' 
     16 
     17 
     18from sys import version_info 
     19assert version_info >= (2,4), "Bazaar-NG backend requires Python 2.4" 
     20del version_info 
    1621 
    1722from bzrlib.osutils import normpath 
Note: See TracChangeset for help on using the changeset viewer.