update
This commit is contained in:
parent
fe63f684f3
commit
eba73c71bc
|
|
@ -0,0 +1,2 @@
|
|||
#!/bin/bash
|
||||
|
||||
|
|
@ -764,6 +764,168 @@ def projectScriptSelf():
|
|||
user = args['user']
|
||||
name = args['name'] + '.git'
|
||||
|
||||
custom_hooks = getRootPath() + '/' + user + '/' + \
|
||||
name + '/custom_hooks'
|
||||
self_path = custom_hooks + '/self'
|
||||
|
||||
if not os.path.exists(self_path):
|
||||
os.mkdir(self_path)
|
||||
|
||||
self_hook_file = custom_hooks + '/self_hook.sh'
|
||||
self_hook_exist = False
|
||||
if os.path.exists(self_hook_file):
|
||||
self_hook_exist = True
|
||||
|
||||
dlist = []
|
||||
if os.path.exists(self_path):
|
||||
for filename in os.listdir(self_path):
|
||||
tmp = {}
|
||||
filePath = self_path + '/' + filename
|
||||
if os.path.isfile(filePath):
|
||||
tmp['path'] = filePath
|
||||
tmp['name'] = os.path.basename(filePath)
|
||||
dlist.append(tmp)
|
||||
|
||||
dlist_sum = len(dlist)
|
||||
# print(dlist)
|
||||
rdata = {}
|
||||
rdata['data'] = dlist
|
||||
rdata['self_hook'] = self_hook_exist
|
||||
rdata['list'] = mw.getPage(
|
||||
{'count': dlist_sum, 'p': 1, 'row': 100, 'tojs': 'self_page'})
|
||||
|
||||
return mw.returnJson(True, 'ok', rdata)
|
||||
|
||||
|
||||
def projectScriptSelf_Create():
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['user', 'name', 'file'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
user = args['user']
|
||||
name = args['name'] + '.git'
|
||||
file = args['file']
|
||||
|
||||
self_path = path = getRootPath() + '/' + user + '/' + \
|
||||
name + '/custom_hooks/self'
|
||||
|
||||
if not os.path.exists(self_path):
|
||||
os.mkdir(self_path)
|
||||
|
||||
abs_file = self_path + '/' + file + '.sh'
|
||||
if os.path.exists(abs_file):
|
||||
return mw.returnJson(False, '脚本已经存在!')
|
||||
|
||||
mw.writeFile(abs_file, "#!/bin/bash\n")
|
||||
|
||||
rdata = {}
|
||||
rdata['abs_file'] = abs_file
|
||||
return mw.returnJson(True, '创建文件成功!', rdata)
|
||||
|
||||
|
||||
def projectScriptSelf_Del():
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['user', 'name', 'file'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
user = args['user']
|
||||
name = args['name'] + '.git'
|
||||
file = args['file']
|
||||
|
||||
self_path = path = getRootPath() + '/' + user + '/' + \
|
||||
name + '/custom_hooks/self'
|
||||
|
||||
if not os.path.exists(self_path):
|
||||
os.mkdir(self_path)
|
||||
|
||||
abs_file = self_path + '/' + file
|
||||
# print(abs_file)
|
||||
if not os.path.exists(abs_file):
|
||||
return mw.returnJson(False, '脚本已经删除!')
|
||||
|
||||
os.remove(abs_file)
|
||||
return mw.returnJson(True, '脚本删除成功!')
|
||||
|
||||
|
||||
def projectScriptSelf_Logs():
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['user', 'name', 'file'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
user = args['user']
|
||||
name = args['name'] + '.git'
|
||||
file = args['file']
|
||||
|
||||
self_path = path = getRootPath() + '/' + user + '/' + \
|
||||
name + '/custom_hooks/self_logs'
|
||||
|
||||
if not os.path.exists(self_path):
|
||||
os.mkdir(self_path)
|
||||
|
||||
logs_file = self_path + '/' + file + '.log'
|
||||
if os.path.exists(logs_file):
|
||||
rdata = {}
|
||||
rdata['path'] = logs_file
|
||||
return mw.returnJson(True, '脚本已经删除!', rdata)
|
||||
|
||||
return mw.returnJson(False, '日志不存在!')
|
||||
|
||||
|
||||
def projectScriptSelf_Rename():
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['user', 'name', 'o_file', 'n_file'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
user = args['user']
|
||||
name = args['name'] + '.git'
|
||||
o_file = args['o_file']
|
||||
n_file = args['n_file']
|
||||
|
||||
self_path = path = getRootPath() + '/' + user + '/' + \
|
||||
name + '/custom_hooks/self'
|
||||
|
||||
if not os.path.exists(self_path):
|
||||
os.mkdir(self_path)
|
||||
|
||||
o_file_abs = self_path + '/' + o_file + '.sh'
|
||||
if not os.path.exists(o_file_abs):
|
||||
return mw.returnJson(False, '原文件已经不存在了!')
|
||||
|
||||
n_file_abs = self_path + '/' + n_file + '.sh'
|
||||
|
||||
os.rename(o_file_abs, n_file_abs)
|
||||
return mw.returnJson(True, '重命名成功!')
|
||||
|
||||
|
||||
def projectScriptSelf_Enable():
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['user', 'name', 'enable'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
user = args['user']
|
||||
name = args['name'] + '.git'
|
||||
enable = args['enable']
|
||||
|
||||
custom_path = getRootPath() + '/' + user + '/' + \
|
||||
name + '/custom_hooks'
|
||||
self_file = custom_path + '/self_hook.sh'
|
||||
self_hook_tpl = getPluginDir() + '/hook/self_hook.tpl'
|
||||
|
||||
if enable == '1':
|
||||
content = mw.readFile(self_hook_tpl)
|
||||
mw.writeFile(self_file, content)
|
||||
mw.execShell("chmod 777" + self_file)
|
||||
return mw.returnJson(True, '开启成功!')
|
||||
else:
|
||||
if os.path.exists(self_file):
|
||||
os.remove(self_file)
|
||||
return mw.returnJson(True, '关闭成功!')
|
||||
|
||||
|
||||
def getRsaPublic():
|
||||
path = getHomeDir()
|
||||
|
|
@ -842,6 +1004,16 @@ if __name__ == "__main__":
|
|||
print(projectScriptRun())
|
||||
elif func == 'project_script_self':
|
||||
print(projectScriptSelf())
|
||||
elif func == 'project_script_self_create':
|
||||
print(projectScriptSelf_Create())
|
||||
elif func == 'project_script_self_del':
|
||||
print(projectScriptSelf_Del())
|
||||
elif func == 'project_script_self_logs':
|
||||
print(projectScriptSelf_Logs())
|
||||
elif func == 'project_script_self_rename':
|
||||
print(projectScriptSelf_Rename())
|
||||
elif func == 'project_script_self_enable':
|
||||
print(projectScriptSelf_Enable())
|
||||
elif func == 'get_rsa_public':
|
||||
print(getRsaPublic())
|
||||
elif func == 'get_total_statistics':
|
||||
|
|
|
|||
|
|
@ -305,7 +305,7 @@ function gogsRepoListPage(page, search){
|
|||
option += '<a class="btlink edit" data-index="'+i+'">编辑</a>' + ' | ';
|
||||
option += '<a class="btlink debug" data-index="'+i+'">日志</a>' + ' | ';
|
||||
option += '<a class="btlink run" data-index="'+i+'">手动</a>' + ' | ';
|
||||
option += '<a class="btlink scripts" data-index="'+i+'" onclick="projectScriptDebug(\''+ulist[i]["name"]+'\',\''+ulist[i]["repo"]+'\')" >自定义</a>';
|
||||
option += '<a class="btlink scripts" data-index="'+i+'" onclick="projectScriptSelf(\''+ulist[i]["name"]+'\',\''+ulist[i]["repo"]+'\')" >自定义</a>';
|
||||
} else{
|
||||
option += '<a data-index="'+i+'" class="btlink load">加载脚本</a>';
|
||||
}
|
||||
|
|
@ -321,9 +321,6 @@ function gogsRepoListPage(page, search){
|
|||
'</tr>';
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
$('#repo_list tbody').html(body);
|
||||
$('#repo_list_page').html(rdata['data']['list']);
|
||||
|
||||
|
|
@ -402,14 +399,9 @@ function gogsRepoListPage(page, search){
|
|||
|
||||
gogsPost('project_script_run', {'user':user,'name':name}, function(data){
|
||||
var data = $.parseJSON(data.data);
|
||||
layer.msg(data.msg,{icon:data.code?2:1,time:2000,shade: [0.3, '#000']});
|
||||
layer.msg(data.msg,{icon:data.status?2:1,time:2000,shade: [0.3, '#000']});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//---------
|
||||
});
|
||||
|
|
@ -519,6 +511,199 @@ function projectScriptDebug(user,name){
|
|||
});
|
||||
}
|
||||
|
||||
|
||||
function projectScriptSelfRender(user, name){
|
||||
gogsPost('project_script_self', {'user':user,'name':name}, function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
|
||||
var data = rdata['data']['data'];
|
||||
|
||||
if (rdata['data']['self_hook']){
|
||||
$('#open_script').prop('checked',true);
|
||||
}
|
||||
|
||||
var body = '';
|
||||
if(data.length == 0 ){
|
||||
body += '<tr><td colspan="3" style="text-align:center;">无脚本数据</td></tr>';
|
||||
} else{
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
body += '<tr>'+
|
||||
'<td>' + data[i]["name"]+'</td>'+
|
||||
'<td>' + '<a class="btlink" target="_blank">已使用</a>'+'</td>'+
|
||||
'<td>' +
|
||||
'<a class="btlink del" data-index="'+i+'" target="_blank">删除</a>' + ' | ' +
|
||||
'<a class="btlink edit" data-index="'+i+'" target="_blank">编辑</a>' + ' | ' +
|
||||
'<a class="btlink logs" data-index="'+i+'" target="_blank">日志</a>' + ' | ' +
|
||||
'<a class="btlink rename" data-index="'+i+'" target="_blank">重命名</a>' +
|
||||
'</td></tr>';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$('#gogs_self_table tbody').html(body);
|
||||
$('#gogs_self_table .page').html(rdata['data']['list']);
|
||||
|
||||
$('#gogs_self_table .del').click(function(){
|
||||
var i = $(this).data('index');
|
||||
var file = data[i]["name"];
|
||||
gogsPost('project_script_self_del', {'user':user,'name':name,'file':file}, function(data){
|
||||
var data = $.parseJSON(data.data);
|
||||
showMsg(data.msg ,function(){
|
||||
projectScriptSelfRender(user, name);
|
||||
},{icon:data.code?2:1,time:2000,shade: [0.3, '#000']},2000);
|
||||
});
|
||||
});
|
||||
|
||||
$('#gogs_self_table .edit').click(function(){
|
||||
var i = $(this).data('index');
|
||||
var path = data[i]["path"];
|
||||
onlineEditFile(0,path);
|
||||
});
|
||||
|
||||
$('#gogs_self_table .logs').click(function(){
|
||||
var i = $(this).data('index');
|
||||
var file = data[i]["name"];
|
||||
gogsPost('project_script_self_logs', {'user':user,'name':name,'file':file}, function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
if (rdata['status']){
|
||||
onlineEditFile(0, rdata['path']);
|
||||
} else {
|
||||
layer.msg(rdata.msg,{icon:data.status?2:1,time:2000,shade: [0.3, '#000']});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
$('#gogs_self_table .rename').click(function(){
|
||||
var i = $(this).data('index');
|
||||
var file = data[i]["name"];
|
||||
file = file.split('.sh')[0];
|
||||
|
||||
layer.open({
|
||||
type: 1,
|
||||
shift: 5,
|
||||
closeBtn: 1,
|
||||
area: '320px',
|
||||
title: '重命名',
|
||||
btn:['设置','关闭'],
|
||||
content: '<div class="bt-form pd20">\
|
||||
<div class="line">\
|
||||
<input type="text" class="bt-input-text" name="Name" id="newFileName" value="'+file+'" placeholder="文件名" style="width:100%" />\
|
||||
</div>\
|
||||
</div>',
|
||||
success:function(){
|
||||
$("#newFileName").focus().keyup(function(e){
|
||||
if(e.keyCode == 13) $(".layui-layer-btn0").click();
|
||||
});
|
||||
},
|
||||
yes:function(){
|
||||
var n_file = $("#newFileName").val();
|
||||
var o_file = file;
|
||||
|
||||
gogsPost('project_script_self_rename', {'user':user,'name':name,'o_file':o_file,'n_file':n_file}, function(data){
|
||||
var data = $.parseJSON(data.data);
|
||||
showMsg(data.msg ,function(){
|
||||
$(".layui-layer-btn1").click();
|
||||
projectScriptSelfRender(user, name);
|
||||
},{icon:data.code?2:1,time:2000,shade: [0.3, '#000']},2000);
|
||||
});
|
||||
}
|
||||
});
|
||||
//-----
|
||||
});
|
||||
//------
|
||||
});
|
||||
}
|
||||
|
||||
//新建文件
|
||||
function createScriptFile(type, user, name, file) {
|
||||
if (type == 1) {
|
||||
gogsPost('project_script_self_create', {'user':user,'name':name,'file': file }, function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
if(!rdata['status']){
|
||||
layer.msg(rdata.msg,{icon:2,time:2000,shade: [0.3, '#000']});
|
||||
return;
|
||||
}
|
||||
|
||||
showMsg(rdata.msg, function(){
|
||||
$(".layui-layer-btn1").click();
|
||||
onlineEditFile(0,rdata['data']['abs_file']);
|
||||
projectScriptSelfRender(user, name);
|
||||
}, {icon:1,shade: [0.3, '#000']},2000);
|
||||
});
|
||||
return;
|
||||
}
|
||||
layer.open({
|
||||
type: 1,
|
||||
shift: 5,
|
||||
closeBtn: 1,
|
||||
area: '320px',
|
||||
title: '新建自定义脚本',
|
||||
btn:['新建','关闭'],
|
||||
content: '<div class="bt-form pd20">\
|
||||
<div class="line">\
|
||||
<input type="text" class="bt-input-text" name="Name" id="newFileName" value="" placeholder="文件名" style="width:100%" />\
|
||||
</div>\
|
||||
</div>',
|
||||
success:function(){
|
||||
$("#newFileName").focus().keyup(function(e){
|
||||
if(e.keyCode == 13) $(".layui-layer-btn0").click();
|
||||
});
|
||||
},
|
||||
yes:function(){
|
||||
var file = $("#newFileName").val();;
|
||||
createScriptFile(1, user, name, file);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function projectScriptSelf(user, name){
|
||||
layer.open({
|
||||
type: 1,
|
||||
title: '项目('+user+'/'+name+')自定义脚本',
|
||||
area: '500px',
|
||||
content:"<div class='bt-form pd15'>\
|
||||
<button id='create_script' class='btn btn-success btn-sm' type='button' style='margin-right: 5px;''>添加脚本</button>\
|
||||
<div style='float:right;'>\
|
||||
<span style='line-height: 23px;'>开启自定义脚本</span>\
|
||||
<input class='btswitch btswitch-ios' id='open_script' type='checkbox'>\
|
||||
<label id='script_hook_enable' class='btswitch-btn' for='open_script' style='display: inline-flex;line-height:38px;margin-left: 4px;float: right;'></label>\
|
||||
</div>\
|
||||
<div id='gogs_self_table' class='divtable' style='margin-top:5px;'>\
|
||||
<table class='table table-hover'>\
|
||||
<thead><tr><th style='width:100px;'>脚本文件名</th><th>状态</th><th>操作</th></tr></thead>\
|
||||
<tbody></tbody>\
|
||||
</table>\
|
||||
<div class='dataTables_paginate paging_bootstrap pagination' style='margin-top:0px;'>\
|
||||
<ul class='page'><div class='gogs_page'></div></ul>\
|
||||
</div>\
|
||||
</div>\
|
||||
</div>",
|
||||
success:function(){
|
||||
projectScriptSelfRender(user, name);
|
||||
|
||||
$('#create_script').click(function(){
|
||||
createScriptFile(0, user, name);
|
||||
});
|
||||
|
||||
$('#script_hook_enable').click(function(){
|
||||
var enable = $('#open_script').prop('checked');
|
||||
var enable_option = '0';
|
||||
if (!enable){
|
||||
enable_option = '1';
|
||||
}
|
||||
gogsPost('project_script_self_enable', {'user':user,'name':name,'enable':enable_option}, function(data){
|
||||
var data = $.parseJSON(data.data);
|
||||
showMsg(data.msg ,function(){
|
||||
projectScriptSelfRender(user, name);
|
||||
},{icon:data.status?1:2,shade: [0.3, '#000']},2000);
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function getRsaPublic(){
|
||||
gogsPost('get_rsa_public', {}, function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
|
|
|
|||
Loading…
Reference in New Issue