def urlvisit(self): '''Visit url(s).''' textbrowsers = 'w3m', 'lynx', 'links', 'elinks' cygwin = util.cygwin() app, tb, cygpath, notty, screen = '', False, False, False, False if self.ui.app is not None: app = os.path.basename(self.ui.app) tb = app in textbrowsers if tb: notty = not util.termconnected() screen = 'STY' in os.environ elif cygwin: # do we have to call cygpath to transform local path to windows # file system path? cygpath = (self.ui.app.find('/cygdrive/') == 0 and self.ui.app.find('/Cygwin/') < 0) elif cygwin: #cygpath = True # not tested yet, err on safe side hint = 'set the $BROWSER environment variable explicitly on cygwin' raise util.DeadMan('cannot detect system browser', hint=hint) if not self.items: self.items = [self.ui.configitem('net', 'homepage')] self.items = [self.fixurl(url, cygpath) for url in self.items] # w3m does not need to be connected to terminal # but has to be connected if called into another screen instance if screen or app in textbrowsers[1:] and notty: for url in self.items: util.systemcall([self.ui.app, url], notty, screen) else: try: b = webbrowser.get(self.ui.app) for url in self.items: b.open(url) except webbrowser.Error, inst: raise util.DeadMan(inst)
def urlretrieval(self, mail): url, cs, cwd = self.items[0], [], '' if mail: cs = [self.mailer] elif self.ui.proto == 'ftp' or urlregex.ftpcheck(url): if self.ui.ftpdir: # otherwise eventual download to cwd self.ui.ftpdir = util.savedir(self.ui.ftpdir) cwd = os.getcwdu() os.chdir(self.ui.ftpdir) cs = [self.ui.configitem('net', 'ftpclient', default='ftp')] # for ftp programs that have more of a browser interface # we assume a file if url has a file extension if os.path.splitext(url)[1]: exe = os.path.split(cs[0])[-1] if exe == 'lftp': # lftp needs an optional command cs += ['-c', 'get'] elif exe == 'ncftp': # use ncftpget instead cs = ['%sget' % cs[0]] if not cs and not self.ui.getdir: b = pybrowser.browser(parentui=self.ui, items=self.items) b.urlvisit() elif self.ui.getdir: uget = wget.wget(self.ui) uget.download([url]) else: cs += [url] util.systemcall(cs) if cwd: os.chdir(cwd)
def urlvisit(self): '''Visit url(s).''' textbrowsers = 'w3m', 'lynx', 'links', 'elinks' notty, screen, cygwin = False, False, util.cygwin() tb = self.appname in textbrowsers if tb: notty = not util.termconnected() screen = 'STY' in os.environ cygpath = self.cygpath(tb, cygwin) if not self.items: self.items = [self.ui.configitem('net', 'homepage')] self.items = [self.fixurl(url, cygpath) for url in self.items] # w3m does not need to be connected to terminal # but has to be connected if called into another screen instance if screen or self.appname in textbrowsers[1:] and notty: for url in self.items: util.systemcall([self.ui.app.name, url], notty, screen) else: for url in self.items: if not self.ui.app.open(url) and not cygwin: # BROWSER=invalid gives valid # webbrowser.GenericBrowser instance # but returns False # disable check for cygwin as valid # graphical browser instances return False too raise PybrowserError
def openkiosk(self, firstid): '''Opens mutt on kiosk mailbox.''' fp = open(self.ui.kiosk, 'ab') try: g = email.Generator.Generator(fp, maxheaderlen=0) for msg in self.msgs: # delete read status and local server info for h in ('status', 'xref'): del msg[h] if not msg.get_unixfrom(): msg = _mkunixfrom(msg) g.flatten(msg, unixfrom=True) finally: fp.close() mailer = self.ui.configitem('messages', 'mailer', default='mutt') cs = [mailer] if mailer[:4] == 'mutt': if len(self.msgs) == 1 and self.muttone: cs += ["-e", "'set pager_index_lines=0'", "-e", "'set quit=yes'", "-e", "'bind pager q quit'", "-e", "'push <return>'"] else: cs += ["-e", "'set uncollapse_jump'", "-e" "'push <search>~i\ \'%s\'<return>'" % firstid] cs += ['-f', self.ui.kiosk] util.systemcall(cs)