提交 d74fbdea 编写于 作者: B BinLong

fix some exceptional bugs

上级 dd1f132f
......@@ -22,13 +22,13 @@ import sys
import requests
from paddlehub.common.logger import logger
from paddlehub.common import stats
from paddlehub.commands.base_command import BaseCommand
from paddlehub.commands import show
from paddlehub.commands import help
from paddlehub.commands import version
from paddlehub.commands import run
from paddlehub.commands import download
from paddlehub.commands import stats
class HubCommand(BaseCommand):
......@@ -51,7 +51,7 @@ class HubCommand(BaseCommand):
help.command.execute(argv)
exit(1)
return False
stats.hub_stat(argv)
stats.hub_stat(['hub'] + argv)
command = BaseCommand.command_dict[sub_command]
return command.execute(argv[1:])
......
......@@ -51,6 +51,7 @@ class HubServer(object):
utils.check_url(self.config['server_url'])
self.server_url = self.config['server_url']
self.request()
self._load_resource_list_file_if_valid()
def get_server_url(self):
......@@ -222,11 +223,10 @@ class HubServer(object):
raise
else:
pass
file_url = self.config[
'resource_storage_server_url'] + RESOURCE_LIST_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:
return False
return True
......
......@@ -13,8 +13,16 @@
# limitations under the License.
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 = {
"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
}
default_stat_config = {"server_list": STAT_SERVERS}
......@@ -14,15 +14,21 @@
# limitations under the License.
import os
import requests
import time
from random import randint, seed
from paddlehub import version
from paddlehub.common.server_config import default_stat_config
def get_stat_server():
stat_srv = os.environ.get('HUB_SERVER_STAT_SRV')
if not stat_srv:
stat_srv = 'http://hub.paddlepaddle.org:8888/paddlehub/stat'
return stat_srv
seed(int(time.time()))
stat_env = os.environ.get('HUB_SERVER_STAT_SRV')
if stat_env:
server_list = stat_env.split(';')
else:
server_list = default_stat_config
return server_list[randint(0, len(server_list) - 1)]
def hub_stat(argv):
......
......@@ -21,6 +21,7 @@ import os
import shutil
from paddlehub.common import utils
from paddlehub.common import stats
from paddlehub.common.downloader import default_downloader
from paddlehub.common.dir import MODULE_HOME
from paddlehub.module import module_desc_pb2
......@@ -80,6 +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])
tips = "Module %s already installed in %s" % (module_tag,
module_dir)
return True, tips, self.modules_dict[module_name]
......@@ -95,6 +97,7 @@ class LocalModuleManager(object):
tips = "Can't find module %s" % module_name
if module_version:
tips += " with version %s" % module_version
stats.hub_stat(['install fail', module_tag])
return False, tips, None
result, tips, module_zip_file = default_downloader.download_file(
......@@ -116,6 +119,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])
if installed_module_version:
tips += "-%s" % installed_module_version
return True, tips, (module_dir, installed_module_version)
......@@ -131,6 +135,7 @@ class LocalModuleManager(object):
1]:
tips = "%s-%s is not installed" % (module_name, module_version)
return True, tips
stats.hub_stat(['uninstall', module_name])
tips = "Successfully uninstalled %s" % module_name
if module_version:
tips += '-%s' % module_version
......
......@@ -13,5 +13,5 @@
# See the License for the specific language governing permissions and
# limitations under the License.
""" PaddleHub version string """
hub_version = "0.5.1"
hub_version = "0.6.5"
module_proto_version = "1.0.0"
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册