Add version command line

This commit is contained in:
2024-09-16 13:39:50 +08:00
parent 75e6d4bd39
commit 4e5342fc83
2 changed files with 27 additions and 2 deletions

View File

@@ -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:

View File

@@ -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)