diff --git a/auto_pt/views.py b/auto_pt/views.py
index 8a4b8b9..a1ea30e 100644
--- a/auto_pt/views.py
+++ b/auto_pt/views.py
@@ -165,14 +165,16 @@ def restart_container(request):
# res = scraper.get('https://gitee.com/ngfchl/ptools/raw/master/update.md')
# update_md = markdown.markdown(res.text, extensions=['tables'])
# 获取docker对象
- client = docker.from_env()
- # 从内部获取容器id
- cid = socket.gethostname()
- started_at = client.api.inspect_container(cid).get('State').get('StartedAt')[:19]
- UTC_FORMAT = "%Y-%m-%dT%H:%M:%S"
- utc_time = datetime.strptime(started_at, UTC_FORMAT)
- delta = datetime.now() - utc_time
-
+ try:
+ client = docker.from_env()
+ # 从内部获取容器id
+ cid = socket.gethostname()
+ started_at = client.api.inspect_container(cid).get('State').get('StartedAt')[:19]
+ UTC_FORMAT = "%Y-%m-%dT%H:%M:%S"
+ utc_time = datetime.strptime(started_at, UTC_FORMAT)
+ delta = (datetime.now() - utc_time).seconds
+ except Exception as e:
+ delta = ''
if get_update_logs():
update = 'false'
update_tips = '目前您使用的是最新版本!'
@@ -181,7 +183,7 @@ def restart_container(request):
update_tips = '已有新版本,请根据需要升级!'
return render(request, 'auto_pt/restart.html',
context={
- 'delta': delta.seconds,
+ 'delta': delta,
'local_logs': get_git_logs(),
'update_notes': get_git_logs(master='origin/master'),
'update': update,
diff --git a/templates/auto_pt/restart.html b/templates/auto_pt/restart.html
index 843431f..c8c3d7b 100644
--- a/templates/auto_pt/restart.html
+++ b/templates/auto_pt/restart.html
@@ -16,11 +16,12 @@
width="200"
trigger="hover"
content="如果遇到无法更新的情况,您可以选择重建容器或者进入容器命令行到项目根目录执行`git pull`命令!">
- {{ update_tips }} + 启动时间:{{ delta }}
+ {{ update_tips }} + 启动时间:{{ delta }}
-{# 获取更新#}
+{# 刷新页面#}
更新
重启
@@ -28,9 +29,9 @@
-
+
@@ -98,107 +99,106 @@
el: '#app',
data: {
update_notes: {{ update_notes | safe }},
- local_logs: {{ local_logs | safe }} ,
+ local_logs: {{ local_logs | safe }},
local_log: [],
- update_log:[],
- update: false,
- local_log_width:24,
- },
- created()
- {
- this.update = {{ update }}
-
- if (this.update) {
- this.local_log_width = 12
-
- }
- this.$message({
- showClose: true,
- message: "{{ update_tips }}",
- type: 'success'
- });
- }
- ,
- methods: {
- do_restart()
- {
- this.$confirm('此操作将重启容器,并更新软件, 是否继续?', '提示', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning'
- }).then(() => {
- axios.get(
- "{% url "do_restart" %}"
- ).then(res => {
- if (res.data.code === 0) {
- this.$message({
- type: 'success',
- message: res.data.msg
- });
- } else {
- console.log(res)
- this.$message({
- type: 'warning',
- message: res.data.msg
- });
- }
- this.reload()
- }).catch(res => {
- this.$message({
- type: 'error',
- message: "重启失败!"
- });
- })
- }).catch(res => {
- {#console.log(res)#}
- this.$message({
- type: 'info',
- message: '已取消重启'
- });
- });
+ update_log: [],
+ update: {{ update }},
+ local_log_width: 24,
},
+ created() {
- do_update()
- {
- this.$confirm('此操作会拉取软件更新软件,新版本不一定稳定,是否继续?', '提示', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning'
- }).then(() => {
- axios.get(
- "{% url "do_update" %}"
- ).then(res => {
- if (res.data.code === 0) {
- console.log(res, 1)
- this.update_log = res.data.data
+ if (this.update) {
+ this.local_log_width = 12
+
+ }
+ this.$message({
+ showClose: true,
+ message: "{{ update_tips }}",
+ type: 'success'
+ });
+ }
+ ,
+ methods: {
+ do_refresh() {
+ },
+ do_restart() {
+ this.$confirm('此操作将重启容器,并更新软件, 是否继续?', '提示', {
+ confirmButtonText: '确定',
+ cancelButtonText: '取消',
+ type: 'warning'
+ }).then(() => {
+ axios.get(
+ "{% url "do_restart" %}"
+ ).then(res => {
+ if (res.data.code === 0) {
+ this.$message({
+ type: 'success',
+ message: res.data.msg
+ });
+ } else {
+ console.log(res)
+ this.$message({
+ type: 'warning',
+ message: res.data.msg
+ });
+ }
+ }).catch(res => {
+ this.$message({
+ type: 'error',
+ message: "重启失败!"
+ });
+ })
+ location.reload()
+
+ }).catch(res => {
+ {#console.log(res)#}
this.$message({
- type: 'success',
- message: res.data.msg
+ type: 'info',
+ message: '已取消重启'
});
- } else {
- console.log(res, 2)
+ });
+ },
+
+ do_update() {
+ this.$confirm('此操作会拉取软件更新软件,新版本不一定稳定,是否继续?', '提示', {
+ confirmButtonText: '确定',
+ cancelButtonText: '取消',
+ type: 'warning'
+ }).then(() => {
+ axios.get(
+ "{% url "do_update" %}"
+ ).then(res => {
+ if (res.data.code === 0) {
+ console.log(res, 1)
+ this.update_log = res.data.data
+ this.$message({
+ type: 'success',
+ message: res.data.msg
+ });
+ } else {
+ console.log(res, 2)
+ this.$message({
+ type: 'warning',
+ message: res.data.msg
+ });
+ }
+ }).catch(res => {
+ console.log(res, 3)
+ this.$message({
+ type: 'error',
+ message: "更新失败!"
+ });
+ })
+ location.reload()
+
+ }).catch(res => {
+ console.log(res)
this.$message({
type: 'warning',
- message: res.data.msg
+ message: '已取消更新'
});
- }
- this.reload()
- }).catch(res => {
- console.log(res, 3)
- this.$message({
- type: 'error',
- message: "更新失败!"
});
- })
-
- }).catch(res => {
- console.log(res)
- this.$message({
- type: 'warning',
- message: '已取消更新'
- });
- });
- }
- }
+ }
+ }
});