From 8d16a4a6c1a039697568bdb0e2bfd7c73424e52a Mon Sep 17 00:00:00 2001
From: Anders Blomdell <anders.blomdell@control.lth.se>
Date: Tue, 18 Jun 2024 14:24:25 +0200
Subject: [PATCH] Whitespace cleanup

---
 config.py                 |  6 +++---
 hashbackup.py             | 18 +++++++++---------
 hashtoc.py                |  8 ++------
 loghandler.py             | 13 ++++++-------
 primary.py                | 14 +++++++-------
 secondary.py              | 12 ++++++------
 tar_stream.py             |  5 ++---
 test/Makefile             |  2 +-
 test/test_sha512backup.sh |  4 +---
 test/test_tar_stream.py   |  3 +--
 10 files changed, 38 insertions(+), 47 deletions(-)

diff --git a/config.py b/config.py
index 54aba87..e7d3702 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 f24b28a..0845463 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 ee66d2e..82863bd 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 eb2f3e5..3d59628 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 ea98f52..8276b24 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 89b7c21..0c2c0fe 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 3844704..2eccb82 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 bc05120..82ec1c2 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 d33376b..33610be 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 6e7a570..5a70493 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
 
-- 
GitLab