mirror of
https://github.com/ngfchl/ptools
synced 2023-07-10 13:41:22 +08:00
1. 规则更新独立出来,更新前备份数据库,防止自行添加的规则覆盖
2. 更新程序时被分数据库操作取消,这个只更新代码 3. 增加更新操作提示,优化提醒
This commit is contained in:
@@ -203,6 +203,25 @@ def do_update(request):
|
||||
for i in out:
|
||||
result.append(i.decode('utf8'))
|
||||
print(result)
|
||||
return JsonResponse(data=CommonResponse.success(
|
||||
msg='更新成功!!',
|
||||
data={
|
||||
'result': result,
|
||||
# 'xpath_update': xpath_update
|
||||
}).to_dict(), safe=False)
|
||||
except Exception as e:
|
||||
return JsonResponse(data=CommonResponse.error(
|
||||
msg='更新指令发送失败!' + str(e)
|
||||
).to_dict(), safe=False)
|
||||
|
||||
|
||||
def do_update_xpath(request):
|
||||
try:
|
||||
# 备份数据库
|
||||
subprocess.Popen(
|
||||
'cp /var/www/html/ptools/db/db.sqlite3 /var/www/html/ptools/db/db.sqlite3-$(date "+%Y%m%d%H%M%S")',
|
||||
shell=True
|
||||
)
|
||||
# 更新数据库
|
||||
with open('./pt_site_site.json', 'r') as f:
|
||||
# print(f.readlines())
|
||||
@@ -215,17 +234,16 @@ def do_update(request):
|
||||
if site.get('pk'):
|
||||
del site['pk']
|
||||
site_obj = Site.objects.update_or_create(defaults=site, url=site.get('url'))
|
||||
xpath_update.append(site_obj)
|
||||
print(site_obj)
|
||||
xpath_update.append(site_obj[0].name + ' 规则新增成功!' if site_obj[1] else '更新成功!')
|
||||
return JsonResponse(data=CommonResponse.success(
|
||||
msg='更新成功!!',
|
||||
data={
|
||||
'result': result,
|
||||
# 'xpath_update': xpath_update
|
||||
'update_log': xpath_update
|
||||
}).to_dict(), safe=False)
|
||||
except Exception as e:
|
||||
return JsonResponse(data=CommonResponse.error(
|
||||
msg='更新指令发送失败!' + str(e)
|
||||
msg='更新失败!' + str(e)
|
||||
).to_dict(), safe=False)
|
||||
|
||||
|
||||
|
||||
@@ -22,9 +22,29 @@
|
||||
</span>
|
||||
<span style="float: right;margin-top: -10px">
|
||||
{# <el-button type="primary" @click="do_refresh">刷新页面</el-button>#}
|
||||
{# <el-button type="success" @click="do_update">更新</el-button>#}
|
||||
<el-button type="success" @click="do_update" v-if="update">更新</el-button>
|
||||
<el-button type="danger" @click="do_restart">重启</el-button>
|
||||
<el-popover
|
||||
placement="top-start"
|
||||
{# title="友情提示"#}
|
||||
width="200"
|
||||
trigger="hover"
|
||||
content="此操作会覆盖已支持站点在本地数据库中的规则,不支持的站点无操作">
|
||||
<el-button slot="reference" type="success" @click="do_update_xpath">规则更新</el-button>
|
||||
</el-popover>
|
||||
<el-popover
|
||||
placement="top-start"
|
||||
width="200"
|
||||
trigger="hover"
|
||||
content="此操作只更新代码,不更新规则,代码更新要生效必须重启!">
|
||||
<el-button slot="reference" type="success" @click="do_update" v-if="update">代码更新</el-button>
|
||||
</el-popover>
|
||||
<el-popover
|
||||
placement="top-start"
|
||||
width="200"
|
||||
trigger="hover"
|
||||
content="只有在容器中部署才能使用本操作,其他环境部署无效">
|
||||
<el-button slot="reference" type="danger" @click="do_restart">重启容器</el-button>
|
||||
</el-popover>
|
||||
|
||||
</span>
|
||||
</div>
|
||||
<div class="text item">
|
||||
@@ -118,7 +138,40 @@
|
||||
}
|
||||
,
|
||||
methods: {
|
||||
do_refresh() {
|
||||
do_update_xpath() {
|
||||
this.$confirm('此操作将覆盖本地规则,请提前备份,是否继续?', '提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}).then(() => {
|
||||
axios.get(
|
||||
"{% url "do_update_xpath" %}"
|
||||
).then(res => {
|
||||
if (res.data.code === 0) {
|
||||
this.$message({
|
||||
type: 'success',
|
||||
message: res.data.msg
|
||||
});
|
||||
this.update_log = res.data.data.update_log
|
||||
} else {
|
||||
console.log(res)
|
||||
this.$message({
|
||||
type: 'warning',
|
||||
message: res.data.msg
|
||||
});
|
||||
}
|
||||
}).catch(res => {
|
||||
this.$message({
|
||||
type: 'error',
|
||||
message: "更新失败!"
|
||||
});
|
||||
})
|
||||
}).catch(res => {
|
||||
this.$message({
|
||||
type: 'info',
|
||||
message: '已取消更新'
|
||||
});
|
||||
});
|
||||
},
|
||||
do_restart() {
|
||||
this.$confirm('此操作将重启容器,并更新软件, 是否继续?', '提示', {
|
||||
@@ -174,8 +227,6 @@
|
||||
type: 'success',
|
||||
message: res.data.msg
|
||||
});
|
||||
location.reload()
|
||||
|
||||
} else {
|
||||
console.log(res, 2)
|
||||
this.$message({
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# 先备份数据库文件再拉取更新 $(date "+%Y%m%d%H%M%S")当前时间年月日时分秒
|
||||
cp /var/www/html/ptools/db/db.sqlite3 /var/www/html/ptools/db/db.sqlite3-$(date "+%Y%m%d%H%M%S") &&
|
||||
#cp /var/www/html/ptools/db/db.sqlite3 /var/www/html/ptools/db/db.sqlite3-$(date "+%Y%m%d%H%M%S") &&
|
||||
git pull &&
|
||||
mv -f /var/www/html/ptools/start.sh /var/www/html/start.sh &&
|
||||
python manage.py makemigrations &&
|
||||
|
||||
Reference in New Issue
Block a user