未验证 提交 b0b61e12 编写于 作者: B Bin Long 提交者: GitHub

Merge pull request #222 from ShenYuhan/update_file

add update outdated resource_list_file.yaml
......@@ -24,6 +24,7 @@ import requests
import json
import yaml
import random
import threading
from random import randint
from paddlehub.common import utils, srv_utils
......@@ -269,6 +270,32 @@ class HubServer(object):
print("Request Hub-Server unsuccessfully.")
class CacheUpdater(threading.Thread):
def __init__(self, module, version=None):
threading.Thread.__init__(self)
self.module = module
self.version = version
def update_resource_list_file(self, module, version=None):
payload = {'word': module}
if version:
payload['version'] = version
api_url = srv_utils.uri_path(default_hub_server.get_server_url(),
'search')
cache_path = os.path.join(CACHE_HOME, RESOURCE_LIST_FILE)
extra = {
"command": "update_cache",
"mtime": os.stat(cache_path).st_mtime
}
r = srv_utils.hub_request(api_url, payload, extra)
if r.get("update_cache", 0) == 1:
with open(cache_path, 'w+') as fp:
yaml.safe_dump({'resource_list': r['data']}, fp)
def run(self):
self.update_resource_list_file(self.module, self.version)
def server_check():
default_hub_server.server_check()
......
......@@ -34,6 +34,7 @@ from paddlehub.common.downloader import default_downloader
from paddlehub.module import module_desc_pb2
from paddlehub.common.dir import CONF_HOME
from paddlehub.module import check_info_pb2
from paddlehub.common.hub_server import CacheUpdater
from paddlehub.module.signature import Signature, create_signature
from paddlehub.module.checker import ModuleChecker
from paddlehub.module.manager import default_module_manager
......@@ -144,6 +145,7 @@ class Module(object):
else:
lock.flock(fp_lock, lock.LOCK_UN)
raise ValueError("Module initialized parameter is empty")
CacheUpdater(name, version).start()
def _init_with_name(self, name, version=None):
log_msg = "Installing %s module" % name
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册