Skip to content
This repository has been archived by the owner on Feb 22, 2020. It is now read-only.

Commit

Permalink
fix(cli): remove unnecessary argument
Browse files Browse the repository at this point in the history
  • Loading branch information
hanhxiao committed Aug 13, 2019
1 parent 5257259 commit df61646
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
25 changes: 14 additions & 11 deletions gnes/cli/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,16 @@ def set_cli_client_parser(parser=None):
if not parser:
parser = set_base_parser()
_set_grpc_parser(parser)
parser.add_argument('--txt_file', type=argparse.FileType('r'),
default=sys.stdin,
help='text file to be used, each line is a doc/query')
group = parser.add_mutually_exclusive_group()

group.add_argument('--txt_file', type=argparse.FileType('r'),
default=sys.stdin,
help='text file to be used, each line is a doc/query')
group.add_argument('--image_zip_file', type=str,
help='image zip file to be used, consists of multiple images')
group.add_argument('--video_zip_file', type=str,
help='video zip file to be used, consists of multiple videos')

parser.add_argument('--batch_size', type=int, default=100,
help='the size of the request to split')
parser.add_argument('--mode', choices=['index', 'query', 'train'], type=str,
Expand All @@ -276,10 +283,6 @@ def set_cli_client_parser(parser=None):
parser.add_argument('--data_type', choices=['text', 'image', 'video'], type=str,
required=True,
help='type of data, available choice: text, image, video')
parser.add_argument('--image_zip_file', type=str,
help='image zip file to be used, consists of multiple images')
parser.add_argument('--video_zip_file', type=str,
help='video zip file to be used, consists of multiple videos')
parser.add_argument('--top_k', type=int,
default=10,
help='default top_k for query mode')
Expand Down Expand Up @@ -312,16 +315,16 @@ def get_main_parser():

# microservices
set_frontend_parser(sp.add_parser('frontend', help='start a frontend service'))
set_indexer_service_parser(sp.add_parser('index', help='start an indexer service'))
set_loadable_service_parser(sp.add_parser('encode', help='start an encoder service'))
set_indexer_service_parser(sp.add_parser('index', help='start an indexer service'))
set_router_service_parser(sp.add_parser('route', help='start a router service'))
set_preprocessor_service_parser(sp.add_parser('preprocess', help='start a preprocessor service'))
set_grpc_service_parser(sp.add_parser('grpc', help='start a general purpose grpc service'))

# clients
set_http_service_parser(sp.add_parser('client_http', help='start a http service'))
set_cli_client_parser(sp.add_parser('client_cli', help='start a grpc client'))
set_http_service_parser(sp.add_parser('client_http', help='start a client that allows HTTP requests as input'))
set_cli_client_parser(sp.add_parser('client_cli', help='start a client that allows STDIN as input'))

# others
set_composer_flask_parser(sp.add_parser('compose', help='start a GNES Board and visualize YAML config'))
set_composer_flask_parser(sp.add_parser('compose', help='start a GNES Board to visualize YAML configs'))
return parser
9 changes: 4 additions & 5 deletions gnes/client/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,16 @@

class CLIClient:
def __init__(self, args):
if args.data_type == 'text':
if args.txt_file:
all_bytes = [v.encode() for v in args.txt_file]
elif args.data_type == 'image':
elif args.image_zip_file:
zipfile_ = zipfile.ZipFile(args.image_zip_file, "r")
all_bytes = [zipfile_.open(v).read() for v in zipfile_.namelist()]
elif args.data_type == 'video':
elif args.video_zip_file:
zipfile_ = zipfile.ZipFile(args.video_zip_file, "r")
all_bytes = [zipfile_.open(v).read() for v in zipfile_.namelist()]
else:
raise ValueError(
'--data_type can only be text, image or video')
raise AttributeError('--txt_file, --image_zip_file, --video_zip_file one must be given')

with grpc.insecure_channel(
'%s:%s' % (args.grpc_host, args.grpc_port),
Expand Down
2 changes: 1 addition & 1 deletion gnes/service/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def message_handler(self, msg: 'gnes_pb2.Message', out_sck, ctrl_sck):
try:
fn = self.handler.serve(msg)
if fn:
add_route(msg.envelope, '%s:%s' % (self.__class__.__name__, self._model.__class__.__name__))
add_route(msg.envelope, self._model.__class__.__name__)
self.logger.info(
'handling a message with route: %s' % '->'.join([r.service for r in msg.envelope.routes]))
if msg.request and msg.request.WhichOneof('body') and \
Expand Down

0 comments on commit df61646

Please sign in to comment.