Changeset 204


Ignore:
Timestamp:
22-04-07 22:20:09 (6 years ago)
Author:
thomas
Message:
  • moap/main.py (main): Handle import errors.
  • moap/util/deps.py (Dependency, Dependency.install, RDF, RDF.fedora_install, genshi, genshi.fedora_install, handleImportError): Flesh out dependency checking code more, using the new distro code.
  • moap/util/Makefile.am:
  • moap/util/distro.py (Distro, Distro.init, getSysName, getMachine, getDistroFromRelease, _fedora_getVersionFromRelease): Add a distro module to figure out what distro we're on, inspired by codeina.
Location:
trunk
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/ChangeLog

    r203 r204  
     12007-04-22  Thomas Vander Stichele  <thomas at apestaart dot org> 
     2 
     3        * moap/main.py (main): 
     4          Handle import errors. 
     5        * moap/util/deps.py (Dependency, Dependency.install, RDF, 
     6          RDF.fedora_install, genshi, genshi.fedora_install, 
     7          handleImportError): 
     8          Flesh out dependency checking code more, using the new distro code. 
     9        * moap/util/Makefile.am: 
     10        * moap/util/distro.py (Distro, Distro.__init__, getSysName, getMachine, 
     11          getDistroFromRelease, _fedora_getVersionFromRelease): 
     12          Add a distro module to figure out what distro we're on, inspired 
     13          by codeina. 
     14 
    1152007-04-22  Thomas Vander Stichele  <thomas at apestaart dot org> 
    216 
  • trunk/moap/main.py

    r124 r204  
    66from moap.command import doap, cl, ignore, bug, code 
    77 
    8 from moap.util import log, util 
     8from moap.util import log, util, deps 
    99 
    1010def main(argv): 
     
    1515        sys.stderr.write('moap: error: %s\n' % e.args) 
    1616        return 255 
     17    except ImportError, e: 
     18        deps.handleImportError(e) 
     19        ret = -1 
    1720 
    1821    if ret is None: 
  • trunk/moap/util/Makefile.am

    r129 r204  
    66        ctags.py \ 
    77        deps.py \ 
     8        distro.py \ 
    89        log.py \ 
    910        mail.py \ 
  • trunk/moap/util/deps.py

    r75 r204  
    55# missing dependency 
    66 
     7from moap.util import distro 
     8 
    79import sys 
    810 
    9 deps = {} 
    10 deps['RDF'] = ( 
    11     "Redland RDF Python Bindings", 
    12     "http://librdf.org/docs/python.html" 
    13 ) 
     11class Dependency: 
     12    module = None 
     13    name = None 
     14    homepage = None 
     15 
     16    def install(self, distro): 
     17        """ 
     18        Return an explanation on how to install the given dependency 
     19        for the given distro/version/arch. 
     20 
     21        @rtype:   str or None 
     22        @returns: an explanation on how to install the dependency, or None. 
     23        """ 
     24        name = distro.tag + '_install' 
     25        m = getattr(self, name, None) 
     26        if m: 
     27            return m(distro) 
     28 
     29 
     30class RDF(Dependency): 
     31    module = 'RDF' 
     32    name = "Redland RDF Python Bindings" 
     33    homepage = "http://librdf.org/docs/python.html" 
     34 
     35    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\" -" 
     39 
     40        return "Your version of Fedora does not have python-redland available." 
     41 
     42 
     43class genshi(Dependency): 
     44    module = 'genshii' 
     45    name = "Genshi templating language" 
     46    homepage = "http://genshi.edgewall.com/" 
     47 
     48    def fedora_install(self, distro): 
     49        return "genshi is not yet available in Fedora Extras.\n" 
    1450 
    1551def handleImportError(exception): 
     
    2258        raise 
    2359    module = first[len('No module named '):] 
     60    module = module.split('.')[0] 
     61    deps = {} 
     62    for dep in [RDF(), genshi()]: 
     63        deps[dep.module] = dep 
     64 
    2465    if module in deps.keys(): 
    2566        dep = deps[module] 
    26         sys.stderr.write('Could not import %s\n' % module) 
    27         sys.stderr.write('This module is part of %s.\n' % dep[0]) 
    28         sys.stderr.write('Please install it and try again.\n') 
     67        sys.stderr.write("Could not import python module '%s'\n" % module) 
     68        sys.stderr.write('This module is part of %s.\n' % dep.name) 
     69        if dep.homepage: 
     70            sys.stderr.write('See %s for more information.\n\n' % dep.homepage) 
     71 
     72        d = distro.getDistroFromRelease() 
     73        if d: 
     74            howto = dep.install(d) 
     75            if howto: 
     76                sys.stderr.write(howto) 
     77            else: 
     78                sys.stderr.write( 
     79                    "On %s, MOAP does not know how to install %s.\n"  
     80                    "Please file a bug so we can add this dependency.\n" % ( 
     81                        d.name, dep.module)) 
     82        else: 
     83            sys.stderr.write("""MOAP does not know your distribution. 
     84Please file a bug so we can add your distribution. 
     85""") 
     86 
     87        sys.stderr.write('\n') 
     88 
     89        sys.stderr.write('Please install %s and try again.\n' % module) 
    2990        sys.stderr.write( 
    3091            'You can confirm it is installed by starting Python and running:\n') 
    3192        sys.stderr.write('import %s\n' % module) 
    32         sys.stderr.write('More information is at %s\n' % dep[1]) 
     93 
     94 
    3395        return 
    3496 
Note: See TracChangeset for help on using the changeset viewer.