From 64f2da23ed482659ff9fbdd69c7fafcc1213c536 Mon Sep 17 00:00:00 2001 From: lifegpc Date: Tue, 7 Sep 2021 14:09:33 +0800 Subject: [PATCH] path type now support custom backup locations and path support absoule path --- example.yaml | 3 ++- game_backuper/config.py | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/example.yaml b/example.yaml index 03c9515..a0efe72 100644 --- a/example.yaml +++ b/example.yaml @@ -5,7 +5,8 @@ programs: files: - 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 file/folder. All subfolders will include if it is a folder. Must be relative path. + path: folder # path to a file/folder. All subfolders will include if it is a folder. Must be relative path if name not found. + name: folder2 # path to the backup files. Shoule be a 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. domains: # optional. Just backup minor domains in localstorage database. Only chromium is tested. diff --git a/game_backuper/config.py b/game_backuper/config.py index c09fda3..08cf178 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, isfile, isdir +from os.path import join, relpath, isfile, isdir, isabs from typing import List, Union from game_backuper.file import listdirs from collections import namedtuple @@ -47,6 +47,8 @@ class Program: for i in self.data[ke]: b = self.base if isinstance(i, str): + if isabs(i): + raise ValueError('Absolute path must need a name.') bp = join(b, i) if isfile(bp): r.append(ConfigNormalFile(i, bp)) @@ -57,13 +59,20 @@ class Program: elif isinstance(i, dict): t = i['type'] if t == 'path': - bp = join(b, i['path']) + if isabs(i['path']): + if 'name' not in i or not isinstance(i['name'], str) or i['name'] == '': # noqa: E501 + raise ValueError('Absolute path must need a name.') + bp = i['path'] + name = i['name'] + else: + bp = join(b, i['path']) + name = i['path'] if isfile(bp): - r.append(ConfigNormalFile(i['path'], bp)) + r.append(ConfigNormalFile(name, bp)) elif isdir(bp): ll = listdirs(bp) for ii in ll: - r.append(ConfigNormalFile(relpath(ii, b), ii)) + r.append(ConfigNormalFile(join(name, relpath(ii, bp)), ii)) # noqa: E501 elif t == 'leveldb': p = join(b, i['path']) dms = None