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 Debian_apt(self, packageName):
41 """ 42 Returns a string explaining how to install the given package. 43 """ 44 return "On Debian, you can install %s with:\n" \ 45 "sudo apt-get install %s" % (self.module, packageName)
46
47 - def Ubuntu_apt(self, packageName):
48 """ 49 Returns a string explaining how to install the given package. 50 """ 51 return "On Ubuntu, you can install %s with:\n" \ 52 "sudo apt-get install %s" % (self.module, packageName)
53
54 -class RDF(Dependency):
55 module = 'RDF' 56 name = "Redland RDF Python Bindings" 57 homepage = "http://librdf.org/docs/python.html" 58
59 - def FedoraCore_install(self, distro):
60 return "python-redland is not yet available in Fedora Extras.\n"
61
62 - def Ubuntu_install(self, distro):
63 return self.Ubuntu_apt('python-librdf')
64
65 -class Cheetah(Dependency):
66 module = 'Cheetah' 67 name = "Cheetah templating language" 68 homepage = "http://cheetahtemplate.org/" 69
70 - def FedoraCore_install(self, distro):
71 if distro.atLeast('4'): 72 return self.FedoraCore_yum('python-cheetah') 73 74 return "python-cheetah is only available in Fedora 4 or newer.\n"
75
76 - def Ubuntu_install(self, distro):
77 return self.Ubuntu_apt('python-cheetah')
78
79 -class genshi(Dependency):
80 module = 'genshi' 81 name = "Genshi templating language" 82 homepage = "http://genshi.edgewall.com/" 83
84 - def FedoraCore_install(self, distro):
85 return "genshi is not yet available in Fedora Extras.\n"
86
87 - def Ubuntu_install(self, distro):
88 return self.Ubuntu_apt('python-genshi')
89
90 -class pygoogle(Dependency):
91 module = 'pygoogle' 92 name = "A Python Interface to the Google API" 93 homepage = "http://pygoogle.sourceforge.net/" 94
95 - def FedoraCore_install(self, distro):
96 return "pygoogle is not yet available in Fedora Extras.\n"
97
98 -class yahoo(Dependency):
99 module = 'yahoo' 100 name = "A Python Interface to the Yahoo Web API" 101 homepage = "http://developer.yahoo.com/python/" 102
103 - def FedoraCore_install(self, distro):
104 return "python-yahoo is not yet available in Fedora Extras.\n"
105
106 - def Debian_install(self, distro):
107 return self.Debian_apt('python-yahoo')
108
109 -class trac(Dependency):
110 module = 'trac' 111 name = "Trac issue tracker" 112 homepage = "http://trac.edgewall.com/" 113
114 - def FedoraCore_install(self, distro):
115 if distro.atLeast('3'): 116 return self.FedoraCore_yum('trac') 117 118 return "trac is only available in Fedora 3 or newer.\n"
119 120 # non-python dependencies
121 -class ctags(Dependency):
122 module = 'ctags' 123 name = "Exuberant ctags" 124 homepage = "http://ctags.sourceforge.net/" 125
126 - def FedoraCore_install(self, distro):
127 return self.FedoraCore_yum('ctags')
128
129 - def Ubuntu_install(self, distro):
130 return self.Ubuntu_apt('exuberant-ctags')
131
132 -def handleImportError(exception):
133 """ 134 Handle dependency import errors by displaying more information about 135 the dependency. 136 """ 137 first = exception.args[0] 138 if first.find('No module named ') < 0: 139 raise 140 module = first[len('No module named '):] 141 module = module.split('.')[0] 142 deps = {} 143 for dep in [RDF(), Cheetah(), genshi(), pygoogle(), trac(), yahoo()]: 144 deps[dep.module] = dep 145 146 if module in deps.keys(): 147 dep = deps[module] 148 sys.stderr.write("Could not import python module '%s'\n" % module) 149 sys.stderr.write('This module is part of %s.\n' % dep.name) 150 151 handleMissingDependency(dep) 152 153 # how to confirm the python module got installed 154 sys.stderr.write( 155 'You can confirm it is installed by starting Python and running:\n') 156 sys.stderr.write('import %s\n' % module) 157 158 return 159 160 # re-raise if we didn't have it 161 raise
162
163 -def getTicketURL(summary):
164 reporter = os.environ.get('EMAIL_ADDRESS', None) 165 get = "summary=%s" % urllib.quote(summary) 166 if reporter: 167 get += "&reporter=%s" % urllib.quote(reporter) 168 return 'http://thomas.apestaart.org/moap/trac/newticket?' + get
169
170 -def handleMissingDependency(dep):
171 if dep.homepage: 172 sys.stderr.write('See %s for more information.\n\n' % dep.homepage) 173 174 d = distro.getDistroFromRelease() 175 if d: 176 howto = dep.install(d) 177 if howto: 178 sys.stderr.write(howto) 179 else: 180 url = getTicketURL('DEP: %s, %s' % (dep.module, d.description)) 181 sys.stderr.write("""On %s, MOAP does not know how to install %s. 182 Please file a bug at: 183 %s 184 with instructions on how to install the dependency so we can add it. 185 """ % (d.description, dep.module, url)) 186 else: 187 url = getTicketURL('DISTRO: Unknown') 188 sys.stderr.write("""MOAP does not know your distribution. 189 Please file a bug at: 190 %s 191 with instructions on how to recognize your distribution so we can add it. 192 """ % url) 193 194 sys.stderr.write('\n') 195 196 sys.stderr.write('Please install %s and try again.\n' % dep.module)
197