예제 #1
0
 def __init__(self, remote, create=False, compression_level=1):
     self._busy = self.conn = None
     self.sock = self.p = self.pout = self.pin = None
     self.compression_level = compression_level
     is_reverse = os.environ.get('BUP_SERVER_REVERSE')
     if is_reverse:
         assert (not remote)
         remote = '%s:' % is_reverse
     (self.protocol, self.host, self.port, self.dir) = parse_remote(remote)
     self.cachedir = git.repo('index-cache/%s' %
                              re.sub(r'[^@\w]', '_', "%s:%s" %
                                     (self.host, self.dir)))
     if is_reverse:
         self.pout = os.fdopen(3, 'rb')
         self.pin = os.fdopen(4, 'wb')
         self.conn = Conn(self.pout, self.pin)
     else:
         if self.protocol in ('ssh', 'file'):
             try:
                 # FIXME: ssh and file shouldn't use the same module
                 self.p = ssh.connect(self.host, self.port, 'server')
                 self.pout = self.p.stdout
                 self.pin = self.p.stdin
                 self.conn = Conn(self.pout, self.pin)
             except OSError, e:
                 raise ClientError, 'connect: %s' % e, sys.exc_info()[2]
         elif self.protocol == 'bup':
             self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
             self.sock.connect((self.host, atoi(self.port) or 1982))
             self.sockw = self.sock.makefile('wb')
             self.conn = DemuxConn(self.sock.fileno(), self.sockw)
예제 #2
0
 def __init__(self, remote, create=False):
     self._busy = self.conn = None
     self.sock = self.p = self.pout = self.pin = None
     is_reverse = os.environ.get('BUP_SERVER_REVERSE')
     if is_reverse:
         assert(not remote)
         remote = '%s:' % is_reverse
     (self.protocol, self.host, self.port, self.dir) = parse_remote(remote)
     self.cachedir = git.repo('index-cache/%s'
                              % re.sub(r'[^@\w]', '_', 
                                       "%s:%s" % (self.host, self.dir)))
     if is_reverse:
         self.pout = os.fdopen(3, 'rb')
         self.pin = os.fdopen(4, 'wb')
         self.conn = Conn(self.pout, self.pin)
     else:
         if self.protocol in ('ssh', 'file'):
             try:
                 # FIXME: ssh and file shouldn't use the same module
                 self.p = ssh.connect(self.host, self.port, 'server')
                 self.pout = self.p.stdout
                 self.pin = self.p.stdin
                 self.conn = Conn(self.pout, self.pin)
             except OSError, e:
                 raise ClientError, 'connect: %s' % e, sys.exc_info()[2]
         elif self.protocol == 'bup':
             self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
             self.sock.connect((self.host, atoi(self.port) or 1982))
             self.sockw = self.sock.makefile('wb')
             self.conn = DemuxConn(self.sock.fileno(), self.sockw)
예제 #3
0
파일: client.py 프로젝트: maw/bup
 def __init__(self, remote, create=False):
     self._busy = self.conn = self.p = self.pout = self.pin = None
     is_reverse = os.environ.get('BUP_SERVER_REVERSE')
     if is_reverse:
         assert(not remote)
         remote = '%s:' % is_reverse
     rs = remote.split(':', 1)
     if len(rs) == 1:
         (host, dir) = (None, remote)
     else:
         (host, dir) = rs
     (self.host, self.dir) = (host, dir)
     self.cachedir = git.repo('index-cache/%s'
                              % re.sub(r'[^@\w]', '_', 
                                       "%s:%s" % (host, dir)))
     try:
         if is_reverse:
             self.pout = os.fdopen(3, 'rb')
             self.pin = os.fdopen(4, 'wb')
         else:
             self.p = ssh.connect(host, 'server')
             self.pout = self.p.stdout
             self.pin = self.p.stdin
     except OSError, e:
         raise ClientError, 'exec %r: %s' % (argv[0], e), sys.exc_info()[2]
