def handle_httpwatch_add(bot, ievent): if len(ievent.args) != 1: ievent.missing('<url>') else: try: geturl2(ievent.args[0]) httpwatch.add(ievent.args[0], bot.name, ievent.channel) ievent.reply('http watcher added') except Exception, e: ievent.reply('failed to add: %s' % (str(e), ))
def handle_httpwatch_add(bot, ievent): if len(ievent.args) != 1: ievent.missing('<url>') else: try: geturl2(ievent.args[0]) httpwatch.add(ievent.args[0], bot.name, ievent.channel) ievent.reply('http watcher added') except Exception, e: ievent.reply('failed to add: %s' % (str(e),))
def show(self, bugId): assert bugId.isdigit(), "bug id has to be a number" html = geturl2(self.show_url(bugId)) data = {} stat = '' for line in html.splitlines(): line = line.strip() if not line: continue elif '<td headers="category">' in line: stat = 'category' elif '<td headers="status">' in line: stat = 'status' elif '<td headers="assignedto">' in line: stat = 'assigned to' elif '<td headers="os">' in line: data['os'] = striphtml(line).strip() elif '<td headers="severity">' in line: data['severity'] = striphtml(line).strip() elif '<td headers="priority">' in line: data['priority'] = striphtml(line).strip() elif '<td headers="reportedver">' in line: data['version'] = striphtml(line).strip() elif '<h2 class="summary' in line: stat = 'summary' elif '<a href="#comments">Comments (' in line: data['comments'] = line.split('(', 1)[1].split(')')[0] # stats elif stat: if stat in ['category', 'status', 'assigned to', 'summary']: data[stat] = striphtml(line).strip() stat = '' return data
def show(self, bugId): assert bugId.isdigit(), "bug id has to be a number" tsv = geturl2(self.show_url(bugId) + '?format=tab').splitlines() keys = map(lambda x: x.strip(), tsv[0].split()) part = tsv[1].split('\t') data = dict(zip(keys, part)) return data
def show(self, bugId): assert bugId.isdigit(), "bug id has to be a number" tsv = geturl2(self.show_url(bugId)+'?format=tab').splitlines() keys = map(lambda x: x.strip(), tsv[0].split()) part = tsv[1].split('\t') data = dict(zip(keys, part)) return data
def handle_install(bot, ievent): """ install <server> <dir> <plugin> .. install plugin from server """ try: (server, dirr, plug) = ievent.args except ValueError: if 'install-plug' in ievent.origtxt: ievent.missing("<server> <dir> <plug>") else: ievent.missing("<server> <dir> <plug> (maybe try install-plug ?)") return if plug.endswith('.py'): plug = plug[:-3] plug = plug.split(os.sep)[-1] url = 'http://%s/%s/%s' % (server, dirr, plug) try: readme = geturl2(url + '.README') if readme: readme = readme.replace('\n', ' .. ') readme = re.sub('\s+', ' ', readme) readme += ' (yes/no)' ievent.reply(readme) response = waitforuser(bot, ievent.userhost) if not response or response.txt != 'yes': ievent.reply('not installing %s' % plug) return except: pass installer = Installer() try: installer.install(plug, 'http://%s/%s' % (server, dirr)) except InstallerException, e: ievent.reply('error installing %s: ' % plug, result=[str(x) for x \ in list(e)], dot=True) return
def geturl_title(url): """ fetch title of url """ try: result = geturl2(url) except urllib2.HTTPError, ex: rlog(10, 'snarf', str(ex)) return False
def fetchplugdata(self, base, ext='py'): ''' Here the actual HTTP request is being made. ''' url = '%s.%s' % (base, ext) plug = base.split('/')[-1] try: plugdata = geturl2(url) except urllib2.HTTPError: raise InstallerException("no %s" % os.path.basename(url)) if plugdata: try: plugsig = geturl2('%s.asc' % url) except urllib2.HTTPError: raise InstallerException('%s plugin has no signature' % plug) else: return plugdata, plugsig
def list(self): html = geturl2(self.list_url()) bugs = [] for line in html.splitlines(): if '<a href="detail?id' in line and '&' in line: bug = line.split('id=')[1].split('&')[0] if not bug in bugs: bugs.append(bug) return bugs
def list(self): csv = geturl2(self.list_url_summary()) num = 0 for line in csv.splitlines(): try: num += int(line.split(',')[1]) except ValueError: pass bugs = [] if num > 100: bugs.append('showing 100-%d' % num) csv = geturl2(self.list_url()) for line in csv.splitlines()[1:]: part = line.split(',') bugs.append('%s (%s)' % (part[0], part[1].replace('"', ''))) if len(bugs) > 100: break return bugs
def list(self): tsv = geturl2(self.list_url()).splitlines() bugs = [] keys = map(lambda x: x.strip(), tsv[0].split()) for item in tsv[1:]: data = {} part = item.split('\t') # dirty hack to allow unescaped multilines in trac if part[0].isdigit() and part[1].isdigit() and len(part) == len(keys): data = dict(zip(keys, part)) bugs.append('%s (%s)' % (data['summary'], data['ticket'])) return bugs
def list(self): tsv = geturl2(self.list_url()).splitlines() bugs = [] keys = map(lambda x: x.strip(), tsv[0].split()) for item in tsv[1:]: data = {} part = item.split('\t') # dirty hack to allow unescaped multilines in trac if part[0].isdigit() and part[1].isdigit() and len(part) == len( keys): data = dict(zip(keys, part)) bugs.append('%s (%s)' % (data['summary'], data['ticket'])) return bugs
def show(self, bugId): assert bugId.isdigit(), "bug id has to be a number" html = geturl2(self.show_url(bugId)) if 'APPLICATION ERROR #1100' in html: raise BugTrackerNotFound('issue not found') data = {'notes': 0} stat = '' skip = 0 for line in html.splitlines(): line = line.strip().replace('\t', '') if skip > 0: skip -= 1 continue elif not line: continue elif '<!-- Category -->' in line: skip = 1 stat = 'category' elif '<!-- Severity -->' in line: skip = 1 stat = 'severity' elif '<!-- Reproducibility -->' in line: skip = 1 stat = 'reproducibility' elif '<!-- Reporter -->' in line: skip = 3 stat = 'reporter' elif '<!-- Priority -->' in line: skip = 1 stat = 'priority' elif '<!-- Resolution -->' in line: skip = 1 stat = 'resolution' elif '<!-- Status -->' in line: skip = 3 stat = 'status' elif '<!-- Summary -->' in line: skip = 4 stat = 'summary' elif '<td class="bugnote-public">' in line: data['notes'] += 1 # stats elif stat: if stat in [ 'category', 'severity', 'reproducibility', 'reporter', 'priority', 'resolution', 'status', 'summary' ]: data[stat] = striphtml(line) stat = '' return data
def show(self, bugId): assert bugId.isdigit(), "bug id has to be a number" html = geturl2(self.show_url(bugId)) if 'APPLICATION ERROR #1100' in html: raise BugTrackerNotFound('issue not found') data = {'notes': 0} stat = '' skip = 0 for line in html.splitlines(): line = line.strip().replace('\t', '') if skip > 0: skip -= 1 continue elif not line: continue elif '<!-- Category -->' in line: skip = 1 stat = 'category' elif '<!-- Severity -->' in line: skip = 1 stat = 'severity' elif '<!-- Reproducibility -->' in line: skip = 1 stat = 'reproducibility' elif '<!-- Reporter -->' in line: skip = 3 stat = 'reporter' elif '<!-- Priority -->' in line: skip = 1 stat = 'priority' elif '<!-- Resolution -->' in line: skip = 1 stat = 'resolution' elif '<!-- Status -->' in line: skip = 3 stat = 'status' elif '<!-- Summary -->' in line: skip = 4 stat = 'summary' elif '<td class="bugnote-public">' in line: data['notes'] += 1 # stats elif stat: if stat in ['category', 'severity', 'reproducibility', 'reporter', 'priority', 'resolution', 'status', 'summary']: data[stat] = striphtml(line) stat = '' return data
def update(): """ update remote installed plugins """ updated = [] all = cfg.list() for plug in all.keys(): try: if plug in plugins.plugdeny.data: continue data = geturl2(all[plug][0]) if hasattr(data, 'info') and data.info.has_key('last-modified'): if data.info['last-modified'] > all[plug][1]: updated.append(all[plug][0]) except urllib2.HTTPError: pass except urllib2.URLError: pass return updated
def handle_installplug(bot, ievent): """ remotely install a plugin """ if not ievent.args: ievent.missing('<plugnames>') return notinstalled = [] installed = [] reloaded = [] reloadfailed = [] missing = [] errors = {} reloaderrors = {} installer = Installer() for plug in ievent.args: ok = False url = '' plug = plug.split(os.sep)[-1] for site in installsites: try: readme = geturl2('%s/%s.README' % (site, plug)) if readme: readme = readme.replace('\n', ' .. ') readme = re.sub('\s+', ' ', readme) readme += ' (yes/no)' ievent.reply(readme) response = waitforuser(bot, ievent.userhost) if not response or response.txt != 'yes': ievent.reply('not installing %s' % plug) notinstalled.append(plug) break except: pass try: url = installer.install(plug, site) if url: rlog(10, 'install', 'installed %s' % url) installed.append(plug) break # stop iterating sites except NoGPGException, ex: ievent.reply("couldn't run gpg .. please install gnupg if you \ want to install remote plugins") return except Exception, ex: errors[site] = str(ex)
def handle_installlist(bot, ievent): """ install-list .. list the available remote installable plugs """ errors = [] result = [] if ievent.rest: sites = [ ievent.rest, ] else: sites = installsites for i in sites: try: pluglist = geturl2(i) except Exception, ex: errors.append(i) continue result += re.findall('<a href="(.*?)\.py">', pluglist) try: result.remove('__init__') except ValueError: pass
def handle_installkey(bot, ievent): """ install a remote gpg key into the keyring """ if not bot.ownercheck(ievent): return if len(ievent.args) != 1: return ievent.missing('<key id> or <key file url>') url = ievent.args[0] if url.startswith('http://'): try: pubkey = geturl2(url) except urllib2.HTTPError: return ievent.reply('failed to fetch key from %s' % ievent.args[0]) except urllib2.URLError, ex: ievent.reply("there was a problem fetching %s .. %s" % (url, \ str(ex))) return fingerprint = pgp.imports(pubkey) if fingerprint: return ievent.reply('installed key with fingerprint %s' % \ fingerprint) else: return ievent.reply('no valid pgp public key found')
def show(self, bugId): assert bugId.isdigit(), "bug id has to ba a number" html = geturl2(self.show_url(bugId)).splitlines() data = {} stat = '' for line in html: line = line.strip() if not line: continue if line.startswith('<span class=h3 >'): data['summary'] = striphtml(line) elif line.startswith('<tr><th align=left>Status:'): stat = 'status' elif line.startswith('class=label><b>Type-</b>'): data['type'] = striphtml(line.split('</b>')[1]) elif line.startswith('class=label><b>Priority-</b>'): data['priority'] = striphtml(line.split('</b>')[1]) elif line.startswith( '<span class=author>') and not data.has_key('author'): stat = 'author' elif line.startswith('<tr><th align=left>Owner:'): stat = 'owner' elif line.startswith('<span class="date" title="'): data['date'] = striphtml(line) elif striphtml(line) == '': pass # stats elif stat == 'author': data['reporter'] = striphtml(line) stat = '' elif stat == 'owner': data['owner'] = striphtml(line) stat = '' elif stat == 'status': data['status'] = striphtml(line) stat = '' return data
def show(self, bugId): assert bugId.isdigit(), "bug id has to ba a number" html = geturl2(self.show_url(bugId)).splitlines() data = {} stat = '' for line in html: line = line.strip() if not line: continue if line.startswith('<span class=h3 >'): data['summary'] = striphtml(line) elif line.startswith('<tr><th align=left>Status:'): stat = 'status' elif line.startswith('class=label><b>Type-</b>'): data['type'] = striphtml(line.split('</b>')[1]) elif line.startswith('class=label><b>Priority-</b>'): data['priority'] = striphtml(line.split('</b>')[1]) elif line.startswith('<span class=author>') and not data.has_key('author'): stat = 'author' elif line.startswith('<tr><th align=left>Owner:'): stat = 'owner' elif line.startswith('<span class="date" title="'): data['date'] = striphtml(line) elif striphtml(line) == '': pass # stats elif stat == 'author': data['reporter'] = striphtml(line) stat = '' elif stat == 'owner': data['owner'] = striphtml(line) stat = '' elif stat == 'status': data['status'] = striphtml(line) stat = '' return data
def fetch(server, qid='random'): html = geturl2('http://%s/%s' % (server, qid)) text = '' keep = False for line in html.splitlines(): if len(line.split('</p>')) == 3: return striphtml(line.split('</p>')[1]) elif line.startswith('<p class="quote">'): if '<p class="qt">' in line: if line.endswith('</p>'): return striphtml(re_p.findall(line)[0]) else: text = line.split('<p class="qt">')[1] keep = True elif keep: if '</p>' in line: text = text + line.split('</p>')[0] return striphtml(text.replace('<br />', ' ')) else: text = text + line if text: return striphtml(text.replace('<br />', ' ')) else: return 'no result'
def checksum(self, url): data = geturl2(url) return md5.new(data).hexdigest()