-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
49 lines (40 loc) · 1.33 KB
/
main.py
File metadata and controls
49 lines (40 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# SlicerBackUp script
#
# Copyright (C) 2025 Christopher Mattar (3dcoded)
#
# This file may be distributed under the terms of the GNU GPLv3 license.
#
from pathlib import Path
from git import Repo, Actor
from git.exc import InvalidGitRepositoryError
from dotenv import load_dotenv
import os
import shutil
import sys
ENV_PATH = Path(sys.argv[-1]).parent / 'env.txt'
load_dotenv(ENV_PATH)
CONFIG_PATH = os.getenv('SLICERBACKUP_CONFIG_DIR')
REPO_URL = os.getenv('SLICERBACKUP_REPO_URL')
COMMIT_EMAIL = os.getenv('COMMIT_EMAIL')
AUTHOR = Actor('SlicerBackUp', COMMIT_EMAIL)
def backup():
git_dir = Path(CONFIG_PATH) / ".git"
if git_dir.exists():
try:
repo = Repo(CONFIG_PATH)
except InvalidGitRepositoryError:
shutil.rmtree(git_dir)
repo = Repo.init(CONFIG_PATH)
else:
repo = Repo.init(CONFIG_PATH)
if "origin" not in [r.name for r in repo.remotes]:
repo.create_remote("origin", REPO_URL)
repo.index.add(["filament", "machine", "process"])
if repo.active_branch.name != 'main':
repo.git.branch('-M', 'main')
repo.index.commit("Slicer profile backup", author=AUTHOR)
origin = repo.remote("origin")
origin.push(refspec="main:main", force=True, set_upstream=True)
if __name__ == '__main__':
backup()