mirror of
https://github.com/ngfchl/ptools
synced 2023-07-10 13:41:22 +08:00
添加初始化Xpath功能,请在更新页面食用
This commit is contained in:
@@ -11,6 +11,7 @@ urlpatterns = [
|
||||
path(r'update', views.update_page, name='update_page'),
|
||||
path(r'do_restart', views.do_restart, name='do_restart'),
|
||||
path(r'do_update', views.do_update, name='do_update'),
|
||||
path(r'do_xpath', views.do_xpath, name='do_xpath'),
|
||||
path(r'import_from_ptpp', views.import_from_ptpp, name='import_from_ptpp'),
|
||||
path(r'page_downloading', views.page_downloading, name='page_downloading'),
|
||||
path(r'get_downloaders', views.get_downloaders, name='get_downloaders'),
|
||||
|
||||
@@ -362,18 +362,12 @@ def exec_command(commands):
|
||||
'command': key,
|
||||
'res': p.returncode
|
||||
})
|
||||
# 休息2秒
|
||||
time.sleep(3)
|
||||
return result
|
||||
|
||||
|
||||
def do_update(request):
|
||||
try:
|
||||
logger.info('开始更新')
|
||||
bt_school = Site.objects.filter(url='http://47.242.110.63/').first()
|
||||
if bt_school:
|
||||
bt_school.url = 'https://pt.btschool.club/'
|
||||
bt_school.save()
|
||||
pt_site_site_mtime = os.stat('pt_site_site.json').st_mtime
|
||||
requirements_mtime = os.stat('requirements.txt').st_mtime
|
||||
update_commands = {
|
||||
@@ -425,8 +419,41 @@ def do_update(request):
|
||||
).to_dict(), safe=False)
|
||||
except Exception as e:
|
||||
# raise
|
||||
msg = '更新失败!{},请初始化Xpath!'.format(str(e))
|
||||
logger.error(msg)
|
||||
return JsonResponse(data=CommonResponse.error(
|
||||
msg='更新失败!' + str(e)
|
||||
msg=msg
|
||||
).to_dict(), safe=False)
|
||||
|
||||
|
||||
def do_xpath(request):
|
||||
"""初始化Xpath规则"""
|
||||
migrate_commands = {
|
||||
'备份数据库': 'cp db/db.sqlite3 db/db.sqlite3-$(date "+%Y%m%d%H%M%S")',
|
||||
'同步数据库': 'python manage.py migrate',
|
||||
}
|
||||
try:
|
||||
logger.info('开始初始化Xpath规则')
|
||||
# p = subprocess.run('cp db/db.sqlite3 db/db.sqlite3-$(date "+%Y%m%d%H%M%S")', shell=True)
|
||||
# logger.info('备份数据库 命令执行结果:\n{}'.format(p))
|
||||
# result = {
|
||||
# 'command': '备份数据库',
|
||||
# 'res': p.returncode
|
||||
# }
|
||||
result = exec_command(migrate_commands)
|
||||
logger.info('初始化Xpath规则 命令执行结果:\n{}'.format(result))
|
||||
return JsonResponse(data=CommonResponse.success(
|
||||
msg='初始化Xpath规则成功!',
|
||||
data={
|
||||
'result': result
|
||||
}
|
||||
).to_dict(), safe=False)
|
||||
except Exception as e:
|
||||
# raise
|
||||
msg = '初始化Xpath失败!{}'.format(str(e))
|
||||
logger.error(msg)
|
||||
return JsonResponse(data=CommonResponse.error(
|
||||
msg=msg
|
||||
).to_dict(), safe=False)
|
||||
|
||||
|
||||
|
||||
@@ -38,6 +38,15 @@
|
||||
v-if="update">更新
|
||||
</el-button>
|
||||
</el-popover>
|
||||
<el-popover
|
||||
placement="top-start"
|
||||
title="友情提示"
|
||||
width="300"
|
||||
trigger="hover"
|
||||
content="如果提示更新失败,可以使用本功能初始化Xpath!!">
|
||||
<el-button slot="reference" type="warning" @click="do_xpath">初始化Xpath
|
||||
</el-button>
|
||||
</el-popover>
|
||||
<el-popover
|
||||
placement="top-start"
|
||||
title="友情提示"
|
||||
@@ -219,7 +228,41 @@
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
do_xpath() {
|
||||
this.$confirm('初始化Xpath, 是否继续?', '提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}).then(() => {
|
||||
axios.get(
|
||||
"{% url "do_xpath" %}", {
|
||||
params: {
|
||||
cid: this.cid
|
||||
}
|
||||
}).then(res => {
|
||||
if (res.data.code === 0) {
|
||||
this.$message({
|
||||
type: 'success',
|
||||
message: res.data.msg
|
||||
});
|
||||
this.time = 15
|
||||
setInterval(this.timeDown, 1000)
|
||||
} else {
|
||||
console.log(res)
|
||||
this.$message({
|
||||
type: 'warning',
|
||||
message: res.data.msg
|
||||
});
|
||||
}
|
||||
})
|
||||
}).catch(res => {
|
||||
{#console.log(res)#}
|
||||
this.$message({
|
||||
type: 'info',
|
||||
message: '已取消重启'
|
||||
});
|
||||
});
|
||||
},
|
||||
do_update() {
|
||||
this.$confirm('此操作会拉取代码并更新软件,是否继续?', '提示', {
|
||||
confirmButtonText: '确定',
|
||||
|
||||
Reference in New Issue
Block a user