-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinitdev.py
90 lines (67 loc) · 1.92 KB
/
initdev.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
import os
import json
import argparse
import configparser
#config path
config_path = "./.bandzdev.ini"
#git repo
initial_repo = "https://github.com/jmarshall9120/initdev.git"
#venv_name
venv_name = "bandz_env"
#default settings
default_settings = {
"env_name": "bandz_env",
"remote_repo": "initial_repo"
}
config = configparser.ConfigParser()
#ensure config exits
if not os.path.exists(config_path):
config["DEFAULT"] = default_settings
with open(config_path, "w") as f:
config.write(f)
config.read("./bandzdev.ini")
# config.sections()
# config["DEFAULT"]["env_name"]
def init():
_initEnv()
_initGit()
return
def _initGit():
if not os.path.exists(".git"):
rtn = os.system('git init')
rtn = os.system('python -m pip install --upgrade pip')
if not os.path.exists(".gitignore"):
with open(".gitignore\n", "w") as f:
f.write(config["DEFAULT"]["env_name"] + "/")
rtn = os.system('git add .')
return
def _initEnv():
if not os.path.exists(env:=config.get("DEFAULT","env_name")):
rtn = os.system(f'python -m venv "{env}"')
rtn = os.system('python -m pip install --upgrade pip')
return
prePushHook= f"""
#!/bin/sh
echo "Working Test 2!!!" > 1
{get_sys_env_path()} freeze > requirements.txt
git add requirements.txt
git commit --reuse-message=HEAD
""".lstrip('\n')
prePushHook
# $env = python -c "import initdev; print(initdev.config.get('DEFAULT','env_name'));"
# ./bandz_env/Scripts/pip.exe freeze
# pip freeze > requirements.txt
def _writePrePushHook():
if not os.path.exists(".git/hooks/pre-push"):
with open(".git/hooks/pre-push", "w") as f:
f.write(prePushHook)
return
_writePrePushHook()
def get_sys_env_path():
path = f"./{config.get('DEFAULT','env_name')}/Scripts/pip.exe"
return os.path.normpath(path)
get_sys_env_path()
def _doPrePush():
return
if __name__ == "__main__":
init()