-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
155 lines (140 loc) · 3.95 KB
/
app.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
from flask import Flask, request
from flask_cors import CORS
from util.file_manager import FileManager
from util.github_manager import Github
import os
app = Flask(__name__)
CORS(app)
#initialize file manager
root_path = os.getcwd()+'/Projects'
print(root_path)
file_manager = FileManager(root=root_path)
github_manager = Github()
#get root directory files/folders
@app.route("/")
def root():
root_path = file_manager.get_root_dir()
file_manager.change_cur_dir(root_path)
return {
"message": file_manager.list_directory(root_path),
"cur_dir": file_manager.cur_dir,
"root_dir": file_manager.root
}
#get cur directory files/folder
#create directory
@app.route("/mkdir/<dir_name>")
def mkdir(dir_name):
cur_dir = file_manager.cur_dir
mkdir_status = file_manager.mkdir(dir_name)
return {
"message": file_manager.list_directory(cur_dir),
"cur_dir": file_manager.cur_dir,
"root_dir": file_manager.root,
"success": mkdir_status
}
#navigate to a folder
@app.route("/forward-nav/<dir>")
def forward_nav(dir):
root_path = file_manager.get_root_dir()
cur_dir = file_manager.change_cur_dir(dir)
return {
"cur_dir": cur_dir,
"root_dir": root_path,
"message": file_manager.list_directory(cur_dir)
}
#go back a folder
@app.route("/backward/<path:subpath>")
def backward_nav(subpath):
root_path = file_manager.get_root_dir()
cur_dir = file_manager.navbypath(subpath)
return {
"cur_dir": cur_dir,
"root_dir": root_path,
"message": file_manager.list_directory(cur_dir)
}
#launch browser
@app.route("/launch-browser")
def launchBrowser():
cur_dir = file_manager.cur_dir
try:
file_manager.launchBroswerWindowAtPath(cur_dir)
return {
"message": "success"
}
except:
return {
"message": "failure"
}
#launch terminal
@app.route("/launch-terminal")
def launchTerminal():
try:
file_manager.launchTerminalAtPath()
return {
"message": "success"
}
except:
return {
"message": "failure"
}
#launch vscode:
@app.route('/launch-vscode')
def vsCodeLaunch():
try:
file_manager.launchCodeEditor()
return {
"message": "success"
}
except:
return {
"message": "failure"
}
#clone a repo:
@app.route('/clone', methods=['POST'])
def clone_git_repo():
req = request.get_json()
remote = req['remote']
cur_dir = file_manager.cur_dir
clone_status = github_manager.git_clone(remote)
if clone_status:
return {
"message": file_manager.list_directory(cur_dir),
"cur_dir": file_manager.cur_dir,
"root_dir": file_manager.root,
"success": clone_status
}
return {
"message": file_manager.list_directory(cur_dir),
"cur_dir": file_manager.cur_dir,
"root_dir": file_manager.root,
"success": clone_status
}
#make first commit to remote repo
@app.route('/create-repo', methods=['POST'])
def create_first_repo():
req = request.get_json()
remote = req['remote']
cur_dir = file_manager.cur_dir
git_status = github_manager.create_new_repo(remote)
return {
"message": file_manager.list_directory(cur_dir),
"cur_dir": file_manager.cur_dir,
"root_dir": file_manager.root,
"success": git_status
}
#commit changes options-[all, select folders]
@app.route('/push-changes', methods=["POST"])
def push_changes_to_git():
req = request.get_json()
commit_message = req['commit_message']
#cur_dir = file_manager.cur_dir
push_status = github_manager.push_changes_to_github(commit_message)
return {
'success': push_status
}
#check git status
#pull changes
#integrate netlify
#integrate heroku
if __name__ == "__main__":
app.run(host='localhost', port=8009, debug=True)