path now support both dir and file

This commit is contained in:
2021-09-06 17:54:33 +08:00
parent d0257d6de7
commit 8c65d63900
3 changed files with 19 additions and 9 deletions

View File

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

View File

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

View File

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