Skip to content
This repository was archived by the owner on Oct 19, 2023. It is now read-only.

Commit 2b4adec

Browse files
committed
Replaces grpc --project flag with --project-id
This is more consistent with the library sample Bug: 70333259 Change-Id: Id372963727bc972655aa43d601babdeea594bf37
1 parent 81ed359 commit 2b4adec

File tree

3 files changed

+20
-18
lines changed

3 files changed

+20
-18
lines changed

google-assistant-sdk/googlesamples/assistant/grpc/devicetool.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def resolve_project_id(client_secrets, credentials):
5252
raise click.ClickException('Error loading client secret: %s.\n'
5353
'Run the device tool '
5454
'with --client-secrets '
55-
'or --project option.\n'
55+
'or --project-id option.\n'
5656
'Or copy the %s file '
5757
'in the current directory.'
5858
% (e, client_secrets))
@@ -65,7 +65,7 @@ def build_api_url(api_endpoint, api_version, project_id):
6565

6666

6767
def build_client_from_context(ctx):
68-
project_id = (ctx.obj['PROJECT']
68+
project_id = (ctx.obj['PROJECT_ID']
6969
or resolve_project_id(ctx.obj['CLIENT_SECRETS'],
7070
ctx.obj['CREDENTIALS']))
7171
api_url = build_api_url(ctx.obj['API_ENDPOINT'],
@@ -103,7 +103,7 @@ def pretty_print_device(device):
103103

104104

105105
@click.group()
106-
@click.option('--project',
106+
@click.option('--project-id',
107107
help='Enter the Google Developer Project ID that you want to '
108108
'use with the registration tool. If you don\'t use this flag, '
109109
'the tool will use the project listed in the '
@@ -113,8 +113,9 @@ def pretty_print_device(device):
113113
help='Enter the path and filename for the '
114114
'<client_secret_client-id.json> file you downloaded from your '
115115
'developer project. This file is used to infer the Google '
116-
'Developer Project ID if it was not provided with the --project '
117-
'flag. If the --project flag and this flag are not used, the '
116+
'Developer Project ID if it was not provided with the '
117+
'--project-id flag. '
118+
'If the --project-id flag and this flag are not used, the '
118119
'tool will look for this file in the current directory (by '
119120
'searching for a file named after the client_id stored in the '
120121
'credentials file).')
@@ -134,7 +135,7 @@ def pretty_print_device(device):
134135
'API. You can use this flag if the credentials were generated '
135136
'in a location that is different than the default.')
136137
@click.pass_context
137-
def cli(ctx, project, client_secrets, verbose, api_endpoint, credentials):
138+
def cli(ctx, project_id, client_secrets, verbose, api_endpoint, credentials):
138139
try:
139140
with open(credentials, 'r') as f:
140141
c = google.oauth2.credentials.Credentials(token=None,
@@ -148,7 +149,7 @@ def cli(ctx, project, client_secrets, verbose, api_endpoint, credentials):
148149
ctx.obj['API_ENDPOINT'] = api_endpoint
149150
ctx.obj['API_VERSION'] = ASSISTANT_API_VERSION
150151
ctx.obj['SESSION'] = None
151-
ctx.obj['PROJECT'] = project
152+
ctx.obj['PROJECT_ID'] = project_id
152153
ctx.obj['CREDENTIALS'] = c
153154
ctx.obj['CLIENT_SECRETS'] = client_secrets
154155
logging.basicConfig(format='',
@@ -207,13 +208,14 @@ def register(ctx, model, type, trait, manufacturer, product_name, description,
207208
hyphen (-), underscore (_), and plus (+). The device nickname can only
208209
contain numbers, letters, and the space ( ) symbol.
209210
"""
210-
# cache SESSION and PROJECT so that we don't re-create them between request
211+
# cache SESSION and PROJECT_ID
212+
# so that we don't re-create them between commands
211213
ctx.obj['SESSION'] = google.auth.transport.requests.AuthorizedSession(
212214
ctx.obj['CREDENTIALS']
213215
)
214-
ctx.obj['PROJECT'] = (ctx.obj['PROJECT']
215-
or resolve_project_id(ctx.obj['CLIENT_SECRETS'],
216-
ctx.obj['CREDENTIALS']))
216+
ctx.obj['PROJECT_ID'] = (ctx.obj['PROJECT_ID']
217+
or resolve_project_id(ctx.obj['CLIENT_SECRETS'],
218+
ctx.obj['CREDENTIALS']))
217219
ctx.invoke(register_model,
218220
model=model, type=type, trait=trait,
219221
manufacturer=manufacturer,
@@ -398,7 +400,7 @@ def delete(ctx, resource, id):
398400
def list(ctx, resource):
399401
"""Lists all of the device models and/or instances associated with the
400402
current Google Developer project. To change the current project, use the
401-
devicetool's --project flag.
403+
devicetool's --project-id flag.
402404
"""
403405
session, api_url, project_id = build_client_from_context(ctx)
404406
url = '/'.join([api_url, resource])

google-assistant-sdk/googlesamples/assistant/grpc/pushtotalk.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,8 @@ def gen_assist_requests(self):
212212
default=os.path.join(click.get_app_dir('google-oauthlib-tool'),
213213
'credentials.json'),
214214
help='Path to read OAuth2 credentials.')
215-
@click.option('--project',
216-
metavar='<project>',
215+
@click.option('--project-id',
216+
metavar='<project id>',
217217
help=('Google Developer Project ID used for registration '
218218
'if --device-id is not specified'))
219219
@click.option('--device-model-id',
@@ -273,7 +273,7 @@ def gen_assist_requests(self):
273273
help='gRPC deadline in seconds')
274274
@click.option('--once', default=False, is_flag=True,
275275
help='Force termination after a single conversation.')
276-
def main(api_endpoint, credentials, project,
276+
def main(api_endpoint, credentials, project_id,
277277
device_model_id, device_id, device_config, lang, verbose,
278278
input_audio_file, output_audio_file,
279279
audio_sample_rate, audio_sample_width,
@@ -377,13 +377,13 @@ def onoff(on):
377377
logging.error('Option --device-model-id required '
378378
'when registrering a model.')
379379
sys.exit(-1)
380-
if not project:
380+
if not project_id:
381381
logging.error('Option --project required '
382382
'when registrering a model.')
383383
sys.exit(-1)
384384
device_base_url = (
385385
'https://%s/v1alpha2/projects/%s/devices' % (api_endpoint,
386-
project)
386+
project_id)
387387
)
388388
device_id = str(uuid.uuid1())
389389
payload = {

google-assistant-sdk/tests/test_devicetool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def test_build_client():
5858
my_session = Session()
5959
my_context = Context()
6060
my_context.obj = {
61-
'PROJECT': 'myproject',
61+
'PROJECT_ID': 'myproject',
6262
'API_ENDPOINT': 'myhostname',
6363
'API_VERSION': 'myversion',
6464
'SESSION': my_session

0 commit comments

Comments
 (0)