2024-01-06 08:03:59 +00:00
|
|
|
from datetime import datetime
|
2023-12-12 12:29:22 +00:00
|
|
|
from pathlib import Path
|
2024-01-06 08:03:59 +00:00
|
|
|
import shutil
|
2023-12-12 12:29:22 +00:00
|
|
|
|
2023-12-12 15:42:02 +00:00
|
|
|
data = Path("data")
|
|
|
|
data.mkdir(exist_ok=True)
|
|
|
|
|
2023-12-12 12:51:22 +00:00
|
|
|
|
2024-01-06 08:03:59 +00:00
|
|
|
def rename(old: Path, need_backup: bool = True):
|
2023-12-12 12:51:22 +00:00
|
|
|
if old.exists():
|
|
|
|
old_file_name = old.name
|
2023-12-12 15:42:02 +00:00
|
|
|
new = data / old_file_name
|
2024-01-06 08:03:59 +00:00
|
|
|
if need_backup and new.exists():
|
|
|
|
datetime_str = datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
|
|
|
|
backup = data / f"{new.stem}.{datetime_str}{new.suffix}"
|
|
|
|
shutil.move(new, backup)
|
|
|
|
shutil.move(old, new)
|
2023-12-12 12:51:22 +00:00
|
|
|
|
|
|
|
|
2023-12-12 12:29:22 +00:00
|
|
|
# move file
|
|
|
|
# session
|
|
|
|
session = Path("pagermaid.session")
|
2023-12-12 12:51:22 +00:00
|
|
|
rename(session)
|
2023-12-12 12:29:22 +00:00
|
|
|
# config
|
|
|
|
config = Path("config.yml")
|
2023-12-12 12:51:22 +00:00
|
|
|
rename(config)
|
|
|
|
# docker
|
|
|
|
docker = Path("install.lock")
|
2024-01-06 08:03:59 +00:00
|
|
|
rename(docker, need_backup=False)
|
2023-12-12 12:29:22 +00:00
|
|
|
# delete file
|
|
|
|
# log
|
|
|
|
log = Path("pagermaid.log.txt")
|
|
|
|
if log.exists():
|
|
|
|
log.unlink()
|