diff --git a/auto_pt/urls.py b/auto_pt/urls.py index c3cca7f..74f4541 100644 --- a/auto_pt/urls.py +++ b/auto_pt/urls.py @@ -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'), diff --git a/auto_pt/views.py b/auto_pt/views.py index ff52a7b..5c6ab60 100644 --- a/auto_pt/views.py +++ b/auto_pt/views.py @@ -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) diff --git a/templates/auto_pt/update.html b/templates/auto_pt/update.html index 8b2fc1e..f8ef274 100644 --- a/templates/auto_pt/update.html +++ b/templates/auto_pt/update.html @@ -38,6 +38,15 @@ v-if="update">更新 + + 初始化Xpath + + { + 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: '确定',