예제 #4
0
 def __init__(self, remote, create=False):
     self.closed = False
     self._busy = self.conn = None
     self.sock = self.p = self.pout = self.pin = None
     try:
         is_reverse = environ.get(b'BUP_SERVER_REVERSE')
         if is_reverse:
             assert(not remote)
             remote = b'%s:' % is_reverse
         (self.protocol, self.host, self.port, self.dir) = parse_remote(remote)
         # The b'None' here matches python2's behavior of b'%s' % None == 'None',
         # python3 will (as of version 3.7.5) do the same for str ('%s' % None),
         # but crashes instead when doing b'%s' % None.
         cachehost = b'None' if self.host is None else self.host
         cachedir = b'None' if self.dir is None else self.dir
         self.cachedir = git.repo(b'index-cache/%s'
                                  % re.sub(br'[^@\w]',
                                           b'_',
                                           b'%s:%s' % (cachehost, cachedir)))
         if is_reverse:
             self.pout = os.fdopen(3, 'rb')
             self.pin = os.fdopen(4, 'wb')
             self.conn = Conn(self.pout, self.pin)
         else:
             if self.protocol in (b'ssh', b'file'):
                 try:
                     # FIXME: ssh and file shouldn't use the same module
                     self.p = ssh.connect(self.host, self.port, b'server')
                     self.pout = self.p.stdout
                     self.pin = self.p.stdin
                     self.conn = Conn(self.pout, self.pin)
                 except OSError as e:
                     reraise(ClientError('connect: %s' % e))
             elif self.protocol == b'bup':
                 self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                 self.sock.connect((self.host,
                                    1982 if self.port is None else int(self.port)))
                 self.sockw = self.sock.makefile('wb')
                 self.conn = DemuxConn(self.sock.fileno(), self.sockw)
         self._available_commands = self._get_available_commands()
         self._require_command(b'init-dir')
         self._require_command(b'set-dir')
         if self.dir:
             self.dir = re.sub(br'[\r\n]', ' ', self.dir)
             if create:
                 self.conn.write(b'init-dir %s\n' % self.dir)
             else:
                 self.conn.write(b'set-dir %s\n' % self.dir)
             self.check_ok()
         self.sync_indexes()
     except BaseException as ex:
         with pending_raise(ex):
             self.close()
예제 #5
0
파일: client.py 프로젝트: jmberg/bup
    def __init__(self, remote, create=False):
        self._busy = self.conn = None
        self.sock = self.p = self.pout = self.pin = None
        (self.protocol, self.host, self.port, self.dir) = parse_remote(remote)
        if self.protocol == b'reverse':
            self.pout = os.fdopen(3, 'rb')
            self.pin = os.fdopen(4, 'wb')
            self.conn = Conn(self.pout, self.pin)
        if self.protocol in (b'ssh', b'file'):
            try:
                # FIXME: ssh and file shouldn't use the same module
                self.p = ssh.connect(self.host, self.port, b'server')
                self.pout = self.p.stdout
                self.pin = self.p.stdin
                self.conn = Conn(self.pout, self.pin)
            except OSError as e:
                reraise(ClientError('connect: %s' % e))
        elif self.protocol == b'bup':
            self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            self.sock.connect((self.host,
                               1982 if self.port is None else int(self.port)))
            self.sockw = self.sock.makefile('wb')
            self.conn = DemuxConn(self.sock.fileno(), self.sockw)
        self._available_commands = self._get_available_commands()
        self._require_command(b'init-dir')
        self._require_command(b'set-dir')
        if self.dir:
            self.dir = re.sub(br'[\r\n]', ' ', self.dir)
            if create:
                self.conn.write(b'init-dir %s\n' % self.dir)
            else:
                self.conn.write(b'set-dir %s\n' % self.dir)
            self.check_ok()

        # Set up the index-cache directory, prefer using the repo-id
        # if the remote repo has one (that can be accessed)
        repo_id = self.config(b'bup.repo-id')
        if repo_id is not None:
            self.cachedir = path.cachedir(repo_id)
        else:
            # The b'None' here matches python2's behavior of b'%s' % None == 'None',
            # python3 will (as of version 3.7.5) do the same for str ('%s' % None),
            # but crashes instead when doing b'%s' % None.
            cachehost = b'None' if self.host is None else self.host
            cachedir = b'None' if self.dir is None else self.dir
            self.cachedir = path.cachedir(re.sub(br'[^@\w]',
                                                 b'_',
                                                 b'%s:%s' % (cachehost, cachedir)))

        self.sync_indexes()
