|
|
|
@ -2,8 +2,8 @@ import datetime |
|
|
|
from pathlib import Path |
|
|
|
import os |
|
|
|
|
|
|
|
|
|
|
|
from tibi_hardlinks.exceptions import ConfigurationException |
|
|
|
from tibi_hardlinks.backup_parser import read_backup_properties |
|
|
|
|
|
|
|
HEIRACHY = ( |
|
|
|
"sys_ro.product.model", |
|
|
|
@ -34,3 +34,29 @@ def create_backup_directory_name(backup_info, time_format="%Y-%m-%d_%H-%M-%S"): |
|
|
|
return backup_directory_name |
|
|
|
|
|
|
|
|
|
|
|
def find_backup_data(backup_filepath: Path, backup_info): |
|
|
|
# find the path of the *.apk, *.properties, and *.tar(.gz) corresponding to backup_filepath |
|
|
|
backup_root = backup_filepath.parent |
|
|
|
apk_hash = backup_info["app_apk_md5"] |
|
|
|
apk_file = filter( |
|
|
|
lambda apk_file: apk_hash in apk_file.name, backup_root.glob("*.apk*") |
|
|
|
) |
|
|
|
related_files = list(backup_root.glob(backup_filepath.stem + "*")) |
|
|
|
if len(related_files) > 2: |
|
|
|
raise Exception |
|
|
|
for filename in related_files: |
|
|
|
if ".tar" in filename.name: |
|
|
|
tar_file = filename |
|
|
|
property_file = backup_filepath |
|
|
|
return property_file, apk_file, tar_file |
|
|
|
|
|
|
|
|
|
|
|
class Backup: |
|
|
|
def __init__(self, property_file: Path): |
|
|
|
self.property_file = property_file |
|
|
|
self.backup_info = read_backup_properties(property_file) |
|
|
|
self.related_files = find_backup_data(self.backup_filepath, self.backup_info) |
|
|
|
|
|
|
|
def hardlink_to(self, dest): |
|
|
|
for filepath in self.related_files: |
|
|
|
filepath.link_to(dest) |