提交 fecb4372 编写于 作者: W wuzewu

search command support regular expression

上级 270e44ab
...@@ -40,9 +40,7 @@ class SearchCommand(BaseCommand): ...@@ -40,9 +40,7 @@ class SearchCommand(BaseCommand):
def exec(self, argv): def exec(self, argv):
if not argv: if not argv:
print("ERROR: Please specify module name.\n") argv = ['.*']
self.help()
return False
resource_name = argv[0] resource_name = argv[0]
resource_list = default_hub_server.search_resource(resource_name) resource_list = default_hub_server.search_resource(resource_name)
......
...@@ -18,6 +18,7 @@ from __future__ import print_function ...@@ -18,6 +18,7 @@ from __future__ import print_function
import os import os
import time import time
import re
from paddlehub.common import utils from paddlehub.common import utils
from paddlehub.common.downloader import default_downloader from paddlehub.common.downloader import default_downloader
...@@ -68,13 +69,16 @@ class HubServer: ...@@ -68,13 +69,16 @@ class HubServer:
if update or not self.resource_list_file: if update or not self.resource_list_file:
self.request() self.request()
match_resource_index_list = [ match_resource_index_list = []
index for index, resource in enumerate(self.resource_list_file['name']):
for index, resource in enumerate(self.resource_list_file['name']) try:
if resource_key in resource and ( is_match = re.match(resource_key, resource)
resource_type is None if is_match and (resource_type is None
or self.resource_list_file['type'][index] == resource_type) or self.resource_list_file['type'][index] ==
] resource_type):
match_resource_index_list.append(index)
except:
pass
return [(self.resource_list_file['name'][index], return [(self.resource_list_file['name'][index],
self.resource_list_file['type'][index], self.resource_list_file['type'][index],
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册