Changeset 221
- Timestamp:
- 19-05-07 00:04:20 (6 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
-
ChangeLog (modified) (1 diff)
-
moap/command/doap.py (modified) (2 diffs)
-
moap/util/deps.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ChangeLog
r220 r221 1 2007-05-19 Thomas Vander Stichele <thomas at apestaart dot org> 2 3 * moap/command/doap.py (Search, Search.addOptions, 4 Search.handleOptions, Search.do, Search.foundURL, Doap): 5 Implement moap doap search using either google or yahoo 6 to do a search for your project's page rank based on your 7 keyword query. 8 * moap/util/deps.py (genshi, genshi.fedora_install, google, 9 google.fedora_install, yahoo, yahoo.fedora_install, 10 handleImportError): 11 Add deps for google and yahoo. Fix genshi dep. 12 1 13 2007-05-16 Thomas Vander Stichele <thomas at apestaart dot org> 2 14 -
trunk/moap/command/doap.py
r208 r221 125 125 self.stderr.write("ERROR: %r\n" % e) 126 126 127 class Search(util.LogCommand): 128 description = "look up rank of project's home page based on keywords" 129 130 _engines = ["google", "yahoo"] 131 _default = "yahoo" 132 133 def addOptions(self): 134 self.parser.add_option('-e', '--engine', 135 action="store", dest="engine", default=self._default, 136 help="search engine to use (out of %s; defaults to %s)" % ( 137 ", ".join(self._engines), self._default)) 138 self.parser.add_option('-l', '--limit', 139 action="store", dest="limit", default="100", 140 help="maximum number of results to look at") 141 142 def handleOptions(self, options): 143 self._limit = int(options.limit) 144 self._engine = options.engine 145 146 def do(self, args): 147 if not args: 148 self.stderr.write('Please provide a search query.\n') 149 return 3 150 151 d = self.parentCommand.doap 152 project = d.getProject() 153 154 rank = 0 155 found = False 156 query = " ".join(args) 157 158 def foundURL(target, url): 159 # returns true if the url is close enough to the target 160 if target.endswith('/'): 161 target = target[:-1] 162 if url.endswith('/'): 163 url = url[:-1] 164 return url == target 165 166 if self._engine == 'google': 167 from pygoogle import google 168 169 while not found: 170 self.debug('Doing Google search for %s starting from %d' % ( 171 " ".join(args), rank)) 172 value = google.doGoogleSearch(" ".join(args), start=rank) 173 for result in value.results: 174 rank += 1 175 self.debug('Hit %d: URL %s' % (rank, result.URL)) 176 if foundURL(project.homepage, result.URL): 177 found = True 178 break 179 180 if rank >= self._limit: 181 break 182 183 elif self._engine == 'yahoo': 184 from yahoo.search import web 185 186 # yahoo's start is 1-based 187 while not found: 188 search = web.WebSearch('moapmoap', query=query, start=rank+1) 189 info = search.parse_results() 190 for result in info.results: 191 rank += 1 192 self.debug('Hit %d: URL %s' % (rank, result['Url'])) 193 if foundURL(project.homepage, result['Url']): 194 found = True 195 break 196 197 if rank >= self._limit: 198 break 199 200 else: 201 self.stderr.write("Unknown search engine '%s'.\n" % self._engine) 202 self.stderr.write("Please choose from %s.\n" % 203 ", ".join(self._engines)) 204 return 3 205 206 if found: 207 self.stdout.write("Found homepage as hit %d\n." % rank) 208 else: 209 self.stdout.write("Did not find homepage in first %d hits.\n" % 210 self._limit) 211 127 212 class Ical(util.LogCommand): 128 213 description = "Output iCal stream from project releases" … … 366 451 usage = "doap [doap-options] %command" 367 452 description = "read and act on DOAP file" 368 subCommandClasses = [Freshmeat, Ical, Mail, Rss, S how, bug.Bug]453 subCommandClasses = [Freshmeat, Ical, Mail, Rss, Search, Show, bug.Bug] 369 454 370 455 doap = None -
trunk/moap/util/deps.py
r204 r221 40 40 return "Your version of Fedora does not have python-redland available." 41 41 42 43 42 class genshi(Dependency): 44 module = 'genshi i'43 module = 'genshi' 45 44 name = "Genshi templating language" 46 45 homepage = "http://genshi.edgewall.com/" … … 48 47 def fedora_install(self, distro): 49 48 return "genshi is not yet available in Fedora Extras.\n" 49 50 class google(Dependency): 51 module = 'google' 52 name = "A Python Interface to the Google API" 53 homepage = "http://pygoogle.sourceforge.net/" 54 55 def fedora_install(self, distro): 56 return "pygoogle is not yet available in Fedora Extras.\n" 57 58 class yahoo(Dependency): 59 module = 'yahoo' 60 name = "A Python Interface to the Yahoo Web API" 61 homepage = "http://developer.yahoo.com/python/" 62 63 def fedora_install(self, distro): 64 return "python-yahoo is not yet available in Fedora Extras.\n" 50 65 51 66 def handleImportError(exception): … … 60 75 module = module.split('.')[0] 61 76 deps = {} 62 for dep in [RDF(), genshi() ]:77 for dep in [RDF(), genshi(), google()]: 63 78 deps[dep.module] = dep 64 79 … … 92 107 sys.stderr.write('import %s\n' % module) 93 108 94 95 109 return 96 110 111 # re-raise if we didn't have it 97 112 raise
Note: See TracChangeset
for help on using the changeset viewer.
