-
Notifications
You must be signed in to change notification settings - Fork 1
/
SublimeBLIH.py
196 lines (167 loc) Β· 6.8 KB
/
SublimeBLIH.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
import sublime
import sublime_plugin
import re
import json
import os
import subprocess
if not int(sublime.version()) >= 3000:
import BLIH
else:
from . import BLIH
def git_clone_repo(command):
try:
res = subprocess.check_output(command, stderr=subprocess.STDOUT, shell=True)
except Exception as e:
result = {"code": 400, "data": {"message": str(e)}}
return result
result = {"code": 200, "data": {"message": "Repository cloned"}}
return result
def blih_get_projects(blih):
result = blih.execute("repository", "list")
repos = []
if result and result["code"] == 200:
for repo in result["data"]["repositories"]:
if repo != "":
repos.append(repo)
repos.sort()
return repos
def output_display(window, data):
output = window.create_output_panel("SublimeTek")
window.run_command("show_panel", {"panel": "output.SublimeTek"})
text = ""
for msg in data:
code = msg["code"]
message = ""
for item in msg["data"]:
message += str(msg["data"][item]) + "\n"
if text != "":
text += "\n"
text += "Code " + str(code) + "\n" + str(message)
result = {"text": text}
output.run_command("sublime_tek_blih_output", result)
def replacer(action, repo="", location="", route=""):
print("B4:" + str(action))
settings = sublime.load_settings("SublimeTek.sublime-settings")
blih = settings.get("BLIH")
action = action.replace("$login", settings.get("login")).replace("$server", blih.get("server"))
action = action.replace("$route", route).replace("$repo", repo).replace("$location", location)
print("AFTR:" + str(action))
return action
class SublimeTekBlihOutput(sublime_plugin.TextCommand):
def run(self, edit, **args):
text = args["text"]
self.view.insert(edit, 0, text)
class SublimeTekBlihCreateRepoCommand(sublime_plugin.WindowCommand):
def run(self):
self.settings = sublime.load_settings('SublimeTek.sublime-settings')
self.login = self.settings.get("login")
self.password = self.settings.get("unix_password")
blih_settings = self.settings.get("BLIH")
self.auto_clone = blih_settings.get("auto_clone")
self.ask_folder_clone = blih_settings.get("ask_for_folder_at_clone")
self.default_folder = blih_settings.get("rendu_folder")
self.base_location = blih_settings.get("base_location")
if not self.base_location:
self.base_location = os.getenv("HOME")
self.server = blih_settings.get("server")
self.window.show_input_panel("Type project name", "", self.create_project, None, None)
def create_project(self, name):
self.name = name
self.blih = BLIH.BLIH(self.login, self.password)
self.result = self.blih.execute("repository", "create", body=[self.name])
if self.result["code"] == 200 and self.auto_clone:
if self.ask_folder_clone:
self.window.show_input_panel("Type folder location for this project", str(self.base_location) + str(name), self.set_folder, None, None)
else:
self.set_folder(self.default_folder)
else:
output_display(self.window, [self.result])
def set_folder(self, folder):
route = replacer(self.settings.get("BLIH").get("route"), repo=self.name)
command = replacer(self.settings.get("BLIH").get("clone_command"), location=folder, route=route)
result = git_clone_repo(command)
output_display(self.window, [self.result, result])
class SublimeTekBlihDeleteRepoCommand(sublime_plugin.WindowCommand):
def remove_project(self, name):
if name == self.name:
result = self.blih.execute("repository", "delete", route=[name])
else:
result = {"code": 401, "data": {"message": "Wrong name for confirmation"}}
output_display(self.window, [result])
def confirm(self, index):
if index != -1:
self.name = self.repos[index]
self.window.show_input_panel("Retype project name to confirm deletion (" + self.name + ")", "", self.remove_project, None, None)
def run(self):
settings = sublime.load_settings('SublimeTek.sublime-settings')
self.login = settings.get("login")
self.password = settings.get("unix_password")
self.blih = BLIH.BLIH(self.login, self.password)
self.repos = blih_get_projects(self.blih)
self.window.show_quick_panel(self.repos, self.confirm)
class SublimeTekBlihCloneRepoCommand(sublime_plugin.WindowCommand):
def set_folder(self, folder):
result = git_clone_repo(self.server, self.login, self.name, folder)
output_display(self.window, [result])
def confirm(self, index):
if index != -1:
self.name = self.repos[index]
if self.ask_folder_clone:
self.window.show_input_panel("Type folder location for this project", self.base_location, self.set_folder, None, None)
else:
self.set_folder(self.default_folder)
def run(self):
settings = sublime.load_settings('SublimeTek.sublime-settings')
self.login = settings.get("login")
self.password = settings.get("unix_password")
self.blih = BLIH.BLIH(self.login, self.password)
self.repos = blih_get_projects(self.blih)
blih_settings = settings.get("BLIH")
self.ask_folder_clone = blih_settings.get("ask_for_folder_at_clone")
self.default_folder = settings.get("rendu_folder")
self.base_location = blih_settings.get("base_location")
if not self.base_location:
self.base_location = os.getenv("HOME")
self.server = blih_settings.get("server")
self.window.show_quick_panel(self.repos, self.confirm)
class SublimeTekBlihGetAclsRepoCommand(sublime_plugin.WindowCommand):
def get_acls(self):
result = self.blih.execute("repository", "getacl", route=[self.name])
data = result["data"]
for item in data:
right = data[item]
self.acls.append([item, right])
def show_acls(self):
self.window.show_quick_panel(self.acls, None)
def confirm(self, index):
if index != -1:
self.name = self.repos[index]
self.get_acls()
self.show_acls()
def run(self):
settings = sublime.load_settings('SublimeTek.sublime-settings')
self.login = settings.get("login")
self.password = settings.get("unix_password")
self.blih = BLIH.BLIH(self.login, self.password)
self.repos = blih_get_projects(self.blih)
self.acls = []
self.window.show_quick_panel(self.repos, self.confirm)
class SublimeTekBlihSetAclsRepoCommand(sublime_plugin.WindowCommand):
def set_acls(self, rights):
result = self.blih.execute("repository", "setacl", route=[self.name], body=[self.user_set, rights])
output_display(self.window, [result])
def ask_acls(self, name):
self.user_set = name
self.window.show_input_panel("Type rights for " + self.user_set + " (r/w/a/None to remove ACLs)", "", self.set_acls, None, None)
def confirm(self, index):
if index != -1:
self.name = self.repos[index]
self.window.show_input_panel("Type user login", "", self.ask_acls, None, None)
def run(self):
settings = sublime.load_settings('SublimeTek.sublime-settings')
self.login = settings.get("login")
self.password = settings.get("unix_password")
self.blih = BLIH.BLIH(self.login, self.password)
self.repos = blih_get_projects(self.blih)
self.acls = []
self.window.show_quick_panel(self.repos, self.confirm)