Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
蜕变的菜鸟
glances
提交
67fab37d
G
glances
项目概览
蜕变的菜鸟
/
glances
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
glances
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
67fab37d
编写于
5月 13, 2016
作者:
N
nicolargo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Validation OK on online and offline machine
上级
f8d20aba
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
53 addition
and
14 deletion
+53
-14
conf/glances.conf
conf/glances.conf
+8
-0
glances/outdated.py
glances/outdated.py
+45
-14
未找到文件。
conf/glances.conf
浏览文件 @
67fab37d
##############################################################################
# Globals Glances parameters
##############################################################################
[
global
]
# Does Glances should check if a newer version is available on Pypi ?
check_update
=
true
##############################################################################
# User interface
##############################################################################
...
...
glances/outdated.py
浏览文件 @
67fab37d
...
...
@@ -53,14 +53,32 @@ class Outdated(object):
self
.
config
=
config
# Set default value...
self
.
outdated_config_tag
=
True
self
.
data
=
{
'installed_version'
:
__version__
,
'latest_version'
:
'0.0'
,
'refresh_date'
:
None
'refresh_date'
:
datetime
.
now
()
}
# ... and update
# Read the configuration file
self
.
load_config
(
config
)
# And update !
self
.
get_pypi_version
()
def
load_config
(
self
,
config
):
"""Load outdated parameter in the global section of the configuration file."""
global_section
=
'global'
if
(
hasattr
(
config
,
'has_section'
)
and
config
.
has_section
(
global_section
)):
self
.
outdated_config_tag
=
config
.
get_value
(
global_section
,
'check_update'
).
lower
()
==
'true'
logger
.
debug
(
"Check Glances version up-to-date: {0}"
.
format
(
self
.
outdated_config_tag
))
else
:
logger
.
debug
(
"Can not find section {0} in the configuration file"
.
format
(
global_section
))
return
False
return
True
def
installed_version
(
self
):
return
self
.
data
[
'installed_version'
]
...
...
@@ -75,10 +93,13 @@ class Outdated(object):
The data are stored in a cached file
Only update online once a week
"""
if
not
outdated_tag
or
not
self
.
outdated_config_tag
:
return
# If the cached file exist, read-it
cached_data
=
self
.
_load_cache
()
if
outdated_tag
and
cached_data
==
{}:
if
cached_data
==
{}:
# Update needed
# Update and save the cache
thread
=
threading
.
Thread
(
target
=
self
.
_update_pypi_version
)
...
...
@@ -88,6 +109,19 @@ class Outdated(object):
self
.
data
[
'latest_version'
]
=
cached_data
[
'latest_version'
]
logger
.
debug
(
"Get the Glances version from the cache file"
)
def
is_outdated
(
self
):
"""Return True if a new version is available"""
if
not
self
.
self
.
outdated_config_tag
:
# Check is disabled by configuration
return
False
if
not
outdated_tag
:
logger
.
debug
(
"Python Request lib is not installed. Can not get last Glances version on Pypi."
)
return
False
logger
.
debug
(
"Check Glances version (installed: {0} / latest: {1})"
.
format
(
self
.
installed_version
(),
self
.
latest_version
()))
return
LooseVersion
(
self
.
latest_version
())
>
LooseVersion
(
self
.
installed_version
())
def
_load_cache
(
self
):
"""Load cache file and return cached data"""
# If the cached file exist, read-it
...
...
@@ -133,6 +167,10 @@ class Outdated(object):
"""Get the latest Pypi version (as a string) via the Restful JSON API"""
# Get the Nginx status
logger
.
debug
(
"Get latest Glances version from the Pypi Restfull API ({0})"
.
format
(
self
.
PYPI_API_URL
))
# Update the current time
self
.
data
[
'refresh_date'
]
=
datetime
.
now
()
try
:
res
=
requests
.
get
(
self
.
PYPI_API_URL
)
except
Exception
as
e
:
...
...
@@ -141,19 +179,12 @@ class Outdated(object):
if
res
.
ok
:
# Update data
self
.
data
[
'latest_version'
]
=
json
.
loads
(
res
.
text
)[
'info'
][
'version'
]
self
.
data
[
'refresh_date'
]
=
datetime
.
now
()
# Save result to the cache file
self
.
_save_cache
()
logger
.
debug
(
"Save Glances version to the cache file"
)
else
:
logger
.
debug
(
"Can not get the Glances version from the Pypi Restfull API ({0})"
.
format
(
res
.
reason
))
return
self
.
data
# Save result to the cache file
# Note: also saved if the Glances Pypi version can not be grabed
self
.
_save_cache
()
def
is_outdated
(
self
):
"""Return True if a new version is available"""
if
not
outdated_tag
:
logger
.
debug
(
"Python Request lib is not installed. Can not get last Glances version on Pypi."
)
return
False
logger
.
debug
(
"Check Glances version (installed: {0} / latest: {1})"
.
format
(
self
.
installed_version
(),
self
.
latest_version
()))
return
LooseVersion
(
self
.
latest_version
())
>
LooseVersion
(
self
.
installed_version
())
return
self
.
data
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录