diff --git a/config.py b/config.py index 54aba87dcca3f88ca8b28abca044626f978e3dd4..e7d3702c15f449f39d00a2737c8a1d467ccdaea8 100755 --- a/config.py +++ b/config.py @@ -11,7 +11,7 @@ def checkDirectory(s, l, t): if not t[0].startswith('/'): raise Exception('Directory expected at line %d" %s' % (lineno(l, s), t[0])) - + _subdirectory_ = ( Regex('[._a-zA-Z0-9/]+') | QuotedString('"') | @@ -43,7 +43,7 @@ _export_entry_ = ( Suppress(']') ) _primary_ = ( - Suppress(Keyword('primary')) + + Suppress(Keyword('primary')) + Suppress('{') + Suppress(Keyword('attributes')) + ( QuotedString('"') | QuotedString("'") )('attributes') + @@ -52,7 +52,7 @@ _primary_ = ( Suppress('{') + Group(OneOrMore(Group(_export_entry_)))('export') + Suppress('}') + - Suppress('}') + Suppress('}') ) _backup_entry_ = ( Group(_host_and_directory_)('mount') + diff --git a/hashbackup.py b/hashbackup.py index f24b28ac5ca0c6204c8338b6843dec6ecdae252e..08454638170c85eb1b5fc193097f690f5968564f 100644 --- a/hashbackup.py +++ b/hashbackup.py @@ -15,23 +15,23 @@ def main(): help='debug actions') parser.add_argument('--xattr', action='store_true', help='let hashtoc store HASH in extended attribute') - parser.add_argument('--max-age', + parser.add_argument('--max-age', metavar='SECONDS', help='maximum SECONDS since last HASH calculation') - parser.add_argument('--jobs', + parser.add_argument('--jobs', metavar='CPU', help='number of CPUs for HASH calculation') - parser.add_argument('--lookahead', + parser.add_argument('--lookahead', metavar='SIZE', help='lookahead buffer size for HASH calculation') group_primary = parser.add_argument_group('primary') group_primary.add_argument('--primary', nargs='+', metavar='CONFIG', help='backup as specified in CONFIG') - group_primary.add_argument('--identity', + group_primary.add_argument('--identity', metavar='IDENTITY', help='ssh IDENTITY for connecting (-i)') - group_primary.add_argument('--user', + group_primary.add_argument('--user', metavar='USER', help='ssh USER for connecting (-l)') group_secondary = parser.add_argument_group('secondary') @@ -45,12 +45,12 @@ def main(): print('Either --primary or --secondary should be specified') exit(1) pass - + m = re.match('^(.*)backup', os.path.basename(sys.argv[0])) if m: hash_name = m.group(1) pass - + if options.primary: done = set() for path in options.primary: @@ -62,7 +62,7 @@ def main(): config=config.parse(open(path).read())) pass pass - + elif options.secondary: secondary.do_backup(hash_name=hash_name, options=options, @@ -71,6 +71,6 @@ def main(): path=options.secondary[2]) pass pass - + if __name__ == '__main__': main() diff --git a/hashtoc.py b/hashtoc.py index ee66d2eb41a9f33a0ca4ba43278ee715ca5dd77b..82863bd3c912b262d591933723044c5ec8695318 100644 --- a/hashtoc.py +++ b/hashtoc.py @@ -22,7 +22,7 @@ def readline_toc(f): continue yield buf[0:pos] buf = buf[pos+len(terminator):] - + class HashTOC: def __init__(self, stream, rename={}): @@ -50,7 +50,7 @@ class HashTOC: self.reader = readtoc(stream) self.next() - + def next(self): data = self.reader.__next__() self.fields = data._fields @@ -58,7 +58,3 @@ class HashTOC: setattr(self, k, v) pass pass - - - - diff --git a/loghandler.py b/loghandler.py index eb2f3e5326c561a769ba077937c9de6e8eb9e6e7..3d596283d382f2f584dbff5ad7d7a450afa86f84 100644 --- a/loghandler.py +++ b/loghandler.py @@ -11,14 +11,14 @@ LOG_WARNING = 2 LOG_DEBUG = 3 class LOG: - + class singleton(object): loop = asyncio.new_event_loop() lock = threading.Lock() def __init__(self): t = threading.Thread(daemon=True, target=self.loop.run_forever) t.start() - + def __call__(self): return self singleton = singleton() @@ -48,7 +48,7 @@ class LOG: if self.prefix != None: print(self.prefix, end='', file=sys.stderr) print(buf, file=sys.stderr, flush=True) - + def ERROR(self, *args): self.MESSAGE(*args, level=LOG_ERROR) @@ -73,7 +73,6 @@ class LOG: else: return b.decode(encoding, errors='surrogateescape') self.decode = decode - def __call__(self): with self.mutex: @@ -89,7 +88,7 @@ class LOG: def flush(self): with self.mutex: while True: - + buf = os.read(self.fd, 4096) if len(buf) == 0: break self.buf.extend(buf) @@ -101,7 +100,7 @@ class LOG: self.buf = self.buf[i+1:] if len(self.buf) > 0: self.log.MESSAGE(self.decode(self.buf), level=level) - + class MakeFile: def __init__(self, log): self.rpipe, self.wpipe = os.pipe() @@ -115,5 +114,5 @@ class LOG: loop.remove_reader(self.rpipe) os.close(self.wpipe) self.reader.flush() - + return MakeFile(self) diff --git a/primary.py b/primary.py index ea98f5279fe36be841dd4d8eef50d6e344ba65d2..8276b241b12a5cf01f492b947799b5e4c257db0c 100644 --- a/primary.py +++ b/primary.py @@ -36,7 +36,7 @@ class AddrInfo: def __repr__(self): return 'AddrInfo(%s, %s)' % (self.name, self.addr) - + class Server: def __init__(self, hash_name, options, config, entry, path, uuid, log): @@ -54,7 +54,7 @@ class Server: self.thread_tar = None self.thread_server = threading.Thread(daemon=True, target=self.run) self.thread_server.start() - + def run(self): atexit.register(cond_unlink, self.socket_path, self.log) server = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) @@ -87,7 +87,7 @@ class Server: return ((self.thread_hash and self.thread_hash.thread.is_alive()) or (self.thread_tar and self.thread_tar.thread.is_alive()) or (self.thread_server.is_alive())) - + def send_HASH(self, config_HASH): self.log.DEBUG('send_HASH', self.config.primary.mount.path, @@ -107,7 +107,7 @@ class Server: finally: config_HASH.shutdown(socket.SHUT_RDWR) config_HASH.close() - + def run_tar(self, tar_socket): self.log.DEBUG('START run_tar', self.config.primary.mount.path, @@ -165,7 +165,7 @@ class Client: self.failed = False self.thread = threading.Thread(daemon=True, target=self.run) self.thread.start() - + def pending(self): return self.thread.is_alive() @@ -219,7 +219,7 @@ class Client: time.sleep(1) self.log.MESSAGE('DONE %s' % (readable)) time.sleep(1) - + def do_backup(hash_name, options, config): def is_primary(): node = set() @@ -238,7 +238,7 @@ def do_backup(hash_name, options, config): log = loghandler.LOG(loghandler.LOG_DEBUG) else: log = loghandler.LOG(loghandler.LOG_WARNING) - + for b in config.secondary.backup: client = [ Client(hash_name=hash_name, options=options, diff --git a/secondary.py b/secondary.py index 89b7c210886bf99e23227e5d19acec4a78bcc605..0c2c0fe6ab72f9674b6a3accfc30db1f8987dfc4 100644 --- a/secondary.py +++ b/secondary.py @@ -48,7 +48,7 @@ class Status: self.replaced, self.metadata, self.extract_OK)) atexit.register(report) - + class Backup: def __init__(self, primary_tar, mount, path, status, log): @@ -116,7 +116,7 @@ class Backup: self.status.metadata += 1 else: self.status.unchanged += 1 - + def make_room(self, size, path=None): def get_free_need(size, path): stat = os.statvfs(self.dst_root) @@ -194,7 +194,7 @@ def do_backup(hash_name, options, socket_path, mount, path): log = loghandler.LOG(loghandler.LOG_WARNING) atexit.register(cond_unlink, socket_path, log) status = Status(log) - + config_path = '%s/TOTALBACKUP.config' % (mount) if not os.path.exists(config_path): raise Exception('"%s" does not exists' % (config_path)) @@ -223,11 +223,11 @@ def do_backup(hash_name, options, socket_path, mount, path): stdout=subprocess.PIPE) atexit.register(cond_kill, p) dst = hashtoc.HashTOC(p.stdout, rename={hash_name:'sum'}) - + # Connect to server tar socket primary_tar = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) primary_tar.connect(socket_path) - + backup = Backup(primary_tar=primary_tar, mount=mount, path=path, status=status, log=log) while True: @@ -259,7 +259,7 @@ def do_backup(hash_name, options, socket_path, mount, path): raise Exception() backup.close() - + log.DEBUG('hashtoc result', p.wait()) config_hash.shutdown(socket.SHUT_RD) config_hash.close() diff --git a/tar_stream.py b/tar_stream.py index 38447044f613abbc2a551e64d6574b341b1d7995..2eccb82b87953e5ffd43aec8afb61934f22b1513 100755 --- a/tar_stream.py +++ b/tar_stream.py @@ -21,7 +21,7 @@ class TarWriter: def close(self): self.tarfile.close() self.tarfile = None - + class TarReader: def __init__(self, fileobj): @@ -42,8 +42,7 @@ class TarReader: self.tarfile.members = [] pass pass - + def close(self): self.tarfile.close() self.tarfile = None - diff --git a/test/Makefile b/test/Makefile index bc05120132e4d7b497cf9ae1f36cf8b3c54dcaee..82ec1c21f672a9c0da2fa57a57d867c56c180e14 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,7 +1,7 @@ PYTESTS = $(wildcard test_*.py) SHTESTS = $(wildcard test_*.sh) -test: $(PYTESTS:%.py=%) $(SHTESTS:%.sh=%) +test: $(PYTESTS:%.py=%) $(SHTESTS:%.sh=%) %: %.py PYTHONPATH=.. ./$< diff --git a/test/test_sha512backup.sh b/test/test_sha512backup.sh index d33376b8d4c7e95a7e6bd9abd9c468ce43ff412e..33610becbdc4ccfef095ba6482c02c78be6b9a32 100755 --- a/test/test_sha512backup.sh +++ b/test/test_sha512backup.sh @@ -55,7 +55,7 @@ config > "${TESTDIR}/2/TOTALBACKUP.config" #../config.py <(config) cp ../sha512backup "${TESTDIR}/" -run ${TESTDIR}/sha512backup --xattr --primary <(config) +run ${TESTDIR}/sha512backup --xattr --primary <(config) # Check that source and dest are equal diff -u \ <(cd ../test ; find | sort) \ @@ -92,5 +92,3 @@ diff -u \ # Check that deleted file exists in TRASH [ -f ${TESTDIR}/1/TRASH/*/${TESTFILE} ] - - diff --git a/test/test_tar_stream.py b/test/test_tar_stream.py index 6e7a570f74d19f0588e03fd61bb86a459cfa69d0..5a70493d39ae010a19c00eb0cbce421ad2f6fde1 100755 --- a/test/test_tar_stream.py +++ b/test/test_tar_stream.py @@ -16,7 +16,7 @@ def walk_files(root): pass pass pass - + def write_tar(t, files): for p in files: t.add(p) @@ -38,7 +38,6 @@ def reader(tar_reader): print(e.linkname) print(e.linkpath) pass - pass pass