예제 #6
0
파일: client.py 프로젝트: kronenpj/bup
 def __init__(self, remote, create=False):
     self._busy = self.conn = None
     self.sock = self.p = self.pout = self.pin = None
     is_reverse = os.environ.get("BUP_SERVER_REVERSE")
     if is_reverse:
         assert not remote
         remote = "%s:" % is_reverse
     (self.protocol, self.host, self.port, self.dir) = parse_remote(remote)
     self.cachedir = git.repo("index-cache/%s" % re.sub(r"[^@\w]", "_", "%s:%s" % (self.host, self.dir)))
     if is_reverse:
         self.pout = os.fdopen(3, "rb")
         self.pin = os.fdopen(4, "wb")
         self.conn = Conn(self.pout, self.pin)
     else:
         if self.protocol in ("ssh", "file"):
             try:
                 # FIXME: ssh and file shouldn't use the same module
                 self.p = ssh.connect(self.host, self.port, "server")
                 self.pout = self.p.stdout
                 self.pin = self.p.stdin
                 self.conn = Conn(self.pout, self.pin)
             except OSError as e:
                 raise ClientError, "connect: %s" % e, sys.exc_info()[2]
         elif self.protocol == "bup":
             self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
             self.sock.connect((self.host, atoi(self.port) or 1982))
             self.sockw = self.sock.makefile("wb")
             self.conn = DemuxConn(self.sock.fileno(), self.sockw)
     if self.dir:
         self.dir = re.sub(r"[\r\n]", " ", self.dir)
         if create:
             self.conn.write("init-dir %s\n" % self.dir)
         else:
             self.conn.write("set-dir %s\n" % self.dir)
         self.check_ok()
     self.sync_indexes()
예제 #7
0
sys.stdout.flush()
out = byte_stream(sys.stdout)

