提交 f87bfd44 编写于 作者: B BinLong

fix compitable problem with paddle_version

上级 3319d88c
......@@ -19,11 +19,10 @@ from __future__ import print_function
import six
import sys
import requests
from paddlehub.common.logger import logger
from paddlehub.common.utils import sys_stdin_encoding
from paddlehub.common import stats
from paddlehub.common import srv_utils
from paddlehub.commands.base_command import BaseCommand
from paddlehub.commands import show
from paddlehub.commands import help
......@@ -52,7 +51,7 @@ class HubCommand(BaseCommand):
help.command.execute(argv)
exit(1)
return False
stats.hub_stat(['hub'] + argv)
srv_utils.hub_stat(['hub'] + argv)
command = BaseCommand.command_dict[sub_command]
return command.execute(argv[1:])
......
......@@ -26,7 +26,7 @@ import yaml
import random
from random import randint
from paddlehub.common import utils
from paddlehub.common import utils, srv_utils
from paddlehub.common.downloader import default_downloader
from paddlehub.common.server_config import default_server_config
from paddlehub.io.parser import yaml_parser
......@@ -95,9 +95,8 @@ class HubServer(object):
payload = {'word': resource_key}
if resource_type:
payload['type'] = resource_type
r = requests.get(
self.get_server_url() + '/' + 'search', params=payload)
r = json.loads(r.text)
api_url = srv_utils.uri_path(self.get_server_url(), 'search')
r = srv_utils.hub_request(api_url, payload)
if r['status'] == 0 and len(r['data']) > 0:
return [(item['name'], item['type'], item['version'],
item['summary']) for item in r['data']]
......@@ -149,9 +148,8 @@ class HubServer(object):
payload['type'] = resource_type
if version:
payload['version'] = version
r = requests.get(
self.get_server_url() + '/' + 'search', params=payload)
r = json.loads(r.text)
api_url = srv_utils.uri_path(self.get_server_url(), 'search')
r = srv_utils.hub_request(api_url, payload)
if r['status'] == 0 and len(r['data']) > 0:
return r['data'][0]
except:
......
......@@ -15,8 +15,10 @@
import os
import requests
import time
import paddle
from random import randint, seed
from paddlehub import version
from paddlehub.common.server_config import default_stat_config
......@@ -33,8 +35,31 @@ def get_stat_server():
def hub_stat(argv):
try:
params = {'command': ' '.join(argv), 'version': version.hub_version}
params = {
'command': ' '.join(argv),
'hub_version': version.hub_version,
'paddle_version': paddle.__version__
}
stat_api = get_stat_server()
r = requests.get(stat_api, params=params, timeout=0.5)
except:
pass
def uri_path(server_url, api):
srv = server_url
if server_url.endswith('/'):
srv = server_url[:-1]
if api.startswith('/'):
srv += api
else:
api = '/' + api
srv += api
return srv
def hub_request(api, params):
params['hub_version'] = version.hub_version
params['paddle_version'] = paddle.__version__
r = requests.get(api, params)
return r.json()
......@@ -21,7 +21,7 @@ import os
import shutil
from paddlehub.common import utils
from paddlehub.common import stats
from paddlehub.common import srv_utils
from paddlehub.common.downloader import default_downloader
from paddlehub.common.dir import MODULE_HOME
from paddlehub.module import module_desc_pb2
......@@ -81,7 +81,7 @@ class LocalModuleManager(object):
module_dir = self.modules_dict[module_name][0]
module_tag = module_name if not module_version else '%s-%s' % (
module_name, module_version)
stats.hub_stat(['installed', module_tag])
srv_utils.hub_stat(['installed', module_tag])
tips = "Module %s already installed in %s" % (module_tag,
module_dir)
return True, tips, self.modules_dict[module_name]
......@@ -100,7 +100,7 @@ class LocalModuleManager(object):
tips += " with version %s" % module_version
module_tag = module_name if not module_version else '%s-%s' % (
module_name, module_version)
stats.hub_stat(['install fail', module_tag])
srv_utils.hub_stat(['install fail', module_tag])
return False, tips, None
result, tips, module_zip_file = default_downloader.download_file(
......@@ -122,7 +122,7 @@ class LocalModuleManager(object):
shutil.move(module_dir, save_path)
module_dir = save_path
tips = "Successfully installed %s" % module_name
stats.hub_stat(['install', module_name, url])
srv_utils.hub_stat(['install', module_name, url])
if installed_module_version:
tips += "-%s" % installed_module_version
return True, tips, (module_dir, installed_module_version)
......@@ -138,7 +138,7 @@ class LocalModuleManager(object):
1]:
tips = "%s-%s is not installed" % (module_name, module_version)
return True, tips
stats.hub_stat(['uninstall', module_name])
srv_utils.hub_stat(['uninstall', module_name])
tips = "Successfully uninstalled %s" % module_name
if module_version:
tips += '-%s' % module_version
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册