Package moap :: Package util :: Module deps
[hide private]
[frames] | no frames]

Source Code for Module moap.util.deps

  1  # -*- Mode: Python -*- 
  2  # vi:si:et:sw=4:sts=4:ts=4 
  3   
  4  # code to handle import errors and tell us more information about the 
  5  # missing dependency 
  6   
  7  import os 
  8  import sys 
  9  import urllib 
 10   
 11  from moap.util import distro 
 12   
13 -class Dependency:
14 module = None 15 name = None 16 homepage = None 17
18 - def install(self, distro):
19 """ 20 Return an explanation on how to install the given dependency 21 for the given distro/version/arch. 22 23 @type distro: L{distro.Distro} 24 25 @rtype: str or None 26 @returns: an explanation on how to install the dependency, or None. 27 """ 28 name = distro.distributor + '_install' 29 m = getattr(self, name, None) 30 if m: 31 return m(distro)
32
33 - def FedoraCore_yum(self, packageName):
34 """ 35 Returns a string explaining how to install the given package. 36 """ 37 return "On Fedora, you can install %s with:\n" \ 38 "su -c \"yum install %s\"" % (self.module, packageName)
39
40 - def Ubuntu_apt(self, packageName):
41 """ 42 Returns a string explaining how to install the given package. 43 """ 44 return "On Ubuntu, you can install %s with:\n" \ 45 "sudo apt-get install %s" % (self.module, packageName)
46
47 -class RDF(Dependency):
48 module = 'RDF' 49 name = "Redland RDF Python Bindings" 50 homepage = "http://librdf.org/docs/python.html" 51
52 - def FedoraCore_install(self, distro):
53 return "python-redland is not yet available in Fedora Extras.\n"
54
55 - def Ubuntu_install(self, distro):
56 return self.Ubuntu_apt('python-librdf')
57
58 -class Cheetah(Dependency):
59 module = 'Cheetah' 60 name = "Cheetah templating language" 61 homepage = "http://cheetahtemplate.org/" 62
63 - def FedoraCore_install(self, distro):
64 if distro.atLeast('4'): 65 return self.FedoraCore_yum('python-cheetah') 66 67 return "python-cheetah is only available in Fedora 4 or newer.\n"
68
69 - def Ubuntu_install(self, distro):
70 return self.Ubuntu_apt('python-cheetah')
71
72 -class genshi(Dependency):
73 module = 'genshi' 74 name = "Genshi templating language" 75 homepage = "http://genshi.edgewall.com/" 76
77 - def FedoraCore_install(self, distro):
78 return "genshi is not yet available in Fedora Extras.\n"
79
80 - def Ubuntu_install(self, distro):
81 return self.Ubuntu_apt('python-genshi')
82
83 -class pygoogle(Dependency):
84 module = 'pygoogle' 85 name = "A Python Interface to the Google API" 86 homepage = "http://pygoogle.sourceforge.net/" 87
88 - def FedoraCore_install(self, distro):
89 return "pygoogle is not yet available in Fedora Extras.\n"
90
91 -class yahoo(Dependency):
92 module = 'yahoo' 93 name = "A Python Interface to the Yahoo Web API" 94 homepage = "http://developer.yahoo.com/python/" 95
96 - def FedoraCore_install(self, distro):
97 return "python-yahoo is not yet available in Fedora Extras.\n"
98
99 -class trac(Dependency):
100 module = 'trac' 101 name = "Trac issue tracker" 102 homepage = "http://trac.edgewall.com/" 103
104 - def FedoraCore_install(self, distro):
105 if distro.atLeast('3'): 106 return self.FedoraCore_yum('trac') 107 108 return "trac is only available in Fedora 3 or newer.\n"
109 110 # non-python dependencies
111 -class ctags(Dependency):
112 module = 'ctags' 113 name = "Exuberant ctags" 114 homepage = "http://ctags.sourceforge.net/" 115
116 - def FedoraCore_install(self, distro):
117 return self.FedoraCore_yum('ctags')
118
119 - def Ubuntu_install(self, distro):
120 return self.Ubuntu_apt('exuberant-ctags')
121
122 -def handleImportError(exception):
123 """ 124 Handle dependency import errors by displaying more information about 125 the dependency. 126 """ 127 first = exception.args[0] 128 if first.find('No module named ') < 0: 129 raise 130 module = first[len('No module named '):] 131 module = module.split('.')[0] 132 deps = {} 133 for dep in [RDF(), Cheetah(), genshi(), pygoogle(), trac(), yahoo()]: 134 deps[dep.module] = dep 135 136 if module in deps.keys(): 137 dep = deps[module] 138 sys.stderr.write("Could not import python module '%s'\n" % module) 139 sys.stderr.write('This module is part of %s.\n' % dep.name) 140 141 handleMissingDependency(dep) 142 143 # how to confirm the python module got installed 144 sys.stderr.write( 145 'You can confirm it is installed by starting Python and running:\n') 146 sys.stderr.write('import %s\n' % module) 147 148 return 149 150 # re-raise if we didn't have it 151 raise
152
153 -def getTicketURL(summary):
154 reporter = os.environ.get('EMAIL_ADDRESS', None) 155 get = "summary=%s" % urllib.quote(summary) 156 if reporter: 157 get += "&reporter=%s" % urllib.quote(reporter) 158 return 'http://thomas.apestaart.org/moap/trac/newticket?' + get
159
160 -def handleMissingDependency(dep):
161 if dep.homepage: 162 sys.stderr.write('See %s for more information.\n\n' % dep.homepage) 163 164 d = distro.getDistroFromRelease() 165 if d: 166 howto = dep.install(d) 167 if howto: 168 sys.stderr.write(howto) 169 else: 170 url = getTicketURL('DEP: %s, %s' % (dep.module, d.description)) 171 sys.stderr.write("""On %s, MOAP does not know how to install %s. 172 Please file a bug at: 173 %s 174 with instructions on how to install the dependency so we can add it. 175 """ % (d.description, dep.module, url)) 176 else: 177 url = getTicketURL('DISTRO: Unknown') 178 sys.stderr.write("""MOAP does not know your distribution. 179 Please file a bug at: 180 %s 181 with instructions on how to recognize your distribution so we can add it. 182 """ % url) 183 184 sys.stderr.write('\n') 185 186 sys.stderr.write('Please install %s and try again.\n' % dep.module)
187