From 8c65d639008b10cac10623c60311b20494cae2cc Mon Sep 17 00:00:00 2001 From: lifegpc Date: Mon, 6 Sep 2021 17:54:33 +0800 Subject: [PATCH] path now support both dir and file --- example.yaml | 6 +++--- game_backuper/backuper.py | 3 ++- game_backuper/config.py | 19 ++++++++++++++----- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/example.yaml b/example.yaml index af2a3d0..03c9515 100644 --- a/example.yaml +++ b/example.yaml @@ -3,10 +3,10 @@ programs: - name: Your program name # This name is used to identify different application. base: /path/to/save/path # Must be absoulte path. files: - - BGI.gdb # A single save file. Must be relative path. + - BGI.gdb # path to a file/folder. All subfolders will include if it is a folder. Must be relative path. - type: path - path: folder # path to a folder. All subfolders will include. Must be relative path. + path: folder # path to a file/folder. All subfolders will include if it is a folder. Must be relative path. - type: leveldb # module plyvel is needed to support this type. This will store leveldb database to a single file database (sqlite3) - path: leveldb # path to leveldb. Must be relative path. + path: leveldb # path to leveldb. Must be relative path. domains: # optional. Just backup minor domains in localstorage database. Only chromium is tested. - some domain diff --git a/game_backuper/backuper.py b/game_backuper/backuper.py index 1c0aad8..2fdfdd0 100644 --- a/game_backuper/backuper.py +++ b/game_backuper/backuper.py @@ -36,7 +36,7 @@ class BackupTask(Thread): de = join(bp, f[0]) if ori is not None: if ori.size == nf.size and ori.hash == nf.hash: - print(f'{prog}: Skip {f[0]}({f[1]}).') + print(f'{prog}: Skip {f[0]}.') continue copy_file(f[1], de, f[0], prog) self.db.set_file(ori.id, nf.size, nf.hash) @@ -58,6 +58,7 @@ class BackupTask(Thread): de = join(bp, f.name + ".db") if ori is not None: if ori.size == stats.size and ori.hash == stats.hash: + print(f'{prog}: Skip {f[0]}') continue if ori.type is None or ori.type != FileType.LEVELDB: pp = join(bp, ori.file) diff --git a/game_backuper/config.py b/game_backuper/config.py index 2465291..c09fda3 100644 --- a/game_backuper/config.py +++ b/game_backuper/config.py @@ -3,7 +3,7 @@ try: from yaml import CSafeLoader as SafeLoader except Exception: from yaml import SafeLoader -from os.path import join, relpath +from os.path import join, relpath, isfile, isdir from typing import List, Union from game_backuper.file import listdirs from collections import namedtuple @@ -47,14 +47,23 @@ class Program: for i in self.data[ke]: b = self.base if isinstance(i, str): - r.append(ConfigNormalFile(i, join(b, i))) + bp = join(b, i) + if isfile(bp): + r.append(ConfigNormalFile(i, bp)) + elif isdir(bp): + ll = listdirs(bp) + for ii in ll: + r.append(ConfigNormalFile(relpath(ii, b), ii)) elif isinstance(i, dict): t = i['type'] if t == 'path': bp = join(b, i['path']) - ll = listdirs(bp) - for ii in ll: - r.append(ConfigNormalFile(relpath(ii, b), ii)) + if isfile(bp): + r.append(ConfigNormalFile(i['path'], bp)) + elif isdir(bp): + ll = listdirs(bp) + for ii in ll: + r.append(ConfigNormalFile(relpath(ii, b), ii)) elif t == 'leveldb': p = join(b, i['path']) dms = None