2012-07-13 23:47:06 +04:00
|
|
|
# sshpeer.py - ssh repository proxy class for mercurial
|
2005-08-28 01:21:25 +04:00
|
|
|
#
|
2006-08-12 23:30:02 +04:00
|
|
|
# Copyright 2005, 2006 Matt Mackall <mpm@selenic.com>
|
2005-08-28 01:21:25 +04:00
|
|
|
#
|
2009-04-26 03:08:54 +04:00
|
|
|
# This software may be used and distributed according to the terms of the
|
2010-01-20 07:20:08 +03:00
|
|
|
# GNU General Public License version 2 or any later version.
|
2005-08-28 01:21:25 +04:00
|
|
|
|
2015-08-09 05:55:01 +03:00
|
|
|
from __future__ import absolute_import
|
|
|
|
|
2011-12-08 19:39:00 +04:00
|
|
|
import re
|
2015-08-09 05:55:01 +03:00
|
|
|
|
|
|
|
from .i18n import _
|
|
|
|
from . import (
|
|
|
|
error,
|
2017-06-26 21:50:55 +03:00
|
|
|
pycompat,
|
2015-08-09 05:55:01 +03:00
|
|
|
util,
|
|
|
|
wireproto,
|
|
|
|
)
|
2005-08-28 01:21:25 +04:00
|
|
|
|
2011-11-26 03:10:31 +04:00
|
|
|
def _serverquote(s):
|
2014-12-29 23:27:02 +03:00
|
|
|
if not s:
|
|
|
|
return s
|
2011-11-26 03:10:31 +04:00
|
|
|
'''quote a string for the remote shell ... which we assume is sh'''
|
2011-12-09 18:50:33 +04:00
|
|
|
if re.match('[a-zA-Z0-9@%_+=:,./-]*$', s):
|
2011-12-08 19:39:00 +04:00
|
|
|
return s
|
2011-11-26 03:10:31 +04:00
|
|
|
return "'%s'" % s.replace("'", "'\\''")
|
|
|
|
|
2015-05-19 07:19:11 +03:00
|
|
|
def _forwardoutput(ui, pipe):
|
|
|
|
"""display all data currently available on pipe as remote output.
|
|
|
|
|
|
|
|
This is non blocking."""
|
|
|
|
s = util.readpipe(pipe)
|
|
|
|
if s:
|
|
|
|
for l in s.splitlines():
|
|
|
|
ui.status(_("remote: "), l, '\n')
|
|
|
|
|
2015-05-22 18:48:11 +03:00
|
|
|
class doublepipe(object):
|
|
|
|
"""Operate a side-channel pipe in addition of a main one
|
|
|
|
|
|
|
|
The side-channel pipe contains server output to be forwarded to the user
|
|
|
|
input. The double pipe will behave as the "main" pipe, but will ensure the
|
|
|
|
content of the "side" pipe is properly processed while we wait for blocking
|
|
|
|
call on the "main" pipe.
|
|
|
|
|
|
|
|
If large amounts of data are read from "main", the forward will cease after
|
|
|
|
the first bytes start to appear. This simplifies the implementation
|
|
|
|
without affecting actual output of sshpeer too much as we rarely issue
|
|
|
|
large read for data not yet emitted by the server.
|
|
|
|
|
|
|
|
The main pipe is expected to be a 'bufferedinputpipe' from the util module
|
2017-04-13 21:48:18 +03:00
|
|
|
that handle all the os specific bits. This class lives in this module
|
2015-10-17 01:58:46 +03:00
|
|
|
because it focus on behavior specific to the ssh protocol."""
|
2015-05-22 18:48:11 +03:00
|
|
|
|
|
|
|
def __init__(self, ui, main, side):
|
|
|
|
self._ui = ui
|
|
|
|
self._main = main
|
|
|
|
self._side = side
|
|
|
|
|
|
|
|
def _wait(self):
|
|
|
|
"""wait until some data are available on main or side
|
|
|
|
|
|
|
|
return a pair of boolean (ismainready, issideready)
|
|
|
|
|
|
|
|
(This will only wait for data if the setup is supported by `util.poll`)
|
|
|
|
"""
|
2015-06-05 14:54:23 +03:00
|
|
|
if getattr(self._main, 'hasbuffer', False): # getattr for classic pipe
|
2015-05-22 18:48:11 +03:00
|
|
|
return (True, True) # main has data, assume side is worth poking at.
|
|
|
|
fds = [self._main.fileno(), self._side.fileno()]
|
|
|
|
try:
|
|
|
|
act = util.poll(fds)
|
|
|
|
except NotImplementedError:
|
|
|
|
# non supported yet case, assume all have data.
|
|
|
|
act = fds
|
|
|
|
return (self._main.fileno() in act, self._side.fileno() in act)
|
|
|
|
|
2015-05-20 18:58:29 +03:00
|
|
|
def write(self, data):
|
|
|
|
return self._call('write', data)
|
|
|
|
|
2015-05-22 18:48:11 +03:00
|
|
|
def read(self, size):
|
2017-04-13 23:09:40 +03:00
|
|
|
r = self._call('read', size)
|
|
|
|
if size != 0 and not r:
|
|
|
|
# We've observed a condition that indicates the
|
|
|
|
# stdout closed unexpectedly. Check stderr one
|
|
|
|
# more time and snag anything that's there before
|
|
|
|
# letting anyone know the main part of the pipe
|
|
|
|
# closed prematurely.
|
|
|
|
_forwardoutput(self._ui, self._side)
|
|
|
|
return r
|
2015-05-22 18:48:11 +03:00
|
|
|
|
|
|
|
def readline(self):
|
|
|
|
return self._call('readline')
|
|
|
|
|
2015-05-21 01:40:47 +03:00
|
|
|
def _call(self, methname, data=None):
|
2015-05-22 18:48:11 +03:00
|
|
|
"""call <methname> on "main", forward output of "side" while blocking
|
|
|
|
"""
|
2015-05-21 01:40:47 +03:00
|
|
|
# data can be '' or 0
|
|
|
|
if (data is not None and not data) or self._main.closed:
|
2015-05-22 18:48:11 +03:00
|
|
|
_forwardoutput(self._ui, self._side)
|
|
|
|
return ''
|
|
|
|
while True:
|
|
|
|
mainready, sideready = self._wait()
|
|
|
|
if sideready:
|
|
|
|
_forwardoutput(self._ui, self._side)
|
|
|
|
if mainready:
|
|
|
|
meth = getattr(self._main, methname)
|
2015-05-21 01:40:47 +03:00
|
|
|
if data is None:
|
2015-05-22 18:48:11 +03:00
|
|
|
return meth()
|
|
|
|
else:
|
2015-05-21 01:40:47 +03:00
|
|
|
return meth(data)
|
2015-05-22 18:48:11 +03:00
|
|
|
|
|
|
|
def close(self):
|
|
|
|
return self._main.close()
|
|
|
|
|
2015-05-20 18:58:29 +03:00
|
|
|
def flush(self):
|
|
|
|
return self._main.flush()
|
|
|
|
|
2017-08-11 06:58:28 +03:00
|
|
|
class sshpeer(wireproto.wirepeer):
|
2011-05-18 21:30:17 +04:00
|
|
|
def __init__(self, ui, path, create=False):
|
2006-07-26 00:50:32 +04:00
|
|
|
self._url = path
|
2017-08-07 03:59:48 +03:00
|
|
|
self._ui = ui
|
2017-08-11 06:55:28 +03:00
|
|
|
self._pipeo = self._pipei = self._pipee = None
|
2005-08-28 01:21:25 +04:00
|
|
|
|
2011-04-30 20:43:20 +04:00
|
|
|
u = util.url(path, parsequery=False, parsefragment=False)
|
2011-03-31 07:01:35 +04:00
|
|
|
if u.scheme != 'ssh' or not u.host or u.path is None:
|
2010-07-15 02:07:13 +04:00
|
|
|
self._abort(error.RepoError(_("couldn't parse location %s") % path))
|
2005-08-28 01:21:25 +04:00
|
|
|
|
2017-08-02 00:40:19 +03:00
|
|
|
util.checksafessh(path)
|
|
|
|
|
2011-03-31 07:01:35 +04:00
|
|
|
if u.passwd is not None:
|
2011-02-23 13:42:41 +03:00
|
|
|
self._abort(error.RepoError(_("password in URL not supported")))
|
2017-08-11 06:55:28 +03:00
|
|
|
|
|
|
|
self._user = u.user
|
|
|
|
self._host = u.host
|
|
|
|
self._port = u.port
|
|
|
|
self._path = u.path or '.'
|
2005-08-28 01:21:25 +04:00
|
|
|
|
codemod: register core configitems using a script
This is done by a script [2] using RedBaron [1], a tool designed for doing
code refactoring. All "default" values are decided by the script and are
strongly consistent with the existing code.
There are 2 changes done manually to fix tests:
[warn] mercurial/exchange.py: experimental.bundle2-output-capture: default needs manual removal
[warn] mercurial/localrepo.py: experimental.hook-track-tags: default needs manual removal
Since RedBaron is not confident about how to indent things [2].
[1]: https://github.com/PyCQA/redbaron
[2]: https://github.com/PyCQA/redbaron/issues/100
[3]:
#!/usr/bin/env python
# codemod_configitems.py - codemod tool to fill configitems
#
# Copyright 2017 Facebook, Inc.
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
from __future__ import absolute_import, print_function
import os
import sys
import redbaron
def readpath(path):
with open(path) as f:
return f.read()
def writepath(path, content):
with open(path, 'w') as f:
f.write(content)
_configmethods = {'config', 'configbool', 'configint', 'configbytes',
'configlist', 'configdate'}
def extractstring(rnode):
"""get the string from a RedBaron string or call_argument node"""
while rnode.type != 'string':
rnode = rnode.value
return rnode.value[1:-1] # unquote, "'str'" -> "str"
def uiconfigitems(red):
"""match *.ui.config* pattern, yield (node, method, args, section, name)"""
for node in red.find_all('atomtrailers'):
entry = None
try:
obj = node[-3].value
method = node[-2].value
args = node[-1]
section = args[0].value
name = args[1].value
if (obj in ('ui', 'self') and method in _configmethods
and section.type == 'string' and name.type == 'string'):
entry = (node, method, args, extractstring(section),
extractstring(name))
except Exception:
pass
else:
if entry:
yield entry
def coreconfigitems(red):
"""match coreconfigitem(...) pattern, yield (node, args, section, name)"""
for node in red.find_all('atomtrailers'):
entry = None
try:
args = node[1]
section = args[0].value
name = args[1].value
if (node[0].value == 'coreconfigitem' and section.type == 'string'
and name.type == 'string'):
entry = (node, args, extractstring(section),
extractstring(name))
except Exception:
pass
else:
if entry:
yield entry
def registercoreconfig(cfgred, section, name, defaultrepr):
"""insert coreconfigitem to cfgred AST
section and name are plain string, defaultrepr is a string
"""
# find a place to insert the "coreconfigitem" item
entries = list(coreconfigitems(cfgred))
for node, args, nodesection, nodename in reversed(entries):
if (nodesection, nodename) < (section, name):
# insert after this entry
node.insert_after(
'coreconfigitem(%r, %r,\n'
' default=%s,\n'
')' % (section, name, defaultrepr))
return
def main(argv):
if not argv:
print('Usage: codemod_configitems.py FILES\n'
'For example, FILES could be "{hgext,mercurial}/*/**.py"')
dirname = os.path.dirname
reporoot = dirname(dirname(dirname(os.path.abspath(__file__))))
# register configitems to this destination
cfgpath = os.path.join(reporoot, 'mercurial', 'configitems.py')
cfgred = redbaron.RedBaron(readpath(cfgpath))
# state about what to do
registered = set((s, n) for n, a, s, n in coreconfigitems(cfgred))
toregister = {} # {(section, name): defaultrepr}
coreconfigs = set() # {(section, name)}, whether it's used in core
# first loop: scan all files before taking any action
for i, path in enumerate(argv):
print('(%d/%d) scanning %s' % (i + 1, len(argv), path))
iscore = ('mercurial' in path) and ('hgext' not in path)
red = redbaron.RedBaron(readpath(path))
# find all repo.ui.config* and ui.config* calls, and collect their
# section, name and default value information.
for node, method, args, section, name in uiconfigitems(red):
if section == 'web':
# [web] section has some weirdness, ignore them for now
continue
defaultrepr = None
key = (section, name)
if len(args) == 2:
if key in registered:
continue
if method == 'configlist':
defaultrepr = 'list'
elif method == 'configbool':
defaultrepr = 'False'
else:
defaultrepr = 'None'
elif len(args) >= 3 and (args[2].target is None or
args[2].target.value == 'default'):
# try to understand the "default" value
dnode = args[2].value
if dnode.type == 'name':
if dnode.value in {'None', 'True', 'False'}:
defaultrepr = dnode.value
elif dnode.type == 'string':
defaultrepr = repr(dnode.value[1:-1])
elif dnode.type in ('int', 'float'):
defaultrepr = dnode.value
# inconsistent default
if key in toregister and toregister[key] != defaultrepr:
defaultrepr = None
# interesting to rewrite
if key not in registered:
if defaultrepr is None:
print('[note] %s: %s.%s: unsupported default'
% (path, section, name))
registered.add(key) # skip checking it again
else:
toregister[key] = defaultrepr
if iscore:
coreconfigs.add(key)
# second loop: rewrite files given "toregister" result
for path in argv:
# reconstruct redbaron - trade CPU for memory
red = redbaron.RedBaron(readpath(path))
changed = False
for node, method, args, section, name in uiconfigitems(red):
key = (section, name)
defaultrepr = toregister.get(key)
if defaultrepr is None or key not in coreconfigs:
continue
if len(args) >= 3 and (args[2].target is None or
args[2].target.value == 'default'):
try:
del args[2]
changed = True
except Exception:
# redbaron fails to do the rewrite due to indentation
# see https://github.com/PyCQA/redbaron/issues/100
print('[warn] %s: %s.%s: default needs manual removal'
% (path, section, name))
if key not in registered:
print('registering %s.%s' % (section, name))
registercoreconfig(cfgred, section, name, defaultrepr)
registered.add(key)
if changed:
print('updating %s' % path)
writepath(path, red.dumps())
if toregister:
print('updating configitems.py')
writepath(cfgpath, cfgred.dumps())
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))
2017-07-15 00:22:40 +03:00
|
|
|
sshcmd = self.ui.config("ui", "ssh")
|
|
|
|
remotecmd = self.ui.config("ui", "remotecmd")
|
2006-07-01 06:24:02 +04:00
|
|
|
|
2017-08-11 06:55:28 +03:00
|
|
|
args = util.sshargs(sshcmd, self._host, self._user, self._port)
|
2007-12-13 01:44:26 +03:00
|
|
|
|
2006-07-01 06:24:02 +04:00
|
|
|
if create:
|
2011-11-26 03:10:31 +04:00
|
|
|
cmd = '%s %s %s' % (sshcmd, args,
|
|
|
|
util.shellquote("%s init %s" %
|
2017-08-11 06:55:28 +03:00
|
|
|
(_serverquote(remotecmd), _serverquote(self._path))))
|
2014-03-19 00:40:03 +04:00
|
|
|
ui.debug('running %s\n' % cmd)
|
2017-03-06 14:25:09 +03:00
|
|
|
res = ui.system(cmd, blockedtag='sshpeer')
|
2006-07-01 06:24:02 +04:00
|
|
|
if res != 0:
|
2010-07-15 02:07:13 +04:00
|
|
|
self._abort(error.RepoError(_("could not create remote repo")))
|
2006-07-01 06:24:02 +04:00
|
|
|
|
2013-07-16 20:18:16 +04:00
|
|
|
self._validaterepo(sshcmd, args, remotecmd)
|
2006-07-01 06:24:02 +04:00
|
|
|
|
2017-08-07 03:59:48 +03:00
|
|
|
# Begin of _basepeer interface.
|
|
|
|
|
|
|
|
@util.propertycache
|
|
|
|
def ui(self):
|
|
|
|
return self._ui
|
|
|
|
|
2006-07-26 00:50:32 +04:00
|
|
|
def url(self):
|
|
|
|
return self._url
|
|
|
|
|
2017-08-07 03:59:48 +03:00
|
|
|
def local(self):
|
|
|
|
return None
|
|
|
|
|
|
|
|
def peer(self):
|
|
|
|
return self
|
|
|
|
|
|
|
|
def canpush(self):
|
|
|
|
return True
|
|
|
|
|
|
|
|
def close(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
# End of _basepeer interface.
|
|
|
|
|
|
|
|
# Begin of _basewirecommands interface.
|
|
|
|
|
|
|
|
def capabilities(self):
|
|
|
|
return self._caps
|
|
|
|
|
|
|
|
# End of _basewirecommands interface.
|
|
|
|
|
2013-07-16 20:18:16 +04:00
|
|
|
def _validaterepo(self, sshcmd, args, remotecmd):
|
2006-09-02 23:08:54 +04:00
|
|
|
# cleanup up previous run
|
2017-08-11 06:55:28 +03:00
|
|
|
self._cleanup()
|
2006-09-02 23:08:54 +04:00
|
|
|
|
2011-11-26 03:10:31 +04:00
|
|
|
cmd = '%s %s %s' % (sshcmd, args,
|
|
|
|
util.shellquote("%s -R %s serve --stdio" %
|
2017-08-11 06:55:28 +03:00
|
|
|
(_serverquote(remotecmd), _serverquote(self._path))))
|
2014-03-19 00:40:03 +04:00
|
|
|
self.ui.debug('running %s\n' % cmd)
|
2011-11-26 03:10:31 +04:00
|
|
|
cmd = util.quotecommand(cmd)
|
2013-03-09 04:59:36 +04:00
|
|
|
|
2017-08-11 06:55:28 +03:00
|
|
|
# while self._subprocess isn't used, having it allows the subprocess to
|
2013-03-09 04:59:36 +04:00
|
|
|
# to clean up correctly later
|
2015-05-20 19:31:38 +03:00
|
|
|
#
|
|
|
|
# no buffer allow the use of 'select'
|
|
|
|
# feel free to remove buffering and select usage when we ultimately
|
|
|
|
# move to threading.
|
|
|
|
sub = util.popen4(cmd, bufsize=0)
|
2017-08-11 06:55:28 +03:00
|
|
|
self._pipeo, self._pipei, self._pipee, self._subprocess = sub
|
2005-08-28 01:21:25 +04:00
|
|
|
|
2017-08-11 06:55:28 +03:00
|
|
|
self._pipei = util.bufferedinputpipe(self._pipei)
|
|
|
|
self._pipei = doublepipe(self.ui, self._pipei, self._pipee)
|
|
|
|
self._pipeo = doublepipe(self.ui, self._pipeo, self._pipee)
|
2015-05-31 10:00:36 +03:00
|
|
|
|
2017-09-12 01:59:18 +03:00
|
|
|
def badresponse():
|
|
|
|
self._abort(error.RepoError(_('no suitable response from '
|
|
|
|
'remote hg')))
|
|
|
|
|
|
|
|
try:
|
|
|
|
# skip any noise generated by remote shell
|
|
|
|
self._callstream("hello")
|
|
|
|
r = self._callstream("between", pairs=("%s-%s" % ("0"*40, "0"*40)))
|
|
|
|
except IOError:
|
|
|
|
badresponse()
|
|
|
|
|
2006-06-10 02:48:14 +04:00
|
|
|
lines = ["", "dummy"]
|
2006-04-04 17:21:20 +04:00
|
|
|
max_noise = 500
|
2006-06-10 02:48:14 +04:00
|
|
|
while lines[-1] and max_noise:
|
2017-09-12 01:59:18 +03:00
|
|
|
try:
|
|
|
|
l = r.readline()
|
|
|
|
self._readerr()
|
|
|
|
if lines[-1] == "1\n" and l == "\n":
|
|
|
|
break
|
|
|
|
if l:
|
|
|
|
self.ui.debug("remote: ", l)
|
|
|
|
lines.append(l)
|
|
|
|
max_noise -= 1
|
|
|
|
except IOError:
|
|
|
|
badresponse()
|
2006-04-03 00:12:56 +04:00
|
|
|
else:
|
2017-09-12 01:59:18 +03:00
|
|
|
badresponse()
|
2006-03-31 13:25:35 +04:00
|
|
|
|
2012-07-13 23:47:06 +04:00
|
|
|
self._caps = set()
|
2009-04-27 01:50:44 +04:00
|
|
|
for l in reversed(lines):
|
2006-06-10 03:03:35 +04:00
|
|
|
if l.startswith("capabilities:"):
|
2012-07-13 23:47:06 +04:00
|
|
|
self._caps.update(l[:-1].split(":")[1].split())
|
2006-06-10 03:03:35 +04:00
|
|
|
break
|
|
|
|
|
2017-08-11 06:55:28 +03:00
|
|
|
def _readerr(self):
|
|
|
|
_forwardoutput(self.ui, self._pipee)
|
2005-08-28 01:21:25 +04:00
|
|
|
|
2010-07-15 01:34:57 +04:00
|
|
|
def _abort(self, exception):
|
2017-08-11 06:55:28 +03:00
|
|
|
self._cleanup()
|
2010-07-15 01:34:57 +04:00
|
|
|
raise exception
|
|
|
|
|
2017-08-11 06:55:28 +03:00
|
|
|
def _cleanup(self):
|
|
|
|
if self._pipeo is None:
|
2012-05-12 18:02:45 +04:00
|
|
|
return
|
2017-08-11 06:55:28 +03:00
|
|
|
self._pipeo.close()
|
|
|
|
self._pipei.close()
|
2005-08-28 01:21:25 +04:00
|
|
|
try:
|
2005-09-28 02:23:34 +04:00
|
|
|
# read the error descriptor until EOF
|
2017-08-11 06:55:28 +03:00
|
|
|
for l in self._pipee:
|
2005-10-19 05:38:39 +04:00
|
|
|
self.ui.status(_("remote: "), l)
|
2012-05-12 18:02:45 +04:00
|
|
|
except (IOError, ValueError):
|
2005-08-28 01:21:25 +04:00
|
|
|
pass
|
2017-08-11 06:55:28 +03:00
|
|
|
self._pipee.close()
|
2005-08-28 01:21:25 +04:00
|
|
|
|
2017-08-11 06:55:28 +03:00
|
|
|
__del__ = _cleanup
|
2006-09-02 23:08:54 +04:00
|
|
|
|
2016-03-02 02:41:43 +03:00
|
|
|
def _submitbatch(self, req):
|
2016-08-06 23:46:28 +03:00
|
|
|
rsp = self._callstream("batch", cmds=wireproto.encodebatchcmds(req))
|
2016-03-02 02:41:43 +03:00
|
|
|
available = self._getamount()
|
|
|
|
# TODO this response parsing is probably suboptimal for large
|
|
|
|
# batches with large responses.
|
|
|
|
toread = min(available, 1024)
|
|
|
|
work = rsp.read(toread)
|
|
|
|
available -= toread
|
|
|
|
chunk = work
|
|
|
|
while chunk:
|
|
|
|
while ';' in work:
|
|
|
|
one, work = work.split(';', 1)
|
|
|
|
yield wireproto.unescapearg(one)
|
|
|
|
toread = min(available, 1024)
|
|
|
|
chunk = rsp.read(toread)
|
|
|
|
available -= toread
|
|
|
|
work += chunk
|
|
|
|
yield wireproto.unescapearg(work)
|
|
|
|
|
2010-07-15 02:07:10 +04:00
|
|
|
def _callstream(self, cmd, **args):
|
2017-06-26 21:50:55 +03:00
|
|
|
args = pycompat.byteskwargs(args)
|
2009-09-19 03:15:38 +04:00
|
|
|
self.ui.debug("sending %s command\n" % cmd)
|
2017-08-11 06:55:28 +03:00
|
|
|
self._pipeo.write("%s\n" % cmd)
|
2011-03-22 09:38:32 +03:00
|
|
|
_func, names = wireproto.commands[cmd]
|
|
|
|
keys = names.split()
|
|
|
|
wireargs = {}
|
|
|
|
for k in keys:
|
|
|
|
if k == '*':
|
|
|
|
wireargs['*'] = args
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
wireargs[k] = args[k]
|
|
|
|
del args[k]
|
|
|
|
for k, v in sorted(wireargs.iteritems()):
|
2017-08-11 06:55:28 +03:00
|
|
|
self._pipeo.write("%s %d\n" % (k, len(v)))
|
2011-03-22 09:38:32 +03:00
|
|
|
if isinstance(v, dict):
|
|
|
|
for dk, dv in v.iteritems():
|
2017-08-11 06:55:28 +03:00
|
|
|
self._pipeo.write("%s %d\n" % (dk, len(dv)))
|
|
|
|
self._pipeo.write(dv)
|
2011-03-22 09:38:32 +03:00
|
|
|
else:
|
2017-08-11 06:55:28 +03:00
|
|
|
self._pipeo.write(v)
|
|
|
|
self._pipeo.flush()
|
2005-08-28 01:21:25 +04:00
|
|
|
|
2017-08-11 06:55:28 +03:00
|
|
|
return self._pipei
|
2005-08-28 01:21:25 +04:00
|
|
|
|
2014-03-29 01:24:13 +04:00
|
|
|
def _callcompressable(self, cmd, **args):
|
|
|
|
return self._callstream(cmd, **args)
|
|
|
|
|
2010-07-15 01:34:57 +04:00
|
|
|
def _call(self, cmd, **args):
|
2010-07-15 02:07:10 +04:00
|
|
|
self._callstream(cmd, **args)
|
2010-07-15 01:34:57 +04:00
|
|
|
return self._recv()
|
|
|
|
|
2010-07-15 02:12:18 +04:00
|
|
|
def _callpush(self, cmd, fp, **args):
|
|
|
|
r = self._call(cmd, **args)
|
|
|
|
if r:
|
|
|
|
return '', r
|
2016-08-05 21:00:22 +03:00
|
|
|
for d in iter(lambda: fp.read(4096), ''):
|
2010-07-15 02:12:18 +04:00
|
|
|
self._send(d)
|
|
|
|
self._send("", flush=True)
|
|
|
|
r = self._recv()
|
|
|
|
if r:
|
|
|
|
return '', r
|
|
|
|
return self._recv(), ''
|
|
|
|
|
2014-04-16 01:18:35 +04:00
|
|
|
def _calltwowaystream(self, cmd, fp, **args):
|
|
|
|
r = self._call(cmd, **args)
|
|
|
|
if r:
|
|
|
|
# XXX needs to be made better
|
2016-06-14 12:53:55 +03:00
|
|
|
raise error.Abort(_('unexpected remote reply: %s') % r)
|
2016-08-05 21:00:22 +03:00
|
|
|
for d in iter(lambda: fp.read(4096), ''):
|
2014-04-16 01:18:35 +04:00
|
|
|
self._send(d)
|
|
|
|
self._send("", flush=True)
|
2017-08-11 06:55:28 +03:00
|
|
|
return self._pipei
|
2010-07-15 02:09:31 +04:00
|
|
|
|
2016-03-02 02:41:43 +03:00
|
|
|
def _getamount(self):
|
2017-08-11 06:55:28 +03:00
|
|
|
l = self._pipei.readline()
|
2011-08-02 23:21:10 +04:00
|
|
|
if l == '\n':
|
2017-08-11 06:55:28 +03:00
|
|
|
self._readerr()
|
2015-05-20 20:33:12 +03:00
|
|
|
msg = _('check previous remote output')
|
|
|
|
self._abort(error.OutOfBandError(hint=msg))
|
2017-08-11 06:55:28 +03:00
|
|
|
self._readerr()
|
2005-08-28 01:21:25 +04:00
|
|
|
try:
|
2016-03-02 02:41:43 +03:00
|
|
|
return int(l)
|
2011-04-23 01:51:25 +04:00
|
|
|
except ValueError:
|
2010-07-15 02:07:13 +04:00
|
|
|
self._abort(error.ResponseError(_("unexpected response:"), l))
|
2016-03-02 02:41:43 +03:00
|
|
|
|
|
|
|
def _recv(self):
|
2017-08-11 06:55:28 +03:00
|
|
|
return self._pipei.read(self._getamount())
|
2008-02-04 02:03:46 +03:00
|
|
|
|
|
|
|
def _send(self, data, flush=False):
|
2017-08-11 06:55:28 +03:00
|
|
|
self._pipeo.write("%d\n" % len(data))
|
2008-02-04 02:03:46 +03:00
|
|
|
if data:
|
2017-08-11 06:55:28 +03:00
|
|
|
self._pipeo.write(data)
|
2008-02-04 02:03:46 +03:00
|
|
|
if flush:
|
2017-08-11 06:55:28 +03:00
|
|
|
self._pipeo.flush()
|
|
|
|
self._readerr()
|
2005-08-28 01:21:25 +04:00
|
|
|
|
2012-07-13 23:47:06 +04:00
|
|
|
instance = sshpeer
|