提交 f87bfd44 编写于 作者: B BinLong

fix compitable problem with paddle_version

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