def sync_indexes(self): self._require_command(b'list-indexes') self.check_busy() conn = self.conn mkdirp(self.cachedir) # All cached idxs are extra until proven otherwise extra = set() for f in os.listdir(self.cachedir): debug1(path_msg(f) + '\n') if f.endswith(b'.idx'): extra.add(f) needed = set() conn.write(b'list-indexes\n') for line in linereader(conn): if not line: break assert(line.find(b'/') < 0) parts = line.split(b' ') idx = parts[0] if len(parts) == 2 and parts[1] == b'load' and idx not in extra: # If the server requests that we load an idx and we don't # already have a copy of it, it is needed needed.add(idx) # Any idx that the server has heard of is proven not extra extra.discard(idx) self.check_ok() debug1('client: removing extra indexes: %s\n' % extra) for idx in extra: os.unlink(os.path.join(self.cachedir, idx)) debug1('client: server requested load of: %s\n' % needed) for idx in needed: self.sync_index(idx) git.auto_midx(self.cachedir)
def _suggest_packs(self): ob = self._busy if ob: assert(ob == b'receive-objects-v2') self.conn.write(b'\xff\xff\xff\xff') # suspend receive-objects-v2 suggested = [] for line in linereader(self.conn): if not line: break debug2('%r\n' % line) if line.startswith(b'index '): idx = line[6:] debug1('client: received index suggestion: %s\n' % git.shorten_hash(idx).decode('ascii')) suggested.append(idx) else: assert(line.endswith(b'.idx')) debug1('client: completed writing pack, idx: %s\n' % git.shorten_hash(line).decode('ascii')) suggested.append(line) self.check_ok() if ob: self._busy = None idx = None for idx in suggested: self.sync_index(idx) git.auto_midx(self.cachedir) if ob: self._busy = ob self.conn.write(b'%s\n' % ob) return idx
def _suggest_packs(self): ob = self._busy if ob: assert(ob == 'receive-objects-v2') self.conn.write('\xff\xff\xff\xff') # suspend receive-objects-v2 suggested = [] for line in linereader(self.conn): if not line: break debug2('%s\n' % line) if line.startswith('index '): idx = line[6:] debug1('client: received index suggestion: %s\n' % git.shorten_hash(idx)) suggested.append(idx) else: assert(line.endswith('.idx')) debug1('client: completed writing pack, idx: %s\n' % git.shorten_hash(line)) suggested.append(line) self.check_ok() if ob: self._busy = None idx = None for idx in suggested: self.sync_index(idx) git.auto_midx(self.cachedir) if ob: self._busy = ob self.conn.write('%s\n' % ob) return idx
def main(argv): o = options.Options(optspec) opt, flags, extra = o.parse_bytes(argv[1:]) if extra: o.fatal('no arguments expected') debug2('bup server: reading from stdin.\n') # FIXME: this protocol is totally lame and not at all future-proof. # (Especially since we abort completely as soon as *anything* bad happens) sys.stdout.flush() conn = Conn(byte_stream(sys.stdin), byte_stream(sys.stdout)) lr = linereader(conn) for _line in lr: line = _line.strip() if not line: continue debug1('bup server: command: %r\n' % line) words = line.split(b' ', 1) cmd = words[0] rest = len(words)>1 and words[1] or b'' if cmd == b'quit': break else: cmd = commands.get(cmd) if cmd: cmd(conn, rest) else: raise Exception('unknown server command: %r\n' % line) debug1('bup server: done\n')
def sync_indexes(self): self.check_busy() conn = self.conn mkdirp(self.cachedir) # All cached idxs are extra until proven otherwise extra = set() for f in os.listdir(self.cachedir): debug1('%s\n' % f) if f.endswith('.idx'): extra.add(f) needed = set() conn.write('list-indexes\n') for line in linereader(conn): if not line: break assert(line.find('/') < 0) parts = line.split(' ') idx = parts[0] if len(parts) == 2 and parts[1] == 'load' and idx not in extra: # If the server requests that we load an idx and we don't # already have a copy of it, it is needed needed.add(idx) # Any idx that the server has heard of is proven not extra extra.discard(idx) self.check_ok() debug1('client: removing extra indexes: %s\n' % extra) for idx in extra: os.unlink(os.path.join(self.cachedir, idx)) debug1('client: server requested load of: %s\n' % needed) for idx in needed: self.sync_index(idx) git.auto_midx(self.cachedir)
def main(argv): o = options.Options(optspec) opt, flags, extra = o.parse_bytes(argv[1:]) if opt.remote: opt.remote = argv_bytes(opt.remote) git.check_repo_or_die() stdin = byte_stream(sys.stdin) if not extra: extra = linereader(stdin) ret = 0 repo = RemoteRepo(opt.remote) if opt.remote else LocalRepo() if opt.o: outfile = open(opt.o, 'wb') else: sys.stdout.flush() outfile = byte_stream(sys.stdout) for ref in [argv_bytes(x) for x in extra]: try: for blob in repo.join(ref): outfile.write(blob) except KeyError as e: outfile.flush() log('error: %s\n' % e) ret = 1 sys.exit(ret)
def handle(self): commands = self._commands # FIXME: this protocol is totally lame and not at all future-proof. # (Especially since we abort completely as soon as *anything* bad happens) lr = linereader(self.conn) for _line in lr: line = _line.strip() if not line: continue debug1('bup server: command: %r\n' % line) words = line.split(b' ', 1) cmd = words[0] if not cmd in commands: raise Exception('unknown server command: %r\n' % line) rest = len(words) > 1 and words[1] or '' if cmd == b'quit': break cmdattr = cmd.replace(b'-', b'_').decode('ascii', errors='replace') getattr(self, cmdattr)(rest) debug1('bup server: done\n')
def _list_indexes(self): self._require_command(b'list-indexes') self.check_busy() self.conn.write(b'list-indexes\n') for line in linereader(self.conn): if not line: break assert(line.find(b'/') < 0) parts = line.split(b' ') idx = parts[0] load = len(parts) == 2 and parts[1] == b'load' yield idx, load self.check_ok()
'list-indexes': list_indexes, 'send-index': send_index, 'receive-objects-v2': receive_objects_v2, 'read-ref': read_ref, 'update-ref': update_ref, 'join': join, 'cat': join, # apocryphal alias 'cat-batch' : cat_batch, 'refs': refs, 'rev-list': rev_list } # FIXME: this protocol is totally lame and not at all future-proof. # (Especially since we abort completely as soon as *anything* bad happens) conn = Conn(sys.stdin, sys.stdout) lr = linereader(conn) for _line in lr: line = _line.strip() if not line: continue debug1('bup server: command: %r\n' % line) words = line.split(' ', 1) cmd = words[0] rest = len(words)>1 and words[1] or '' if cmd == 'quit': break else: cmd = commands.get(cmd) if cmd: cmd(conn, rest) else:
optspec = """ bup join [-r host:path] [refs or hashes...] -- r,remote= remote repository path o= output filename """ o = options.Options(optspec) (opt, flags, extra) = o.parse(sys.argv[1:]) if opt.remote: opt.remote = argv_bytes(opt.remote) stdin = byte_stream(sys.stdin) if not extra: extra = linereader(stdin) ret = 0 repo = from_opts(opt) if opt.o: outfile = open(opt.o, 'wb') else: sys.stdout.flush() outfile = byte_stream(sys.stdout) for ref in [argv_bytes(x) for x in extra]: try: for blob in repo.join(ref): outfile.write(blob) except KeyError as e:
from bup import git, options, client from bup.helpers import linereader, log optspec = """ bup join [-r host:path] [refs or hashes...] -- r,remote= remote repository path o= output filename """ o = options.Options(optspec) (opt, flags, extra) = o.parse(sys.argv[1:]) git.check_repo_or_die() if not extra: extra = linereader(sys.stdin) ret = 0 if opt.remote: cli = client.Client(opt.remote) cat = cli.cat else: cp = git.CatPipe() cat = cp.join if opt.o: outfile = open(opt.o, 'wb') else: outfile = sys.stdout
from bup.repo import LocalRepo, RemoteRepo optspec = """ bup join [-r host:path] [refs or hashes...] -- r,remote= remote repository path o= output filename """ o = options.Options(optspec) (opt, flags, extra) = o.parse(sys.argv[1:]) git.check_repo_or_die() if not extra: extra = linereader(sys.stdin) ret = 0 repo = RemoteRepo(opt.remote) if opt.remote else LocalRepo() if opt.o: outfile = open(opt.o, 'wb') else: outfile = sys.stdout for ref in extra: try: for blob in repo.join(ref): outfile.write(blob) except KeyError as e: outfile.flush()