-
Notifications
You must be signed in to change notification settings - Fork 0
/
dev.py
79 lines (63 loc) · 2.19 KB
/
dev.py
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
from git import Repo
from pathlib import Path
import dotenv
import os
from datetime import datetime
import subprocess
import json
# TODO: get username and pw using dotenv
# use typer or argparse to get commit msg. if blank, use date + id?
# Do a check with "safety" lib. use subprocess?
# add progressbar from git lib?
cwd = Path.cwd().resolve()
repo = Repo(cwd)
assert not repo.bare
assert repo.working_tree_dir == str(cwd.resolve())
dotenv.load_dotenv(cwd / ".env")
username = os.getenv("GIT_USERNAME") or "DML"
password = os.getenv("GIT_PASSWORD") # or None
try:
repo.remotes.origin.pull()
print("Pulling from github....")
except Exception as e:
print("Could not pull from github!")
raise e
else:
print(" .... done")
if repo.is_dirty():
changedFiles = [item.a_path for item in repo.index.diff(None)]
repo.git.add(update=True)
print(f"Modifying files: {changedFiles}")
# TODO get list of changed files. repo.diff? repo.git.diff?
if repo.untracked_files:
print(f"Adding files: {repo.untracked_files}") # list of filename strings that have not been added
repo.index.add(repo.untracked_files)
update_pending = True
else:
update_pending = False
commit_msg = ""
if update_pending:
if not commit_msg:
commit_msg = f"{username}, {datetime.now()}"
try:
repo.index.commit(commit_msg)
print(f"Commiting changes with msg: {commit_msg}")
repo.remotes.origin.push()
print(f"Pushing changes to: {repo.remotes.origin.url}")
except Exception:
raise
venv_bytespath = subprocess.check_output("poetry env info --path".split(), shell=True)
venv_str = venv_bytespath.decode("UTF-8")
venv_path = venv_str.strip()
"""
# check if vscode settings exists, or create if not
Path(".vscode").mkdir(parents=True, exist_ok=True)
Path(".vscode/settings.json").touch()
print(f"Updating path to \n {venv_path}")
with open(".vscode/settings.json", "r") as f:
settings = json.load(f)
settings["python.pythonPath"] = venv_path + R"\\scripts\\python.exe"
with open(".vscode/settings.json", "w") as f:
json.dump(settings, f, sort_keys=True, indent=4)
"""
# print(json.dumps(settings, sort_keys=True, indent=4))