def quotepath(path): '''quote the path part of a URL This is similar to urllib.quote, but it also tries to avoid quoting things twice (inspired by wget): >>> quotepath('abc def') 'abc%20def' >>> quotepath('abc%20def') 'abc%20def' >>> quotepath('abc%20 def') 'abc%20%20def' >>> quotepath('abc def%20') 'abc%20def%20' >>> quotepath('abc def%2') 'abc%20def%252' >>> quotepath('abc def%') 'abc%20def%25' ''' global _safeset, _hex if _safeset is None: _safeset = util.set(_safe) _hex = util.set('abcdefABCDEF0123456789') l = list(path) for i in xrange(len(l)): c = l[i] if c == '%' and i + 2 < len(l) and (l[i + 1] in _hex and l[i + 2] in _hex): pass elif c not in _safeset: l[i] = '%%%02X' % ord(c) return ''.join(l)
def quotepath(path): '''quote the path part of a URL This is similar to urllib.quote, but it also tries to avoid quoting things twice (inspired by wget): >>> quotepath('abc def') 'abc%20def' >>> quotepath('abc%20def') 'abc%20def' >>> quotepath('abc%20 def') 'abc%20%20def' >>> quotepath('abc def%20') 'abc%20def%20' >>> quotepath('abc def%2') 'abc%20def%252' >>> quotepath('abc def%') 'abc%20def%25' ''' global _safeset, _hex if _safeset is None: _safeset = util.set(_safe) _hex = util.set('abcdefABCDEF0123456789') l = list(path) for i in xrange(len(l)): c = l[i] if c == '%' and i + 2 < len(l) and (l[i+1] in _hex and l[i+2] in _hex): pass elif c not in _safeset: l[i] = '%%%02X' % ord(c) return ''.join(l)
def get_caps(self): if self.caps is None: try: self.caps = util.set(self.do_read('capabilities').split()) except repo.RepoError: self.caps = util.set() self.ui.debug( _('capabilities: %s\n') % (' '.join(self.caps or ['none']))) return self.caps
def get_caps(self): if self.caps is None: try: self.caps = util.set(self.do_read('capabilities').split()) except repo.RepoError: self.caps = util.set() self.ui.debug(_('capabilities: %s\n') % (' '.join(self.caps or ['none']))) return self.caps
def validate_repo(self, ui, sshcmd, args, remotecmd): # cleanup up previous run self.cleanup() cmd = '%s %s "%s -R %s serve --stdio"' cmd = cmd % (sshcmd, args, remotecmd, self.path) cmd = util.quotecommand(cmd) ui.note(_('running %s\n') % cmd) self.pipeo, self.pipei, self.pipee = util.popen3(cmd, 'b') # skip any noise generated by remote shell self.do_cmd("hello") r = self.do_cmd("between", pairs=("%s-%s" % ("0"*40, "0"*40))) lines = ["", "dummy"] max_noise = 500 while lines[-1] and max_noise: l = r.readline() self.readerr() if lines[-1] == "1\n" and l == "\n": break if l: ui.debug(_("remote: "), l) lines.append(l) max_noise -= 1 else: self.abort(error.RepoError(_("no suitable response from remote hg"))) self.capabilities = util.set() lines.reverse() for l in lines: if l.startswith("capabilities:"): self.capabilities.update(l[:-1].split(":")[1].split()) break
def validate_repo(self, ui, sshcmd, args, remotecmd): # cleanup up previous run self.cleanup() cmd = '%s %s "%s -R %s serve --stdio"' cmd = cmd % (sshcmd, args, remotecmd, self.path) cmd = util.quotecommand(cmd) ui.note('running %s\n' % cmd) self.pipeo, self.pipei, self.pipee = os.popen3(cmd, 'b') # skip any noise generated by remote shell self.do_cmd("hello") r = self.do_cmd("between", pairs=("%s-%s" % ("0"*40, "0"*40))) lines = ["", "dummy"] max_noise = 500 while lines[-1] and max_noise: l = r.readline() self.readerr() if lines[-1] == "1\n" and l == "\n": break if l: ui.debug(_("remote: "), l) lines.append(l) max_noise -= 1 else: self.raise_(repo.RepoError(_("no suitable response from remote hg"))) self.capabilities = util.set() lines.reverse() for l in lines: if l.startswith("capabilities:"): self.capabilities.update(l[:-1].split(":")[1].split()) break
def descendants(self, *revs): 'Generate the descendants of revs in topological order' seen = util.set(revs) for i in xrange(min(revs) + 1, len(self)): for x in self.parentrevs(i): if x != nullrev and x in seen: seen.add(i) yield i break
def ancestors(self, *revs): 'Generate the ancestors of revs using a breadth-first visit' visit = list(revs) seen = util.set([nullrev]) while visit: for parent in self.parentrevs(visit.pop(0)): if parent not in seen: visit.append(parent) seen.add(parent) yield parent
def handle_read(self): data = self.recv(1024) if data == '': self.handle_close() return log.l.LogIt('RTC006', 'D', 'cmd i: %s', (data)) args = string.split(data) if len(args) == 0: return; self.mode = args[0] self.target = args[1] args = args[2:] log.l.LogIt('RTC007', '1', '%s', (str(args))) if len(args) == 0: return #-------------------- if args[0] == 'close': self.senddata.append(util.close(self.mode == 'router', self.target, args[1:])) #-------------------- elif args[0] == 'data': if self.mode == 'domain': self.senddata.append('command: '+args[0]+': address only to router') if self.mode == 'router': self.senddata.append(util.data(args[1:])) elif args[0] == 'dump': if self.mode == 'domain': self.senddata.append('command: '+args[0]+': address only to router') if self.mode == 'router': self.senddata.append(util.dump()) #-------------------- elif args[0] == 'event': if self.mode == 'domain': self.senddata.append('command: '+args[0]+': address only to router') if self.mode == 'router': self.senddata.append(util.event(args[1:])) #-------------------- elif args[0] == 'fb' or args[0] == 'fallback' or args[0] == 'secondary': if len(args) > 1 and args[1] == 'auto': auto = 1 else: auto = 0 if self.mode == 'domain': cfg.domain[self.target]['fallback'] = 1 self.senddata.append(util.switch_secondary(self.target, auto)) if self.mode == 'router': for i in cfg.domain.keys(): if cfg.domain[i]['apr'] == cfg.name: cfg.domain[i]['fallback'] = 1 self.senddata.append(i+' '+util.switch_secondary(i, auto)) #-------------------- elif args[0] == 'ff' or args[0] == 'fallforward' or args[0] == 'primary': if len(args) > 1 and args[1] == 'auto': auto = 1 else: auto = 0 if self.mode == 'domain': cfg.domain[self.target]['fallback'] = 0 self.senddata.append(util.switch_primary(self.target, auto)) if self.mode == 'router': for i in cfg.domain.keys(): if cfg.domain[i]['apr'] == cfg.name: cfg.domain[i]['fallback'] = 0 self.senddata.append(i+' '+util.switch_primary(i, auto)) #-------------------- elif args[0] == 'pvc': if self.mode == 'domain': self.senddata.append('command: '+args[0]+': address only to router') if self.mode == 'router': self.senddata.append(util.pvc(args[1:])) #-------------------- elif args[0] == 'refresh': evt_hdlr.refresh() self.senddata.append('status refreshed') #-------------------- elif args[0] == 'set': self.senddata = util.set(self.mode == 'router', self.target, args[1:]) #-------------------- elif args[0] == 'sna': if self.mode == 'domain': self.senddata.append('command: '+args[0]+': address only to router') if self.mode == 'router': self.senddata.append(util.sna(args[1:])) #-------------------- elif args[0] == 'status': if self.mode == 'domain': self.senddata.append(util.status(self.target)) if self.mode == 'router': for i in cfg.domain.keys(): if cfg.domain[i]['apr'] == cfg.name: self.senddata.append(i+' '+util.status(i)) if len(self.senddata) == 0: self.senddata.append('not active') #-------------------- elif args[0] == 'stop': if self.mode == 'domain': self.senddata.append('command: '+args[0]+': address only to router') if self.mode == 'router': log.l.LogIt('RTC008', 'I', 'command termination', ()) cfg.stopping = 1 msg = '%s terminating' % self.target self.senddata.append(msg) for i in cfg.domain.keys(): util.closeall(i) #-------------------- elif args[0] == 'trace': if self.mode == 'domain': self.senddata.append('command: '+args[0]+': address only to router') if self.mode == 'router': if len(args) > 1: log.l.SetTraceLevel(int(args[1])) self.senddata.append('trace level %s' % (args[1])) log.l.LogIt('RTC009', 'I', 'command trace %s', (args[1])) else: level = log.l.GetTraceLevel() self.senddata.append('trace level %d' % (level)) log.l.LogIt('RTC010', 'I', 'command get trace: %d', (level)) #-------------------- elif args[0] == 'version': msg = ver.getVersion() if cfg.snasrv_version != '': msg = msg + ' snasrv: ' + cfg.snasrv_version self.senddata.append(msg) #-------------------- else: self.senddata.append('command: '+args[0]+': not implemented')