def sign(self): self.sdir = util.absolutepath(self.sdir) sl = [f for f in os.listdir(self.sdir) if f.endswith(self.tail)] if not sl: raise util.DeadMan('no signature files in %s' % self.sdir) self.sigs = [sig for sig in map(self.getstring, sl) if sig] weed_re = None while True: reply = self.getsig(weed_re) if reply.startswith(self.ckey): weed_re = self.checkpattern(reply[1:]) else: break if self.items is not None: if self.items: sig = self.sep + self.items[0] else: self.sig = util.absolutepath(self.sig) fp = open(self.sig) try: sig = self.sep + fp.read() finally: fp.close() if not self.dest: self.ui.write(sig) else: for fn in self.dest: fp = open(fn, 'a') try: fp.write(sig) finally: fp.close() elif self.dest: self.ui.write('\n')
def getmhiers(self): '''Checks whether given directories exist and creates mhiers set (unique elems) with absolute paths.''' if self.ui.mhiers or self.ui.specdirs: # cmdline priority # specdirs have priority mhiers = self.ui.specdirs or self.ui.mhiers # split colon-separated list from cmdline mhiers = mhiers.split(':') elif self.ui.mhiers is None: mhiers = self.ui.configlist('messages', 'maildirs', default=_getmhier()) else: mhiers = self.ui.mhiers # create set of unique elements mhiers = set([util.absolutepath(e) for e in mhiers]) mhiers = sorted(mhiers) self.ui.mhiers = [] previtem = '' for hier in mhiers: if not os.path.isdir(hier): self.ui.warn('%s: not a directory, skipping\n' % hier) continue if previtem and hier.startswith(previtem): self.ui.warn('%s: subdirectory of %s, skipping\n' % (hier, previtem)) continue self.ui.mhiers.append(hier) previtem = hier
def fixurl(self, url, cygpath): '''Adapts possibly short url to pass as browser argument.''' if not self.weburl_re or self.weburl_re.match(url): url = urlregex.webschemecomplete(url) gophers = ('lynx', 'firefox') if url.startswith('gopher://') and self.ui.app not in gophers: # use gateway when browser is not gopher capable url = url.replace('gopher://', 'http://gopher.floodgap.com/gopher/gw?') else: # local if url.startswith('file:'): # drop scheme in favour of local path # as some browsers do not handle file scheme gracefully url = url[5:] if url.startswith('//'): url = url[2:] if not url.startswith('/'): # drop host part (validity of path checked below) url = '/' + url.split('/', 1)[1] if not url.startswith('http://'): url = util.absolutepath(url) if not os.path.exists(url): raise util.DeadMan('%s: not found' % url) if cygpath: url = util.pipeline(['cygpath', '-w', url]).rstrip() url = 'file://' + url return url
def kiosktest(self): '''Provides the path to an mbox file to store retrieved messages.''' if not self.ui.kiosk: self.ui.kiosk = tempfile.mkstemp(prefix='kiosk.')[1] return self.ui.kiosk = util.absolutepath(self.ui.kiosk) if (not os.path.exists(self.ui.kiosk) or not os.path.getsize(self.ui.kiosk)): # non existant or empty is fine return if not os.path.isfile(self.ui.kiosk): raise util.DeadMan('%s: not a regular file' % self.ui.kiosk) fp = open(self.ui.kiosk, 'rb') try: testline = fp.readline() finally: fp.close() try: p = email.Parser.Parser() check = p.parsestr(testline, headersonly=True) except email.Errors.HeaderParseError as inst: raise util.DeadMan(inst) if check.get_unixfrom(): self.muttone = False else: raise util.DeadMan('%s: not a unix mailbox' % self.ui.kiosk)
def fixurl(self, url, cygpath): '''Adapts possibly short url to pass as browser argument.''' if not self.weburl_re or self.weburl_re.match(url): url = urlregex.webschemecomplete(url) gophers = 'lynx', 'firefox' if url.startswith('gopher://') and self.appname not in gophers: # use gateway when browser is not gopher capable url = url.replace('gopher://', 'http://gopher.floodgap.com/gopher/gw?') else: # local if url.startswith('file:'): # drop scheme in favour of local path # as some browsers do not handle file scheme gracefully url = url[5:] if url.startswith('//'): url = url[2:] if not url.startswith('/'): # drop host part (validity of path checked below) url = '/' + url.split('/', 1)[1] if not url.startswith('https://') and not url.startswith( 'http://'): url = util.absolutepath(url) if not os.path.exists(url): raise PybrowserError('%s: not found' % url) if cygpath: url = util.pipeline(['cygpath', '-w', url]).rstrip() url = 'file://' + url return url
def kiosktest(self): '''Provides the path to an mbox file to store retrieved messages.''' if not self.ui.kiosk: self.ui.kiosk = tempfile.mkstemp(prefix='kiosk.')[1] return self.ui.kiosk = util.absolutepath(self.ui.kiosk) if (not os.path.exists(self.ui.kiosk) or not os.path.getsize(self.ui.kiosk)): # non existant or empty is fine return if not os.path.isfile(self.ui.kiosk): raise util.DeadMan('%s: not a regular file' % self.ui.kiosk) fp = open(self.ui.kiosk, 'rb') try: testline = fp.readline() finally: fp.close() try: p = email.Parser.Parser() check = p.parsestr(testline, headersonly=True) except email.Errors.HeaderParseError, inst: raise util.DeadMan(inst)
def urlcollect(self): '''Harvests urls from stdin or files.''' if not self.files: # stdin tempname = tempfile.mkstemp(prefix='urlcollector.')[1] fp = open(tempname, 'wb') try: fp.write(sys.stdin.read()) finally: fp.close() text = self.filedeconstructor(tempname) os.unlink(tempname) else: textlist = [] for fn in self.files: textlist.append(self.filedeconstructor(util.absolutepath(fn))) text = '\n'.join(textlist) if text: self.findurls(text) if self.ui.pat and self.items: try: ui_re = re.compile(r'%s' % self.ui.pat, re.IGNORECASE) except re.error as err: raise util.DeadMan("%s in pattern `%s'" % (err, self.ui.pat)) self.items = [i for i in self.items if ui_re.search(i)]
def urlcollect(self): '''Harvests urls from stdin or files.''' if not self.files: # stdin tempname = tempfile.mkstemp(prefix='urlcollector.')[1] fp = open(tempname, 'wb') try: fp.write(sys.stdin.read()) finally: fp.close() text = self.filedeconstructor(tempname) os.unlink(tempname) else: textlist = [] for fn in self.files: textlist.append(self.filedeconstructor(util.absolutepath(fn))) text = '\n'.join(textlist) if text: self.findurls(text) if self.ui.pat and self.items: try: ui_re = re.compile(r'%s' % self.ui.pat, re.IGNORECASE) except re.error, err: raise util.DeadMan("%s in pattern `%s'" % (err, self.ui.pat)) self.items = [i for i in self.items if ui_re.search(i)]