提交 b7d9adc1 编写于 作者: W wuzewu

Add server_check

上级 5173059d
...@@ -22,6 +22,7 @@ __version__ = '2.0.0-alpha0' ...@@ -22,6 +22,7 @@ __version__ = '2.0.0-alpha0'
from paddlehub.config import config from paddlehub.config import config
from paddlehub.utils import log, parser, utils from paddlehub.utils import log, parser, utils
from paddlehub.utils.paddlex import download, ResourceNotFoundError from paddlehub.utils.paddlex import download, ResourceNotFoundError
from paddlehub.server import server_check
from paddlehub.server.server_source import ServerConnectionError from paddlehub.server.server_source import ServerConnectionError
from paddlehub.module import Module from paddlehub.module import Module
from paddlehub.text.bert_tokenizer import BertTokenizer from paddlehub.text.bert_tokenizer import BertTokenizer
......
...@@ -51,7 +51,7 @@ class ConfigCommand: ...@@ -51,7 +51,7 @@ class ConfigCommand:
hubconf.reset() hubconf.reset()
print(hubconf) print(hubconf)
elif arg.startswith("server=="): elif arg.startswith("server=="):
hubconf.server_url = arg.split("==")[1] hubconf.server = arg.split("==")[1]
elif arg.startswith("log.level=="): elif arg.startswith("log.level=="):
hubconf.log_level = arg.split("==")[1] hubconf.log_level = arg.split("==")[1]
elif arg.startswith("log.enable=="): elif arg.startswith("log.enable=="):
......
...@@ -13,6 +13,17 @@ ...@@ -13,6 +13,17 @@
# 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.
from .server_source import ServerSource from paddlehub.server.server_source import ServerSource
from .git_source import GitSource from paddlehub.server.git_source import GitSource
from .server import module_server from paddlehub.server.server import module_server
from paddlehub.utils import log
def server_check() -> bool:
'''Check whether localhost can access the PaddleHub default server normally.'''
if module_server.get_source_by_key('default_hub_server').is_connected():
log.logger.info('Request Hub-Server successfully.')
return True
log.logger.info('Request Hub-Server unsuccessfully.')
return False
...@@ -119,6 +119,9 @@ class ServerSource(object): ...@@ -119,6 +119,9 @@ class ServerSource(object):
except requests.exceptions.ConnectionError as e: except requests.exceptions.ConnectionError as e:
raise ServerConnectionError(self._url) raise ServerConnectionError(self._url)
def is_connected(self):
return self.check(self._url)
@classmethod @classmethod
def check(cls, url: str) -> bool: def check(cls, url: str) -> bool:
''' '''
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册