提交 d74fbdea 编写于 作者: B BinLong

fix some exceptional bugs

上级 dd1f132f
...@@ -22,13 +22,13 @@ import sys ...@@ -22,13 +22,13 @@ import sys
import requests import requests
from paddlehub.common.logger import logger from paddlehub.common.logger import logger
from paddlehub.common import stats
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
from paddlehub.commands import version from paddlehub.commands import version
from paddlehub.commands import run from paddlehub.commands import run
from paddlehub.commands import download from paddlehub.commands import download
from paddlehub.commands import stats
class HubCommand(BaseCommand): class HubCommand(BaseCommand):
...@@ -51,7 +51,7 @@ class HubCommand(BaseCommand): ...@@ -51,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(argv) stats.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:])
......
...@@ -51,6 +51,7 @@ class HubServer(object): ...@@ -51,6 +51,7 @@ class HubServer(object):
utils.check_url(self.config['server_url']) utils.check_url(self.config['server_url'])
self.server_url = self.config['server_url'] self.server_url = self.config['server_url']
self.request()
self._load_resource_list_file_if_valid() self._load_resource_list_file_if_valid()
def get_server_url(self): def get_server_url(self):
...@@ -222,11 +223,10 @@ class HubServer(object): ...@@ -222,11 +223,10 @@ class HubServer(object):
raise raise
else: else:
pass pass
file_url = self.config[ file_url = self.config[
'resource_storage_server_url'] + RESOURCE_LIST_FILE 'resource_storage_server_url'] + RESOURCE_LIST_FILE
result, tips, self.resource_list_file = default_downloader.download_file( result, tips, self.resource_list_file = default_downloader.download_file(
file_url, save_path=hub.CACHE_HOME) file_url, save_path=hub.CACHE_HOME, replace=True)
if not result: if not result:
return False return False
return True return True
......
...@@ -13,8 +13,16 @@ ...@@ -13,8 +13,16 @@
# limitations under the License. # limitations under the License.
HUB_SERVERS = ["http://gzbh-aip-paddlehub01.gzbh.baidu.com:8889/paddlehub"] HUB_SERVERS = ["http://gzbh-aip-paddlehub01.gzbh.baidu.com:8889/paddlehub"]
STAT_SERVERS = [
"http://gzbh-aip-paddlehub01.gzbh.baidu.com:8889/paddlehub/stat",
"http://gzbh-aip-paddlehub02.gzbh.baidu.com:8889/paddlehub/stat"
]
default_server_config = { default_server_config = {
"server_url": HUB_SERVERS, "server_url": HUB_SERVERS,
"resource_storage_server_url": "https://bj.bcebos.com/paddlehub/", "resource_storage_server_url": "https://bj.bcebos.com/paddlehub-data/",
"debug": False "debug": False
} }
default_stat_config = {"server_list": STAT_SERVERS}
...@@ -14,15 +14,21 @@ ...@@ -14,15 +14,21 @@
# limitations under the License. # limitations under the License.
import os import os
import requests import requests
import time
from random import randint, seed
from paddlehub import version from paddlehub import version
from paddlehub.common.server_config import default_stat_config
def get_stat_server(): def get_stat_server():
stat_srv = os.environ.get('HUB_SERVER_STAT_SRV') seed(int(time.time()))
if not stat_srv: stat_env = os.environ.get('HUB_SERVER_STAT_SRV')
stat_srv = 'http://hub.paddlepaddle.org:8888/paddlehub/stat' if stat_env:
return stat_srv server_list = stat_env.split(';')
else:
server_list = default_stat_config
return server_list[randint(0, len(server_list) - 1)]
def hub_stat(argv): def hub_stat(argv):
......
...@@ -21,6 +21,7 @@ import os ...@@ -21,6 +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.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
...@@ -80,6 +81,7 @@ class LocalModuleManager(object): ...@@ -80,6 +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])
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]
...@@ -95,6 +97,7 @@ class LocalModuleManager(object): ...@@ -95,6 +97,7 @@ class LocalModuleManager(object):
tips = "Can't find module %s" % module_name tips = "Can't find module %s" % module_name
if module_version: if module_version:
tips += " with version %s" % module_version tips += " with version %s" % module_version
stats.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(
...@@ -116,6 +119,7 @@ class LocalModuleManager(object): ...@@ -116,6 +119,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])
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)
...@@ -131,6 +135,7 @@ class LocalModuleManager(object): ...@@ -131,6 +135,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])
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
......
...@@ -13,5 +13,5 @@ ...@@ -13,5 +13,5 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
""" PaddleHub version string """ """ PaddleHub version string """
hub_version = "0.5.1" hub_version = "0.6.5"
module_proto_version = "1.0.0" module_proto_version = "1.0.0"
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册