_resource_path = os.environ.get('BUP_RESOURCE_PATH') or '.'
return os.path.join(_resource_path, subdir)
+
class NotOk(Exception):
pass
+
class BaseConn:
def __init__(self, outp):
self.outp = outp
raise Exception('expected "ok", got %r' % rl)
return self._check_ok(onempty)
+
class Conn(BaseConn):
def __init__(self, inp, outp):
BaseConn.__init__(self, outp)
else:
return None
+
def checked_reader(fd, n):
while n > 0:
rl, _, _ = select.select([fd], [], [])
yield buf
n -= len(buf)
+
MAX_PACKET = 128 * 1024
def mux(p, outfd, outr, errr):
try:
finally:
os.write(outfd, struct.pack('!IB', 0, 3))
+
class DemuxConn(BaseConn):
"""A helper class for bup's client-server protocol."""
def __init__(self, infd, outp):
def has_input(self):
return self._load_buf(0)
+
def linereader(f):
"""Generate a list of input lines from 'f' without terminating newlines."""
while 1:
saved_errors.append(e)
log('%-70s\n' % e)
+
istty = os.isatty(2) or atoi(os.environ.get('BUP_FORCE_TTY'))
def progress(s):
"""Calls log(s) if stderr is a TTY. Does nothing otherwise."""
out += prefix + ''.join(('%-*s' % (clen+2, s)) for s in row) + '\n'
return out
+
def parse_date_or_fatal(str, fatal):
"""Parses the given date or calls Option.fatal().
For now we expect a string that contains a float."""
else:
return date
+
def strip_path(prefix, path):
"""Strips a given prefix from a path.
else:
return path
+
def strip_base_path(path, base_paths):
"""Strips the base path from a given path.
return strip_path(bp, normalized_path)
return path
+
def graft_path(graft_points, path):
normalized_path = os.path.realpath(path)
for graft_point in graft_points:
"""Format bup's version date string for output."""
return _version.DATE.split(' ')[0]
+
def version_commit():
"""Get the commit hash of bup's current version."""
return _version.COMMIT
+
def version_tag():
"""Format bup's version tag (the official version number).