add platfrom check
This commit is contained in:
parent
d6ba5eba45
commit
fee5a7db1a
40
sync.py
40
sync.py
@ -6,18 +6,44 @@ import os
|
|||||||
from os import path
|
from os import path
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
#=== Init ===#
|
||||||
|
|
||||||
backup_root: str = path.dirname(__file__)
|
backup_root: str = path.dirname(__file__)
|
||||||
user_home: str = path.expanduser("~")
|
user_home: str = path.expanduser("~")
|
||||||
|
|
||||||
if user_home == "~":
|
if user_home == "~":
|
||||||
print("WARN: Cannot read the user home dir, do you run it in the correct script?")
|
print("WARN: Cannot read the user home dir, do you run it in the correct script?")
|
||||||
print("continue? [y/N]")
|
exit()
|
||||||
if (input().lower != 'y'):
|
|
||||||
exit()
|
|
||||||
else:
|
else:
|
||||||
print("dot-config: current user home: " + user_home)
|
print("dot-config: current user home: " + user_home)
|
||||||
|
|
||||||
|
class SysType (Enum):
|
||||||
|
LINUX = "linux"
|
||||||
|
TERMUX = "termux"
|
||||||
|
WINDOWS = "windows"
|
||||||
|
if ("termux" in backup_root):
|
||||||
|
sys_type: SysType = SysType.TERMUX
|
||||||
|
elif (backup_root[0] == "/"):
|
||||||
|
sys_type: SysType = SysType.LINUX
|
||||||
|
else:
|
||||||
|
sys_type: SysType = SysType.WINDOWS
|
||||||
|
print(f"dot config: your dot-config path is {backup_root}")
|
||||||
|
print(f"dot config: your system type is {sys_type}")
|
||||||
|
print(f"Is all the informations correct? [y/n] ", end="")
|
||||||
|
while True:
|
||||||
|
_in = input()
|
||||||
|
match _in:
|
||||||
|
case "y":
|
||||||
|
print("continuing...")
|
||||||
|
break;
|
||||||
|
case "n":
|
||||||
|
print("Exiting")
|
||||||
|
exit()
|
||||||
|
case _:
|
||||||
|
print("please confirm with [y/n] ", end="")
|
||||||
|
|
||||||
|
#=== Utils ===#
|
||||||
|
|
||||||
def sorted_paths (paths: Iterable[str]) -> list[str]:
|
def sorted_paths (paths: Iterable[str]) -> list[str]:
|
||||||
fin = sorted(paths)
|
fin = sorted(paths)
|
||||||
return fin
|
return fin
|
||||||
@ -25,6 +51,8 @@ def sorted_paths (paths: Iterable[str]) -> list[str]:
|
|||||||
def de_abs_path (path: str) -> str:
|
def de_abs_path (path: str) -> str:
|
||||||
return path.strip('/').strip('\\')
|
return path.strip('/').strip('\\')
|
||||||
|
|
||||||
|
#=== Backup Item ===#
|
||||||
|
|
||||||
class BackupItem:
|
class BackupItem:
|
||||||
def __init__ (self, backup_dir: str, origin_dir: str) -> None:
|
def __init__ (self, backup_dir: str, origin_dir: str) -> None:
|
||||||
self.name: str = backup_dir
|
self.name: str = backup_dir
|
||||||
@ -32,7 +60,8 @@ class BackupItem:
|
|||||||
self.origin_dir: str = path.abspath(path.expanduser(origin_dir))
|
self.origin_dir: str = path.abspath(path.expanduser(origin_dir))
|
||||||
|
|
||||||
table: list[BackupItem] = [
|
table: list[BackupItem] = [
|
||||||
BackupItem("PowerShell", "~/Documents/PowerShell")
|
BackupItem("PowerShell", "~/Documents/PowerShell"),
|
||||||
|
BackupItem("lsd", "~/.config/lsd")
|
||||||
]
|
]
|
||||||
|
|
||||||
def execute_sync (backupItem: BackupItem) -> None:
|
def execute_sync (backupItem: BackupItem) -> None:
|
||||||
@ -95,5 +124,8 @@ def compare_file (rootBackItem: BackupItem, relative_file_path: str) -> None:
|
|||||||
case IsNewerStatus.DIFFERENT:
|
case IsNewerStatus.DIFFERENT:
|
||||||
print(f"{relative_file_path} : WARN : backup is different but cannot determine which is newer")
|
print(f"{relative_file_path} : WARN : backup is different but cannot determine which is newer")
|
||||||
|
|
||||||
|
|
||||||
|
#=== main ===#
|
||||||
|
|
||||||
for i in table:
|
for i in table:
|
||||||
execute_sync(i)
|
execute_sync(i)
|
||||||
|
Loading…
Reference in New Issue
Block a user