diff --git a/SourceManager.py b/SourceManager.py index 5873c9e..e8055d1 100755 --- a/SourceManager.py +++ b/SourceManager.py @@ -76,6 +76,13 @@ class o: print("[{}DEBUG{}]{}".format(colors.HEADER, colors.ENDC, text)) return True +def format_bytes(size): + for unit in ['B', 'KB', 'MB', 'GB', 'TB']: + if size < 1024.0: + return f"{size:.2f} {unit}" + size /= 1024.0 + return f"{size:.2f} PB" + def hashfile(filepath, blocksize = 65536): file_hash = hashlib.sha256() with open(filepath, "rb") as f: @@ -726,7 +733,10 @@ class Server: self.o.error(f"Cannot find logs in {lgsm_logs_place}") logs_files = default_logs + sourcemod_logs + lgsm_logs - self.o.info(f"Compress {len(logs_files)} logs files and delete?") + size = 0 + for f in logs_files: + size += os.path.getsize(f) + self.o.info(f"Compress {len(logs_files)} ({format_bytes(size)}) logs files and delete?") if not self.wait_input(): return True @@ -794,12 +804,16 @@ class Server: return True while True: - print("Enter \"{}\" to accept or \"{}\" to negative response:".format(yes, no) ,end="\t") - response = input() - if response.lower() == yes: - return True - if response.lower() == no: - return False + try: + print("Enter \"{}\" to accept or \"{}\" to negative response:".format(yes, no) ,end="\t") + response = input() + if response.lower() == yes: + return True + if response.lower() == no: + return False + except KeyboardInterrupt: + print("exit...") + sys.exit(1) def select(self, request): if self.name == request: