Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
蜕变的菜鸟
glances
提交
3f0094fa
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,发现更多精彩内容 >>
提交
3f0094fa
编写于
3月 12, 2017
作者:
A
Alessio Sergi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Drop requests to check for outdated Glances version
上级
7ecafebd
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
21 addition
and
35 deletion
+21
-35
glances/compat.py
glances/compat.py
+2
-2
glances/outdated.py
glances/outdated.py
+19
-33
未找到文件。
glances/compat.py
浏览文件 @
3f0094fa
...
...
@@ -34,7 +34,7 @@ if PY3:
from
xmlrpc.client
import
Fault
,
ProtocolError
,
ServerProxy
,
Transport
from
xmlrpc.server
import
SimpleXMLRPCRequestHandler
,
SimpleXMLRPCServer
from
urllib.request
import
urlopen
from
urllib.error
import
URLError
from
urllib.error
import
HTTPError
,
URLError
input
=
input
range
=
range
...
...
@@ -89,7 +89,7 @@ else:
from
ConfigParser
import
SafeConfigParser
as
ConfigParser
,
NoOptionError
,
NoSectionError
from
SimpleXMLRPCServer
import
SimpleXMLRPCRequestHandler
,
SimpleXMLRPCServer
from
xmlrpclib
import
Fault
,
ProtocolError
,
ServerProxy
,
Transport
from
urllib2
import
urlopen
,
URLError
from
urllib2
import
urlopen
,
HTTPError
,
URLError
input
=
raw_input
range
=
xrange
...
...
glances/outdated.py
浏览文件 @
3f0094fa
...
...
@@ -25,29 +25,23 @@ import threading
import
json
import
pickle
import
os
try
:
import
requests
except
ImportError
:
outdated_tag
=
False
else
:
outdated_tag
=
True
from
glances
import
__version__
from
glances.compat
import
nativestr
,
urlopen
,
HTTPError
,
URLError
from
glances.config
import
user_cache_dir
from
glances.globals
import
safe_makedirs
from
glances.logger
import
logger
PYPI_API_URL
=
'https://pypi.python.org/pypi/Glances/json'
class
Outdated
(
object
):
"""
This class aims at providing methods to warn the user when a new Glances
version is available on the Py
pi
repository (https://pypi.python.org/pypi/Glances/).
version is available on the Py
PI
repository (https://pypi.python.org/pypi/Glances/).
"""
PYPI_API_URL
=
'https://pypi.python.org/pypi/Glances/json'
max_refresh_date
=
timedelta
(
days
=
7
)
def
__init__
(
self
,
args
,
config
):
"""Init the Outdated class"""
self
.
args
=
args
...
...
@@ -91,11 +85,11 @@ class Outdated(object):
return
self
.
data
[
'refresh_date'
]
def
get_pypi_version
(
self
):
"""Wrapper to get the latest Py
pi
version (async)
"""Wrapper to get the latest Py
PI
version (async)
The data are stored in a cached file
Only update online once a week
"""
if
not
outdated_tag
or
self
.
args
.
disable_check_update
:
if
self
.
args
.
disable_check_update
:
return
# If the cached file exist, read-it
...
...
@@ -109,7 +103,7 @@ class Outdated(object):
else
:
# Update not needed
self
.
data
[
'latest_version'
]
=
cached_data
[
'latest_version'
]
logger
.
debug
(
"Get
the Glances version from the
cache file"
)
logger
.
debug
(
"Get
Glances version from
cache file"
)
def
is_outdated
(
self
):
"""Return True if a new version is available"""
...
...
@@ -117,26 +111,23 @@ class Outdated(object):
# 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: {} / latest: {})"
.
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
max_refresh_date
=
timedelta
(
days
=
7
)
cached_data
=
{}
try
:
with
open
(
self
.
cache_file
,
'rb'
)
as
f
:
cached_data
=
pickle
.
load
(
f
)
except
Exception
as
e
:
logger
.
debug
(
"Cannot read
the version
cache file: {}"
.
format
(
e
))
logger
.
debug
(
"Cannot read
version from
cache file: {}"
.
format
(
e
))
else
:
logger
.
debug
(
"Read
the version
cache file"
)
logger
.
debug
(
"Read
version from
cache file"
)
if
(
cached_data
[
'installed_version'
]
!=
self
.
installed_version
()
or
datetime
.
now
()
-
cached_data
[
'refresh_date'
]
>
self
.
max_refresh_date
):
datetime
.
now
()
-
cached_data
[
'refresh_date'
]
>
max_refresh_date
):
# Reset the cache if:
# - the installed version is different
# - the refresh_date is > max_refresh_date
...
...
@@ -153,27 +144,22 @@ class Outdated(object):
pickle
.
dump
(
self
.
data
,
f
)
def
_update_pypi_version
(
self
):
"""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 RESTful API ({})"
.
format
(
self
.
PYPI_API_URL
))
"""Get the latest PyPI version (as a string) via the RESTful JSON API"""
logger
.
debug
(
"Get latest Glances version from the PyPI RESTful API ({})"
.
format
(
PYPI_API_URL
))
# Update the current time
self
.
data
[
u
'refresh_date'
]
=
datetime
.
now
()
try
:
res
=
requests
.
get
(
self
.
PYPI_API_URL
,
timeout
=
3
)
except
Exception
as
e
:
logger
.
debug
(
"Cannot get
the
Glances version from the PyPI RESTful API ({})"
.
format
(
e
))
res
=
urlopen
(
PYPI_API_URL
,
timeout
=
3
).
read
(
)
except
(
HTTPError
,
URLError
)
as
e
:
logger
.
debug
(
"Cannot get Glances version from the PyPI RESTful API ({})"
.
format
(
e
))
else
:
if
res
.
ok
:
# Update data
self
.
data
[
u
'latest_version'
]
=
json
.
loads
(
res
.
text
)[
'info'
][
'version'
]
logger
.
debug
(
"Save Glances version to the cache file"
)
else
:
logger
.
debug
(
"Cannot get the Glances version from the PyPI RESTful API ({})"
.
format
(
res
.
reason
))
self
.
data
[
u
'latest_version'
]
=
json
.
loads
(
nativestr
(
res
))[
'info'
][
'version'
]
logger
.
debug
(
"Save Glances version to the cache file"
)
# Save result to the cache file
# Note: also saved if the Glances Py
pi version can not be gra
bed
# Note: also saved if the Glances Py
PI version cannot be grab
bed
self
.
_save_cache
()
return
self
.
data
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录