From 4e5342fc834821d86159f3e43e6bdff730fcdbcf Mon Sep 17 00:00:00 2001 From: lifegpc Date: Mon, 16 Sep 2024 13:39:50 +0800 Subject: [PATCH] Add version command line --- game_backuper/cml.py | 5 ++++- game_backuper/main.py | 24 +++++++++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/game_backuper/cml.py b/game_backuper/cml.py index eb3cdb0..0898171 100644 --- a/game_backuper/cml.py +++ b/game_backuper/cml.py @@ -15,6 +15,7 @@ class OptAction(IntEnum): RESTORE = 1 LIST = 2 LIST_LEVELDB_KEY = 3 + VERSION = 4 @staticmethod def from_str(v: str) -> IntEnum: @@ -28,6 +29,8 @@ class OptAction(IntEnum): return OptAction.LIST elif t == 'list_leveldb_key': return OptAction.LIST_LEVELDB_KEY + elif t == "version": + return OptAction.VERSION else: raise TypeError('Must be str.') @@ -59,7 +62,7 @@ class Opts: re = OptAction.from_str(cm[0]) if re is not None: self.action = re - if re == OptAction.LIST: + if re == OptAction.LIST or re == OptAction.VERSION: return elif re == OptAction.LIST_LEVELDB_KEY: if len(cm) == 1: diff --git a/game_backuper/main.py b/game_backuper/main.py index 906a1ff..e8abb60 100644 --- a/game_backuper/main.py +++ b/game_backuper/main.py @@ -1,5 +1,5 @@ from game_backuper.config import Config -from game_backuper.cml import Opts +from game_backuper.cml import Opts, OptAction from game_backuper.db import Db from game_backuper.backuper import Backuper from os import makedirs @@ -11,6 +11,28 @@ def main(cm=None): import sys cm = sys.argv[1:] cml = Opts(cm) + if cml.action == OptAction.VERSION: + from game_backuper.compress import ( + have_brotli, + have_bz2, + have_gzip, + have_lzip, + have_lzma, + have_snappy, + have_zstd, + ) + from game_backuper.leveldb import have_leveldb + from game_backuper.regexp import have_pcre2 + print("Brotli support:", have_brotli) + print("BZip2 support:", have_bz2) + print("GZip support:", have_gzip) + print("LZip support:", have_lzip) + print("LZMA support:", have_lzma) + print("Snappy support:", have_snappy) + print("ZSTD support:", have_zstd) + print("LevelDB support:", have_leveldb) + print("PCRE2 support:", have_pcre2) + return 0 cfg = Config(cml.config_file) if not exists(cfg.dest): makedirs(cfg.dest)