-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdev.py
96 lines (72 loc) · 2.49 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import subprocess
import json
from pathlib import Path
from git import Repo, exc
import dotenv
import os
from datetime import datetime
from git.diff import _octal_repl
# import safety
"""
poetry config virtualenvs.in-project true
"""
# 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()
try:
git_wd = cwd
repo = Repo(git_wd)
except exc.InvalidGitRepositoryError:
git_wd = cwd.parent
repo = Repo(git_wd)
assert not repo.bare
print(type(repo.working_tree_dir))
print(type(git_wd.resolve()))
assert repo.working_tree_dir == str(git_wd.resolve())
dotenv.load_dotenv(cwd / ".env")
username = os.getenv("GIT_USERNAME") or "DML"
password = os.getenv("GIT_PASSWORD") # or None
repo.remotes.origin.pull()
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_path_bytes = subprocess.check_output("poetry env info --path".split(), shell=True)
venv_path = venv_path_bytes.decode("UTF-8")
Path(".vscode").mkdir(parents=True, exist_ok=True)
Path(".vscode/settings.json").touch()
with open(".vscode/settings.json", "r") as f:
settings = json.load(f)
settings["python.pythonPath"] = venv_path
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))
"""
def _intp(mode: int, hex: str, st: int, path: str) -> str:
return "(%o, %s, %i, %s)" % (mode, hex, st, path)
print(_intp(9, "es", 2, "Fr"))
def fintp(mode: int, hex: str, st: int, path: str) -> str:
# assert isinstance(mode, _octal_repl)
return f"({mode:o}, {hex}, {st}, {path})"
print(fintp(9, "es", 2, "Fr"))