try:
    sp = None
    p = None
    ret = 99

    hp = argv_bytes(extra[0]).split(b':')
    if len(hp) == 1:
        (hostname, port) = (hp[0], None)
    else:
        (hostname, port) = hp
    argv = [argv_bytes(x) for x in extra[1:]]
    p = ssh.connect(hostname, port, b'on--server', stderr=PIPE)

    try:
        argvs = b'\0'.join([b'bup'] + argv)
        p.stdin.write(struct.pack('!I', len(argvs)) + argvs)
        p.stdin.flush()

        # for commands not listed here don't even execute the server
        # (e.g. bup on <host> index ...)
        # (FIXME: consider parsing get arguments?)
        read_append_commands = [b'get']
        append_commands = [b'save', b'split', b'tag']
        read_commands = [b'restore', b'web', b'fuse']
        # FIXME: is there any value in even allowing these?
        #        it's inefficient to make the roundtrip ...
        read_commands += [
예제 #8
0
파일: on-cmd.py 프로젝트: bup/bup
signal.signal(signal.SIGTERM, handler)
signal.signal(signal.SIGINT, handler)

try:
    sp = None
    p = None
    ret = 99

    hp = extra[0].split(':')
    if len(hp) == 1:
        (hostname, port) = (hp[0], None)
    else:
        (hostname, port) = hp
    argv = extra[1:]
    p = ssh.connect(hostname, port, 'on--server', stderr=PIPE)

    try:
        argvs = '\0'.join(['bup'] + argv)
        p.stdin.write(struct.pack('!I', len(argvs)) + argvs)
        p.stdin.flush()
        sp = subprocess.Popen([path.exe(), 'server'],
                              stdin=p.stdout, stdout=p.stdin)
        p.stdin.close()
        p.stdout.close()
        # Demultiplex remote client's stderr (back to stdout/stderr).
        dmc = DemuxConn(p.stderr.fileno(), open(os.devnull, "w"))
        for line in iter(dmc.readline, ""):
            sys.stdout.write(line)
    finally:
        while 1:
예제 #9
0
signal.signal(signal.SIGTERM, handler)
signal.signal(signal.SIGINT, handler)

sp = None
p = None
ret = 99

try:
    hp = extra[0].split(':')
    if len(hp) == 1:
        (hostname, port) = (hp[0], None)
    else:
        (hostname, port) = hp

    argv = extra[1:]
    p = ssh.connect(hostname, port, 'on--server')

    argvs = '\0'.join(['bup'] + argv)
    p.stdin.write(struct.pack('!I', len(argvs)) + argvs)
    p.stdin.flush()

    sp = subprocess.Popen([path.exe(), 'server'],
                          stdin=p.stdout,
                          stdout=p.stdin)
    p.stdin.close()
    p.stdout.close()

finally:
    while 1:
        # if we get a signal while waiting, we have to keep waiting, just
        # in case our child doesn't die.
예제 #10
0
def main(argv):
    o = options.Options(optspec, optfunc=getopt.getopt)
    opt, flags, extra = o.parse_bytes(argv[1:])
    if len(extra) < 2:
        o.fatal('arguments expected')

    class SigException(Exception):
        def __init__(self, signum):
            self.signum = signum
            Exception.__init__(self, 'signal %d received' % signum)

    def handler(signum, frame):
        raise SigException(signum)

    signal.signal(signal.SIGTERM, handler)
    signal.signal(signal.SIGINT, handler)

    sys.stdout.flush()
    out = byte_stream(sys.stdout)

    try:
        sp = None
        p = None
        ret = 99

        hp = argv_bytes(extra[0]).split(b':')
        if len(hp) == 1:
            (hostname, port) = (hp[0], None)
        else:
            (hostname, port) = hp
        argv = [argv_bytes(x) for x in extra[1:]]
        p = ssh.connect(hostname, port, b'on--server', stderr=PIPE)

        try:
            argvs = b'\0'.join([b'bup'] + argv)
            p.stdin.write(struct.pack('!I', len(argvs)) + argvs)
            p.stdin.flush()

            # for commands not listed here don't even execute the server
            # (e.g. bup on <host> index ...)
            cmdmodes = {
                b'get': b'unrestricted',
                b'save': b'append',
                b'split': b'append',
                b'tag': b'append',
                b'join': b'read',
                b'cat-file': b'read',
                b'ftp': b'read',
                b'ls': b'read',
                b'margin': b'read',
                b'meta': b'read',
            }
            mode = cmdmodes.get(argv[0], None)

            if mode is not None:
                # we already put BUP_DIR into the environment, which
                # is inherited here
                sp = subprocess.Popen([
                    path.exe(), b'server', b'--force-repo', b'--mode=' + mode
                ],
                                      stdin=p.stdout,
                                      stdout=p.stdin)
            p.stdin.close()
            p.stdout.close()
            # Demultiplex remote client's stderr (back to stdout/stderr).
            dmc = DemuxConn(p.stderr.fileno(), open(os.devnull, "wb"))
            for line in iter(dmc.readline, b''):
                out.write(line)
        finally:
            while 1:
                # if we get a signal while waiting, we have to keep waiting, just
                # in case our child doesn't die.
                try:
                    ret = p.wait()
                    if sp:
                        sp.wait()
                    break
                except SigException as e:
                    log('\nbup on: %s\n' % e)
                    os.kill(p.pid, e.signum)
                    ret = 84
    except SigException as e:
        if ret == 0:
            ret = 99
        log('\nbup on: %s\n' % e)

    sys.exit(ret)
예제 #11
0
파일: on.py 프로젝트: fakegit/bup
def main(argv):
    o = options.Options(optspec, optfunc=getopt.getopt)
    opt, flags, extra = o.parse_bytes(argv[1:])
    if len(extra) < 2:
        o.fatal('arguments expected')

    class SigException(Exception):
        def __init__(self, signum):
            self.signum = signum
            Exception.__init__(self, 'signal %d received' % signum)
    def handler(signum, frame):
        raise SigException(signum)

    signal.signal(signal.SIGTERM, handler)
    signal.signal(signal.SIGINT, handler)

    sys.stdout.flush()
    out = byte_stream(sys.stdout)

    try:
        sp = None
        p = None
        ret = 99

        hp = argv_bytes(extra[0]).split(b':')
        if len(hp) == 1:
            (hostname, port) = (hp[0], None)
        else:
            (hostname, port) = hp
        argv = [argv_bytes(x) for x in extra[1:]]
        p = ssh.connect(hostname, port, b'on--server', stderr=PIPE)

        try:
            argvs = b'\0'.join([b'bup'] + argv)
            p.stdin.write(struct.pack('!I', len(argvs)) + argvs)
            p.stdin.flush()
            sp = subprocess.Popen([path.exe(), b'server'],
                                  stdin=p.stdout, stdout=p.stdin)
            p.stdin.close()
            p.stdout.close()
            # Demultiplex remote client's stderr (back to stdout/stderr).
            with DemuxConn(p.stderr.fileno(), open(os.devnull, "wb")) as dmc:
                for line in iter(dmc.readline, b''):
                    out.write(line)
        finally:
            while 1:
                # if we get a signal while waiting, we have to keep waiting, just
                # in case our child doesn't die.
                try:
                    ret = p.wait()
                    if sp:
                        sp.wait()
                    break
                except SigException as e:
                    log('\nbup on: %s\n' % e)
                    os.kill(p.pid, e.signum)
                    ret = 84
    except SigException as e:
        if ret == 0:
            ret = 99
        log('\nbup on: %s\n' % e)

    sys.exit(ret)
예제 #12
0
파일: rbackup-cmd.py 프로젝트: lkosewsk/bup
        self.signum = signum
        Exception.__init__(self, 'signal %d received' % signum)
def handler(signum, frame):
    raise SigException(signum)

signal.signal(signal.SIGTERM, handler)
signal.signal(signal.SIGINT, handler)

sp = None
p = None
ret = 99

try:
    hostname = extra[0]
    argv = extra[1:]
    p = ssh.connect(hostname, 'rbackup-server')

    argvs = '\0'.join(['bup'] + argv)
    p.stdin.write(struct.pack('!I', len(argvs)) + argvs)
    p.stdin.flush()

    main_exe = os.environ.get('BUP_MAIN_EXE') or sys.argv[0]
    sp = subprocess.Popen([main_exe, 'server'], stdin=p.stdout, stdout=p.stdin)

    p.stdin.close()
    p.stdout.close()

finally:
    while 1:
        # if we get a signal while waiting, we have to keep waiting, just
        # in case our child doesn't die.
예제 #13
0
파일: on-cmd.py 프로젝트: 3v/bup
signal.signal(signal.SIGTERM, handler)
signal.signal(signal.SIGINT, handler)

sp = None
p = None
ret = 99

try:
    hp = extra[0].split(':')
    if len(hp) == 1:
        (hostname, port) = (hp[0], None)
    else:
        (hostname, port) = hp

    argv = extra[1:]
    p = ssh.connect(hostname, port, 'on--server')

    argvs = '\0'.join(['bup'] + argv)
    p.stdin.write(struct.pack('!I', len(argvs)) + argvs)
    p.stdin.flush()

    sp = subprocess.Popen([path.exe(), 'server'],
                          stdin=p.stdout, stdout=p.stdin)
    p.stdin.close()
    p.stdout.close()

finally:
    while 1:
        # if we get a signal while waiting, we have to keep waiting, just
        # in case our child doesn't die.
        try: