Changeset 231


Ignore:
Timestamp:
19-05-07 13:30:41 (6 years ago)
Author:
thomas
Message:
  • moap/util/deps.py (Dependency.install, Dependency.fedora_yum, RDF.fedora_install, Cheetah, Cheetah.fedora_install, handleImportError): Add a method to make the yum install output uniform. RDF is not available at all yet in Fedora. Cheeath is though.
  • moap/util/distro.py (Distro, Distro.atLeast, getDistroFromRelease, _fedora_getNameVersionFromRelease): Rename distro-specific methods internally to make more sense. Add .atLeast to do string-based version comparisons.
  • moap/test/test_util_distro.py (TestRelease?.testFedora, TestRelease?.testGet, TestAtLeast?, TestAtLeast?.testFedora): Add some tests for atLeast Coverage: 73 % ( 859 / 1172)
Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/ChangeLog

    r230 r231  
     12007-05-19  Thomas Vander Stichele  <thomas at apestaart dot org> 
     2 
     3        * moap/util/deps.py (Dependency.install, Dependency.fedora_yum, 
     4          RDF.fedora_install, Cheetah, Cheetah.fedora_install, 
     5          handleImportError): 
     6          Add a method to make the yum install output uniform. 
     7          RDF is not available at all yet in Fedora. 
     8          Cheeath is though. 
     9        * moap/util/distro.py (Distro, Distro.atLeast, getDistroFromRelease, 
     10          _fedora_getNameVersionFromRelease): 
     11          Rename distro-specific methods internally to make more sense. 
     12          Add .atLeast to do string-based version comparisons. 
     13        * moap/test/test_util_distro.py (TestRelease.testFedora, 
     14          TestRelease.testGet, TestAtLeast, TestAtLeast.testFedora): 
     15          Add some tests for atLeast 
     16 
     17          Coverage: 73 %   ( 859 / 1172) 
     18 
    1192007-05-19  Thomas Vander Stichele  <thomas at apestaart dot org> 
    220 
  • trunk/moap/test/test_util_distro.py

    r205 r231  
    1010class TestRelease(unittest.TestCase): 
    1111    def testFedora(self): 
    12         self.assertEquals(distro._fedora_getVersionFromRelease( 
     12        self.assertEquals(distro._fedora_getNameVersionFromRelease( 
    1313            'Fedora Core release 5 (Bordeaux)\n'), ('Fedora Core', '5')) 
    1414 
    1515    def testGet(self): 
    1616        distro.getDistroFromRelease() 
     17 
     18class TestAtLeast(unittest.TestCase): 
     19    def testFedora(self): 
     20        d = distro.Distro('fedora', 'Fedora Core', '5', 'i386') 
     21        self.failUnless(d.atLeast('4test2')) 
     22        self.failUnless(d.atLeast('5')) 
     23        self.failIf(d.atLeast('5test2')) 
     24        self.failIf(d.atLeast('40')) 
     25        self.failIf(d.atLeast('50')) 
  • trunk/moap/util/deps.py

    r224 r231  
    1919        for the given distro/version/arch. 
    2020 
     21        @type  distro: L{distro.Distro} 
     22 
    2123        @rtype:   str or None 
    2224        @returns: an explanation on how to install the dependency, or None. 
     
    2729            return m(distro) 
    2830 
     31    def fedora_yum(self, packageName): 
     32        """ 
     33        Returns a string explaining how to install the given package. 
     34        """ 
     35        return "On Fedora, you can install %s with:\n" \ 
     36                "su -c \"yum install %s\"" % (self.module, packageName) 
    2937 
    3038class RDF(Dependency): 
     
    3442 
    3543    def fedora_install(self, distro): 
    36         if distro.version >= '5': 
    37             return "You can install RDF on Fedora with:\n" \ 
    38                 "su -c \"yum install python-redland\" -" 
     44        return "python-redland is not yet available in Fedora Extras.\n" 
    3945 
    40         return "Your version of Fedora does not have python-redland available." 
     46class Cheetah(Dependency): 
     47    module = 'Cheetah' 
     48    name = "Cheetah templating language" 
     49    homepage = "http://cheetahtemplate.org/" 
     50 
     51    def fedora_install(self, distro): 
     52        if distro.atLeast('4'): 
     53            return self.fedora_yum('python-cheetah') 
     54 
     55        return "python-cheetah is only available in Fedora 4 or newer.\n" 
    4156 
    4257class genshi(Dependency): 
     
    7590    module = module.split('.')[0] 
    7691    deps = {} 
    77     for dep in [RDF(), genshi(), pygoogle(), yahoo()]: 
     92    for dep in [RDF(), Cheetah(), genshi(), pygoogle(), yahoo()]: 
    7893        deps[dep.module] = dep 
    7994 
  • trunk/moap/util/distro.py

    r204 r231  
    44import os 
    55import re 
     6 
     7import distutils.version 
    68 
    79from moap.util import log 
     
    1214 
    1315class Distro: 
     16    """ 
     17    @cvar tag:     a short lower-case identifier for the distro 
     18    @type tag:     str 
     19    @cvar name:    a longer human-readable name for the distro 
     20    @type name:    str 
     21    @cvar version: the version of the distro 
     22    @type version: str 
     23    @cvar arch:    the architecture of the distro 
     24    @type arch:    str 
     25    """ 
    1426    tag = None 
    1527    name = None 
     
    2234        self.version = version 
    2335        self.arch = arch 
     36 
     37    def atLeast(self, version): 
     38        """ 
     39        @param version: version to compare with 
     40        @type version:  str 
     41 
     42        Returns: whether the distro is at least as new as the given version, 
     43                 taking non-numbers into account. 
     44        """ 
     45        mine = distutils.version.LooseVersion(self.version) 
     46        theirs = distutils.version.LooseVersion(version) 
     47        return mine >= theirs 
    2448 
    2549def getSysName(): 
     
    6589            h.close() 
    6690            version = None 
    67             f = '_%s_getVersionFromRelease' % distro 
     91            f = '_%s_getNameVersionFromRelease' % distro 
    6892            if f in globals().keys(): 
    6993                log.debug('distro', "Found version function %r" % f) 
     
    7498 
    7599# distro-specific name and version getters 
    76 def _fedora_getVersionFromRelease(contents): 
     100# each getter should return a list of [full name, version] 
     101def _fedora_getNameVersionFromRelease(contents): 
    77102    matcher = re.compile("^(Fedora Core) release (\d+) .*") 
    78103    m = matcher.search(contents) 
Note: See TracChangeset for help on using the changeset viewer.