• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2"""CLI for fusiontables, version v1."""
3# NOTE: This file is autogenerated and should not be edited by hand.
4
5import code
6import os
7import platform
8import sys
9
10from apitools.base.protorpclite import message_types
11from apitools.base.protorpclite import messages
12
13from google.apputils import appcommands
14import gflags as flags
15
16import apitools.base.py as apitools_base
17from apitools.base.py import cli as apitools_base_cli
18import fusiontables_v1_client as client_lib
19import fusiontables_v1_messages as messages
20
21
22def _DeclareFusiontablesFlags():
23  """Declare global flags in an idempotent way."""
24  if 'api_endpoint' in flags.FLAGS:
25    return
26  flags.DEFINE_string(
27      'api_endpoint',
28      u'https://www.googleapis.com/fusiontables/v1/',
29      'URL of the API endpoint to use.',
30      short_name='fusiontables_url')
31  flags.DEFINE_string(
32      'history_file',
33      u'~/.fusiontables.v1.history',
34      'File with interactive shell history.')
35  flags.DEFINE_multistring(
36      'add_header', [],
37      'Additional http headers (as key=value strings). '
38      'Can be specified multiple times.')
39  flags.DEFINE_string(
40      'service_account_json_keyfile', '',
41      'Filename for a JSON service account key downloaded'
42      ' from the Developer Console.')
43  flags.DEFINE_enum(
44      'alt',
45      u'json',
46      [u'csv', u'json'],
47      u'Data format for the response.')
48  flags.DEFINE_string(
49      'fields',
50      None,
51      u'Selector specifying which fields to include in a partial response.')
52  flags.DEFINE_string(
53      'key',
54      None,
55      u'API key. Your API key identifies your project and provides you with '
56      u'API access, quota, and reports. Required unless you provide an OAuth '
57      u'2.0 token.')
58  flags.DEFINE_string(
59      'oauth_token',
60      None,
61      u'OAuth 2.0 token for the current user.')
62  flags.DEFINE_boolean(
63      'prettyPrint',
64      'True',
65      u'Returns response with indentations and line breaks.')
66  flags.DEFINE_string(
67      'quotaUser',
68      None,
69      u'Available to use for quota purposes for server-side applications. Can'
70      u' be any arbitrary string assigned to a user, but should not exceed 40'
71      u' characters. Overrides userIp if both are provided.')
72  flags.DEFINE_string(
73      'trace',
74      None,
75      'A tracing token of the form "token:<tokenid>" to include in api '
76      'requests.')
77  flags.DEFINE_string(
78      'userIp',
79      None,
80      u'IP address of the site where the request originates. Use this if you '
81      u'want to enforce per-user limits.')
82
83
84FLAGS = flags.FLAGS
85apitools_base_cli.DeclareBaseFlags()
86_DeclareFusiontablesFlags()
87
88
89def GetGlobalParamsFromFlags():
90  """Return a StandardQueryParameters based on flags."""
91  result = messages.StandardQueryParameters()
92  if FLAGS['alt'].present:
93    result.alt = messages.StandardQueryParameters.AltValueValuesEnum(FLAGS.alt)
94  if FLAGS['fields'].present:
95    result.fields = FLAGS.fields.decode('utf8')
96  if FLAGS['key'].present:
97    result.key = FLAGS.key.decode('utf8')
98  if FLAGS['oauth_token'].present:
99    result.oauth_token = FLAGS.oauth_token.decode('utf8')
100  if FLAGS['prettyPrint'].present:
101    result.prettyPrint = FLAGS.prettyPrint
102  if FLAGS['quotaUser'].present:
103    result.quotaUser = FLAGS.quotaUser.decode('utf8')
104  if FLAGS['trace'].present:
105    result.trace = FLAGS.trace.decode('utf8')
106  if FLAGS['userIp'].present:
107    result.userIp = FLAGS.userIp.decode('utf8')
108  return result
109
110
111def GetClientFromFlags():
112  """Return a client object, configured from flags."""
113  log_request = FLAGS.log_request or FLAGS.log_request_response
114  log_response = FLAGS.log_response or FLAGS.log_request_response
115  api_endpoint = apitools_base.NormalizeApiEndpoint(FLAGS.api_endpoint)
116  additional_http_headers = dict(x.split('=', 1) for x in FLAGS.add_header)
117  credentials_args = {
118      'service_account_json_keyfile': os.path.expanduser(FLAGS.service_account_json_keyfile)
119  }
120  try:
121    client = client_lib.FusiontablesV1(
122        api_endpoint, log_request=log_request,
123        log_response=log_response,
124        credentials_args=credentials_args,
125        additional_http_headers=additional_http_headers)
126  except apitools_base.CredentialsError as e:
127    print 'Error creating credentials: %s' % e
128    sys.exit(1)
129  return client
130
131
132class PyShell(appcommands.Cmd):
133
134  def Run(self, _):
135    """Run an interactive python shell with the client."""
136    client = GetClientFromFlags()
137    params = GetGlobalParamsFromFlags()
138    for field in params.all_fields():
139      value = params.get_assigned_value(field.name)
140      if value != field.default:
141        client.AddGlobalParam(field.name, value)
142    banner = """
143           == fusiontables interactive console ==
144                 client: a fusiontables client
145          apitools_base: base apitools module
146         messages: the generated messages module
147    """
148    local_vars = {
149        'apitools_base': apitools_base,
150        'client': client,
151        'client_lib': client_lib,
152        'messages': messages,
153    }
154    if platform.system() == 'Linux':
155      console = apitools_base_cli.ConsoleWithReadline(
156          local_vars, histfile=FLAGS.history_file)
157    else:
158      console = code.InteractiveConsole(local_vars)
159    try:
160      console.interact(banner)
161    except SystemExit as e:
162      return e.code
163
164
165class ColumnDelete(apitools_base_cli.NewCmd):
166  """Command wrapping column.Delete."""
167
168  usage = """column_delete <tableId> <columnId>"""
169
170  def __init__(self, name, fv):
171    super(ColumnDelete, self).__init__(name, fv)
172
173  def RunWithArgs(self, tableId, columnId):
174    """Deletes the column.
175
176    Args:
177      tableId: Table from which the column is being deleted.
178      columnId: Name or identifier for the column being deleted.
179    """
180    client = GetClientFromFlags()
181    global_params = GetGlobalParamsFromFlags()
182    request = messages.FusiontablesColumnDeleteRequest(
183        tableId=tableId.decode('utf8'),
184        columnId=columnId.decode('utf8'),
185        )
186    result = client.column.Delete(
187        request, global_params=global_params)
188    print apitools_base_cli.FormatOutput(result)
189
190
191class ColumnGet(apitools_base_cli.NewCmd):
192  """Command wrapping column.Get."""
193
194  usage = """column_get <tableId> <columnId>"""
195
196  def __init__(self, name, fv):
197    super(ColumnGet, self).__init__(name, fv)
198
199  def RunWithArgs(self, tableId, columnId):
200    """Retrieves a specific column by its id.
201
202    Args:
203      tableId: Table to which the column belongs.
204      columnId: Name or identifier for the column that is being requested.
205    """
206    client = GetClientFromFlags()
207    global_params = GetGlobalParamsFromFlags()
208    request = messages.FusiontablesColumnGetRequest(
209        tableId=tableId.decode('utf8'),
210        columnId=columnId.decode('utf8'),
211        )
212    result = client.column.Get(
213        request, global_params=global_params)
214    print apitools_base_cli.FormatOutput(result)
215
216
217class ColumnInsert(apitools_base_cli.NewCmd):
218  """Command wrapping column.Insert."""
219
220  usage = """column_insert <tableId>"""
221
222  def __init__(self, name, fv):
223    super(ColumnInsert, self).__init__(name, fv)
224    flags.DEFINE_string(
225        'column',
226        None,
227        u'A Column resource to be passed as the request body.',
228        flag_values=fv)
229
230  def RunWithArgs(self, tableId):
231    """Adds a new column to the table.
232
233    Args:
234      tableId: Table for which a new column is being added.
235
236    Flags:
237      column: A Column resource to be passed as the request body.
238    """
239    client = GetClientFromFlags()
240    global_params = GetGlobalParamsFromFlags()
241    request = messages.FusiontablesColumnInsertRequest(
242        tableId=tableId.decode('utf8'),
243        )
244    if FLAGS['column'].present:
245      request.column = apitools_base.JsonToMessage(messages.Column, FLAGS.column)
246    result = client.column.Insert(
247        request, global_params=global_params)
248    print apitools_base_cli.FormatOutput(result)
249
250
251class ColumnList(apitools_base_cli.NewCmd):
252  """Command wrapping column.List."""
253
254  usage = """column_list <tableId>"""
255
256  def __init__(self, name, fv):
257    super(ColumnList, self).__init__(name, fv)
258    flags.DEFINE_integer(
259        'maxResults',
260        None,
261        u'Maximum number of columns to return. Optional. Default is 5.',
262        flag_values=fv)
263    flags.DEFINE_string(
264        'pageToken',
265        None,
266        u'Continuation token specifying which result page to return. '
267        u'Optional.',
268        flag_values=fv)
269
270  def RunWithArgs(self, tableId):
271    """Retrieves a list of columns.
272
273    Args:
274      tableId: Table whose columns are being listed.
275
276    Flags:
277      maxResults: Maximum number of columns to return. Optional. Default is 5.
278      pageToken: Continuation token specifying which result page to return.
279        Optional.
280    """
281    client = GetClientFromFlags()
282    global_params = GetGlobalParamsFromFlags()
283    request = messages.FusiontablesColumnListRequest(
284        tableId=tableId.decode('utf8'),
285        )
286    if FLAGS['maxResults'].present:
287      request.maxResults = FLAGS.maxResults
288    if FLAGS['pageToken'].present:
289      request.pageToken = FLAGS.pageToken.decode('utf8')
290    result = client.column.List(
291        request, global_params=global_params)
292    print apitools_base_cli.FormatOutput(result)
293
294
295class ColumnPatch(apitools_base_cli.NewCmd):
296  """Command wrapping column.Patch."""
297
298  usage = """column_patch <tableId> <columnId>"""
299
300  def __init__(self, name, fv):
301    super(ColumnPatch, self).__init__(name, fv)
302    flags.DEFINE_string(
303        'column',
304        None,
305        u'A Column resource to be passed as the request body.',
306        flag_values=fv)
307
308  def RunWithArgs(self, tableId, columnId):
309    """Updates the name or type of an existing column. This method supports
310    patch semantics.
311
312    Args:
313      tableId: Table for which the column is being updated.
314      columnId: Name or identifier for the column that is being updated.
315
316    Flags:
317      column: A Column resource to be passed as the request body.
318    """
319    client = GetClientFromFlags()
320    global_params = GetGlobalParamsFromFlags()
321    request = messages.FusiontablesColumnPatchRequest(
322        tableId=tableId.decode('utf8'),
323        columnId=columnId.decode('utf8'),
324        )
325    if FLAGS['column'].present:
326      request.column = apitools_base.JsonToMessage(messages.Column, FLAGS.column)
327    result = client.column.Patch(
328        request, global_params=global_params)
329    print apitools_base_cli.FormatOutput(result)
330
331
332class ColumnUpdate(apitools_base_cli.NewCmd):
333  """Command wrapping column.Update."""
334
335  usage = """column_update <tableId> <columnId>"""
336
337  def __init__(self, name, fv):
338    super(ColumnUpdate, self).__init__(name, fv)
339    flags.DEFINE_string(
340        'column',
341        None,
342        u'A Column resource to be passed as the request body.',
343        flag_values=fv)
344
345  def RunWithArgs(self, tableId, columnId):
346    """Updates the name or type of an existing column.
347
348    Args:
349      tableId: Table for which the column is being updated.
350      columnId: Name or identifier for the column that is being updated.
351
352    Flags:
353      column: A Column resource to be passed as the request body.
354    """
355    client = GetClientFromFlags()
356    global_params = GetGlobalParamsFromFlags()
357    request = messages.FusiontablesColumnUpdateRequest(
358        tableId=tableId.decode('utf8'),
359        columnId=columnId.decode('utf8'),
360        )
361    if FLAGS['column'].present:
362      request.column = apitools_base.JsonToMessage(messages.Column, FLAGS.column)
363    result = client.column.Update(
364        request, global_params=global_params)
365    print apitools_base_cli.FormatOutput(result)
366
367
368class QuerySql(apitools_base_cli.NewCmd):
369  """Command wrapping query.Sql."""
370
371  usage = """query_sql <sql>"""
372
373  def __init__(self, name, fv):
374    super(QuerySql, self).__init__(name, fv)
375    flags.DEFINE_boolean(
376        'hdrs',
377        None,
378        u'Should column names be included (in the first row)?. Default is '
379        u'true.',
380        flag_values=fv)
381    flags.DEFINE_boolean(
382        'typed',
383        None,
384        u'Should typed values be returned in the (JSON) response -- numbers '
385        u'for numeric values and parsed geometries for KML values? Default is'
386        u' true.',
387        flag_values=fv)
388    flags.DEFINE_string(
389        'download_filename',
390        '',
391        'Filename to use for download.',
392        flag_values=fv)
393    flags.DEFINE_boolean(
394        'overwrite',
395        'False',
396        'If True, overwrite the existing file when downloading.',
397        flag_values=fv)
398
399  def RunWithArgs(self, sql):
400    """Executes an SQL SELECT/INSERT/UPDATE/DELETE/SHOW/DESCRIBE/CREATE
401    statement.
402
403    Args:
404      sql: An SQL SELECT/SHOW/DESCRIBE/INSERT/UPDATE/DELETE/CREATE statement.
405
406    Flags:
407      hdrs: Should column names be included (in the first row)?. Default is
408        true.
409      typed: Should typed values be returned in the (JSON) response -- numbers
410        for numeric values and parsed geometries for KML values? Default is
411        true.
412      download_filename: Filename to use for download.
413      overwrite: If True, overwrite the existing file when downloading.
414    """
415    client = GetClientFromFlags()
416    global_params = GetGlobalParamsFromFlags()
417    request = messages.FusiontablesQuerySqlRequest(
418        sql=sql.decode('utf8'),
419        )
420    if FLAGS['hdrs'].present:
421      request.hdrs = FLAGS.hdrs
422    if FLAGS['typed'].present:
423      request.typed = FLAGS.typed
424    download = None
425    if FLAGS.download_filename:
426      download = apitools_base.Download.FromFile(FLAGS.download_filename, overwrite=FLAGS.overwrite,
427          progress_callback=apitools_base.DownloadProgressPrinter,
428          finish_callback=apitools_base.DownloadCompletePrinter)
429    result = client.query.Sql(
430        request, global_params=global_params, download=download)
431    print apitools_base_cli.FormatOutput(result)
432
433
434class QuerySqlGet(apitools_base_cli.NewCmd):
435  """Command wrapping query.SqlGet."""
436
437  usage = """query_sqlGet <sql>"""
438
439  def __init__(self, name, fv):
440    super(QuerySqlGet, self).__init__(name, fv)
441    flags.DEFINE_boolean(
442        'hdrs',
443        None,
444        u'Should column names be included (in the first row)?. Default is '
445        u'true.',
446        flag_values=fv)
447    flags.DEFINE_boolean(
448        'typed',
449        None,
450        u'Should typed values be returned in the (JSON) response -- numbers '
451        u'for numeric values and parsed geometries for KML values? Default is'
452        u' true.',
453        flag_values=fv)
454    flags.DEFINE_string(
455        'download_filename',
456        '',
457        'Filename to use for download.',
458        flag_values=fv)
459    flags.DEFINE_boolean(
460        'overwrite',
461        'False',
462        'If True, overwrite the existing file when downloading.',
463        flag_values=fv)
464
465  def RunWithArgs(self, sql):
466    """Executes an SQL SELECT/SHOW/DESCRIBE statement.
467
468    Args:
469      sql: An SQL SELECT/SHOW/DESCRIBE statement.
470
471    Flags:
472      hdrs: Should column names be included (in the first row)?. Default is
473        true.
474      typed: Should typed values be returned in the (JSON) response -- numbers
475        for numeric values and parsed geometries for KML values? Default is
476        true.
477      download_filename: Filename to use for download.
478      overwrite: If True, overwrite the existing file when downloading.
479    """
480    client = GetClientFromFlags()
481    global_params = GetGlobalParamsFromFlags()
482    request = messages.FusiontablesQuerySqlGetRequest(
483        sql=sql.decode('utf8'),
484        )
485    if FLAGS['hdrs'].present:
486      request.hdrs = FLAGS.hdrs
487    if FLAGS['typed'].present:
488      request.typed = FLAGS.typed
489    download = None
490    if FLAGS.download_filename:
491      download = apitools_base.Download.FromFile(FLAGS.download_filename, overwrite=FLAGS.overwrite,
492          progress_callback=apitools_base.DownloadProgressPrinter,
493          finish_callback=apitools_base.DownloadCompletePrinter)
494    result = client.query.SqlGet(
495        request, global_params=global_params, download=download)
496    print apitools_base_cli.FormatOutput(result)
497
498
499class StyleDelete(apitools_base_cli.NewCmd):
500  """Command wrapping style.Delete."""
501
502  usage = """style_delete <tableId> <styleId>"""
503
504  def __init__(self, name, fv):
505    super(StyleDelete, self).__init__(name, fv)
506
507  def RunWithArgs(self, tableId, styleId):
508    """Deletes a style.
509
510    Args:
511      tableId: Table from which the style is being deleted
512      styleId: Identifier (within a table) for the style being deleted
513    """
514    client = GetClientFromFlags()
515    global_params = GetGlobalParamsFromFlags()
516    request = messages.FusiontablesStyleDeleteRequest(
517        tableId=tableId.decode('utf8'),
518        styleId=styleId,
519        )
520    result = client.style.Delete(
521        request, global_params=global_params)
522    print apitools_base_cli.FormatOutput(result)
523
524
525class StyleGet(apitools_base_cli.NewCmd):
526  """Command wrapping style.Get."""
527
528  usage = """style_get <tableId> <styleId>"""
529
530  def __init__(self, name, fv):
531    super(StyleGet, self).__init__(name, fv)
532
533  def RunWithArgs(self, tableId, styleId):
534    """Gets a specific style.
535
536    Args:
537      tableId: Table to which the requested style belongs
538      styleId: Identifier (integer) for a specific style in a table
539    """
540    client = GetClientFromFlags()
541    global_params = GetGlobalParamsFromFlags()
542    request = messages.FusiontablesStyleGetRequest(
543        tableId=tableId.decode('utf8'),
544        styleId=styleId,
545        )
546    result = client.style.Get(
547        request, global_params=global_params)
548    print apitools_base_cli.FormatOutput(result)
549
550
551class StyleInsert(apitools_base_cli.NewCmd):
552  """Command wrapping style.Insert."""
553
554  usage = """style_insert <tableId>"""
555
556  def __init__(self, name, fv):
557    super(StyleInsert, self).__init__(name, fv)
558    flags.DEFINE_string(
559        'kind',
560        u'fusiontables#styleSetting',
561        u'Type name: an individual style setting. A StyleSetting contains the'
562        u' style defintions for points, lines, and polygons in a table. Since'
563        u' a table can have any one or all of them, a style definition can '
564        u'have point, line and polygon style definitions.',
565        flag_values=fv)
566    flags.DEFINE_string(
567        'markerOptions',
568        None,
569        u'Style definition for points in the table.',
570        flag_values=fv)
571    flags.DEFINE_string(
572        'name',
573        None,
574        u'Optional name for the style setting.',
575        flag_values=fv)
576    flags.DEFINE_string(
577        'polygonOptions',
578        None,
579        u'Style definition for polygons in the table.',
580        flag_values=fv)
581    flags.DEFINE_string(
582        'polylineOptions',
583        None,
584        u'Style definition for lines in the table.',
585        flag_values=fv)
586    flags.DEFINE_integer(
587        'styleId',
588        None,
589        u'Identifier for the style setting (unique only within tables).',
590        flag_values=fv)
591
592  def RunWithArgs(self, tableId):
593    """Adds a new style for the table.
594
595    Args:
596      tableId: Identifier for the table.
597
598    Flags:
599      kind: Type name: an individual style setting. A StyleSetting contains
600        the style defintions for points, lines, and polygons in a table. Since
601        a table can have any one or all of them, a style definition can have
602        point, line and polygon style definitions.
603      markerOptions: Style definition for points in the table.
604      name: Optional name for the style setting.
605      polygonOptions: Style definition for polygons in the table.
606      polylineOptions: Style definition for lines in the table.
607      styleId: Identifier for the style setting (unique only within tables).
608    """
609    client = GetClientFromFlags()
610    global_params = GetGlobalParamsFromFlags()
611    request = messages.StyleSetting(
612        tableId=tableId.decode('utf8'),
613        )
614    if FLAGS['kind'].present:
615      request.kind = FLAGS.kind.decode('utf8')
616    if FLAGS['markerOptions'].present:
617      request.markerOptions = apitools_base.JsonToMessage(messages.PointStyle, FLAGS.markerOptions)
618    if FLAGS['name'].present:
619      request.name = FLAGS.name.decode('utf8')
620    if FLAGS['polygonOptions'].present:
621      request.polygonOptions = apitools_base.JsonToMessage(messages.PolygonStyle, FLAGS.polygonOptions)
622    if FLAGS['polylineOptions'].present:
623      request.polylineOptions = apitools_base.JsonToMessage(messages.LineStyle, FLAGS.polylineOptions)
624    if FLAGS['styleId'].present:
625      request.styleId = FLAGS.styleId
626    result = client.style.Insert(
627        request, global_params=global_params)
628    print apitools_base_cli.FormatOutput(result)
629
630
631class StyleList(apitools_base_cli.NewCmd):
632  """Command wrapping style.List."""
633
634  usage = """style_list <tableId>"""
635
636  def __init__(self, name, fv):
637    super(StyleList, self).__init__(name, fv)
638    flags.DEFINE_integer(
639        'maxResults',
640        None,
641        u'Maximum number of styles to return. Optional. Default is 5.',
642        flag_values=fv)
643    flags.DEFINE_string(
644        'pageToken',
645        None,
646        u'Continuation token specifying which result page to return. '
647        u'Optional.',
648        flag_values=fv)
649
650  def RunWithArgs(self, tableId):
651    """Retrieves a list of styles.
652
653    Args:
654      tableId: Table whose styles are being listed
655
656    Flags:
657      maxResults: Maximum number of styles to return. Optional. Default is 5.
658      pageToken: Continuation token specifying which result page to return.
659        Optional.
660    """
661    client = GetClientFromFlags()
662    global_params = GetGlobalParamsFromFlags()
663    request = messages.FusiontablesStyleListRequest(
664        tableId=tableId.decode('utf8'),
665        )
666    if FLAGS['maxResults'].present:
667      request.maxResults = FLAGS.maxResults
668    if FLAGS['pageToken'].present:
669      request.pageToken = FLAGS.pageToken.decode('utf8')
670    result = client.style.List(
671        request, global_params=global_params)
672    print apitools_base_cli.FormatOutput(result)
673
674
675class StylePatch(apitools_base_cli.NewCmd):
676  """Command wrapping style.Patch."""
677
678  usage = """style_patch <tableId> <styleId>"""
679
680  def __init__(self, name, fv):
681    super(StylePatch, self).__init__(name, fv)
682    flags.DEFINE_string(
683        'kind',
684        u'fusiontables#styleSetting',
685        u'Type name: an individual style setting. A StyleSetting contains the'
686        u' style defintions for points, lines, and polygons in a table. Since'
687        u' a table can have any one or all of them, a style definition can '
688        u'have point, line and polygon style definitions.',
689        flag_values=fv)
690    flags.DEFINE_string(
691        'markerOptions',
692        None,
693        u'Style definition for points in the table.',
694        flag_values=fv)
695    flags.DEFINE_string(
696        'name',
697        None,
698        u'Optional name for the style setting.',
699        flag_values=fv)
700    flags.DEFINE_string(
701        'polygonOptions',
702        None,
703        u'Style definition for polygons in the table.',
704        flag_values=fv)
705    flags.DEFINE_string(
706        'polylineOptions',
707        None,
708        u'Style definition for lines in the table.',
709        flag_values=fv)
710
711  def RunWithArgs(self, tableId, styleId):
712    """Updates an existing style. This method supports patch semantics.
713
714    Args:
715      tableId: Identifier for the table.
716      styleId: Identifier for the style setting (unique only within tables).
717
718    Flags:
719      kind: Type name: an individual style setting. A StyleSetting contains
720        the style defintions for points, lines, and polygons in a table. Since
721        a table can have any one or all of them, a style definition can have
722        point, line and polygon style definitions.
723      markerOptions: Style definition for points in the table.
724      name: Optional name for the style setting.
725      polygonOptions: Style definition for polygons in the table.
726      polylineOptions: Style definition for lines in the table.
727    """
728    client = GetClientFromFlags()
729    global_params = GetGlobalParamsFromFlags()
730    request = messages.StyleSetting(
731        tableId=tableId.decode('utf8'),
732        styleId=styleId,
733        )
734    if FLAGS['kind'].present:
735      request.kind = FLAGS.kind.decode('utf8')
736    if FLAGS['markerOptions'].present:
737      request.markerOptions = apitools_base.JsonToMessage(messages.PointStyle, FLAGS.markerOptions)
738    if FLAGS['name'].present:
739      request.name = FLAGS.name.decode('utf8')
740    if FLAGS['polygonOptions'].present:
741      request.polygonOptions = apitools_base.JsonToMessage(messages.PolygonStyle, FLAGS.polygonOptions)
742    if FLAGS['polylineOptions'].present:
743      request.polylineOptions = apitools_base.JsonToMessage(messages.LineStyle, FLAGS.polylineOptions)
744    result = client.style.Patch(
745        request, global_params=global_params)
746    print apitools_base_cli.FormatOutput(result)
747
748
749class StyleUpdate(apitools_base_cli.NewCmd):
750  """Command wrapping style.Update."""
751
752  usage = """style_update <tableId> <styleId>"""
753
754  def __init__(self, name, fv):
755    super(StyleUpdate, self).__init__(name, fv)
756    flags.DEFINE_string(
757        'kind',
758        u'fusiontables#styleSetting',
759        u'Type name: an individual style setting. A StyleSetting contains the'
760        u' style defintions for points, lines, and polygons in a table. Since'
761        u' a table can have any one or all of them, a style definition can '
762        u'have point, line and polygon style definitions.',
763        flag_values=fv)
764    flags.DEFINE_string(
765        'markerOptions',
766        None,
767        u'Style definition for points in the table.',
768        flag_values=fv)
769    flags.DEFINE_string(
770        'name',
771        None,
772        u'Optional name for the style setting.',
773        flag_values=fv)
774    flags.DEFINE_string(
775        'polygonOptions',
776        None,
777        u'Style definition for polygons in the table.',
778        flag_values=fv)
779    flags.DEFINE_string(
780        'polylineOptions',
781        None,
782        u'Style definition for lines in the table.',
783        flag_values=fv)
784
785  def RunWithArgs(self, tableId, styleId):
786    """Updates an existing style.
787
788    Args:
789      tableId: Identifier for the table.
790      styleId: Identifier for the style setting (unique only within tables).
791
792    Flags:
793      kind: Type name: an individual style setting. A StyleSetting contains
794        the style defintions for points, lines, and polygons in a table. Since
795        a table can have any one or all of them, a style definition can have
796        point, line and polygon style definitions.
797      markerOptions: Style definition for points in the table.
798      name: Optional name for the style setting.
799      polygonOptions: Style definition for polygons in the table.
800      polylineOptions: Style definition for lines in the table.
801    """
802    client = GetClientFromFlags()
803    global_params = GetGlobalParamsFromFlags()
804    request = messages.StyleSetting(
805        tableId=tableId.decode('utf8'),
806        styleId=styleId,
807        )
808    if FLAGS['kind'].present:
809      request.kind = FLAGS.kind.decode('utf8')
810    if FLAGS['markerOptions'].present:
811      request.markerOptions = apitools_base.JsonToMessage(messages.PointStyle, FLAGS.markerOptions)
812    if FLAGS['name'].present:
813      request.name = FLAGS.name.decode('utf8')
814    if FLAGS['polygonOptions'].present:
815      request.polygonOptions = apitools_base.JsonToMessage(messages.PolygonStyle, FLAGS.polygonOptions)
816    if FLAGS['polylineOptions'].present:
817      request.polylineOptions = apitools_base.JsonToMessage(messages.LineStyle, FLAGS.polylineOptions)
818    result = client.style.Update(
819        request, global_params=global_params)
820    print apitools_base_cli.FormatOutput(result)
821
822
823class TableCopy(apitools_base_cli.NewCmd):
824  """Command wrapping table.Copy."""
825
826  usage = """table_copy <tableId>"""
827
828  def __init__(self, name, fv):
829    super(TableCopy, self).__init__(name, fv)
830    flags.DEFINE_boolean(
831        'copyPresentation',
832        None,
833        u'Whether to also copy tabs, styles, and templates. Default is false.',
834        flag_values=fv)
835
836  def RunWithArgs(self, tableId):
837    """Copies a table.
838
839    Args:
840      tableId: ID of the table that is being copied.
841
842    Flags:
843      copyPresentation: Whether to also copy tabs, styles, and templates.
844        Default is false.
845    """
846    client = GetClientFromFlags()
847    global_params = GetGlobalParamsFromFlags()
848    request = messages.FusiontablesTableCopyRequest(
849        tableId=tableId.decode('utf8'),
850        )
851    if FLAGS['copyPresentation'].present:
852      request.copyPresentation = FLAGS.copyPresentation
853    result = client.table.Copy(
854        request, global_params=global_params)
855    print apitools_base_cli.FormatOutput(result)
856
857
858class TableDelete(apitools_base_cli.NewCmd):
859  """Command wrapping table.Delete."""
860
861  usage = """table_delete <tableId>"""
862
863  def __init__(self, name, fv):
864    super(TableDelete, self).__init__(name, fv)
865
866  def RunWithArgs(self, tableId):
867    """Deletes a table.
868
869    Args:
870      tableId: ID of the table that is being deleted.
871    """
872    client = GetClientFromFlags()
873    global_params = GetGlobalParamsFromFlags()
874    request = messages.FusiontablesTableDeleteRequest(
875        tableId=tableId.decode('utf8'),
876        )
877    result = client.table.Delete(
878        request, global_params=global_params)
879    print apitools_base_cli.FormatOutput(result)
880
881
882class TableGet(apitools_base_cli.NewCmd):
883  """Command wrapping table.Get."""
884
885  usage = """table_get <tableId>"""
886
887  def __init__(self, name, fv):
888    super(TableGet, self).__init__(name, fv)
889
890  def RunWithArgs(self, tableId):
891    """Retrieves a specific table by its id.
892
893    Args:
894      tableId: Identifier(ID) for the table being requested.
895    """
896    client = GetClientFromFlags()
897    global_params = GetGlobalParamsFromFlags()
898    request = messages.FusiontablesTableGetRequest(
899        tableId=tableId.decode('utf8'),
900        )
901    result = client.table.Get(
902        request, global_params=global_params)
903    print apitools_base_cli.FormatOutput(result)
904
905
906class TableImportRows(apitools_base_cli.NewCmd):
907  """Command wrapping table.ImportRows."""
908
909  usage = """table_importRows <tableId>"""
910
911  def __init__(self, name, fv):
912    super(TableImportRows, self).__init__(name, fv)
913    flags.DEFINE_string(
914        'delimiter',
915        None,
916        u'The delimiter used to separate cell values. This can only consist '
917        u"of a single character. Default is ','.",
918        flag_values=fv)
919    flags.DEFINE_string(
920        'encoding',
921        None,
922        u"The encoding of the content. Default is UTF-8. Use 'auto-detect' if"
923        u' you are unsure of the encoding.',
924        flag_values=fv)
925    flags.DEFINE_integer(
926        'endLine',
927        None,
928        u'The index of the last line from which to start importing, '
929        u'exclusive. Thus, the number of imported lines is endLine - '
930        u'startLine. If this parameter is not provided, the file will be '
931        u'imported until the last line of the file. If endLine is negative, '
932        u'then the imported content will exclude the last endLine lines. That'
933        u' is, if endline is negative, no line will be imported whose index '
934        u'is greater than N + endLine where N is the number of lines in the '
935        u'file, and the number of imported lines will be N + endLine - '
936        u'startLine.',
937        flag_values=fv)
938    flags.DEFINE_boolean(
939        'isStrict',
940        None,
941        u'Whether the CSV must have the same number of values for each row. '
942        u'If false, rows with fewer values will be padded with empty values. '
943        u'Default is true.',
944        flag_values=fv)
945    flags.DEFINE_integer(
946        'startLine',
947        None,
948        u'The index of the first line from which to start importing, '
949        u'inclusive. Default is 0.',
950        flag_values=fv)
951    flags.DEFINE_string(
952        'upload_filename',
953        '',
954        'Filename to use for upload.',
955        flag_values=fv)
956    flags.DEFINE_string(
957        'upload_mime_type',
958        '',
959        'MIME type to use for the upload. Only needed if the extension on '
960        '--upload_filename does not determine the correct (or any) MIME '
961        'type.',
962        flag_values=fv)
963
964  def RunWithArgs(self, tableId):
965    """Import more rows into a table.
966
967    Args:
968      tableId: The table into which new rows are being imported.
969
970    Flags:
971      delimiter: The delimiter used to separate cell values. This can only
972        consist of a single character. Default is ','.
973      encoding: The encoding of the content. Default is UTF-8. Use 'auto-
974        detect' if you are unsure of the encoding.
975      endLine: The index of the last line from which to start importing,
976        exclusive. Thus, the number of imported lines is endLine - startLine.
977        If this parameter is not provided, the file will be imported until the
978        last line of the file. If endLine is negative, then the imported
979        content will exclude the last endLine lines. That is, if endline is
980        negative, no line will be imported whose index is greater than N +
981        endLine where N is the number of lines in the file, and the number of
982        imported lines will be N + endLine - startLine.
983      isStrict: Whether the CSV must have the same number of values for each
984        row. If false, rows with fewer values will be padded with empty
985        values. Default is true.
986      startLine: The index of the first line from which to start importing,
987        inclusive. Default is 0.
988      upload_filename: Filename to use for upload.
989      upload_mime_type: MIME type to use for the upload. Only needed if the
990        extension on --upload_filename does not determine the correct (or any)
991        MIME type.
992    """
993    client = GetClientFromFlags()
994    global_params = GetGlobalParamsFromFlags()
995    request = messages.FusiontablesTableImportRowsRequest(
996        tableId=tableId.decode('utf8'),
997        )
998    if FLAGS['delimiter'].present:
999      request.delimiter = FLAGS.delimiter.decode('utf8')
1000    if FLAGS['encoding'].present:
1001      request.encoding = FLAGS.encoding.decode('utf8')
1002    if FLAGS['endLine'].present:
1003      request.endLine = FLAGS.endLine
1004    if FLAGS['isStrict'].present:
1005      request.isStrict = FLAGS.isStrict
1006    if FLAGS['startLine'].present:
1007      request.startLine = FLAGS.startLine
1008    upload = None
1009    if FLAGS.upload_filename:
1010      upload = apitools_base.Upload.FromFile(
1011          FLAGS.upload_filename, FLAGS.upload_mime_type,
1012          progress_callback=apitools_base.UploadProgressPrinter,
1013          finish_callback=apitools_base.UploadCompletePrinter)
1014    result = client.table.ImportRows(
1015        request, global_params=global_params, upload=upload)
1016    print apitools_base_cli.FormatOutput(result)
1017
1018
1019class TableImportTable(apitools_base_cli.NewCmd):
1020  """Command wrapping table.ImportTable."""
1021
1022  usage = """table_importTable <name>"""
1023
1024  def __init__(self, name, fv):
1025    super(TableImportTable, self).__init__(name, fv)
1026    flags.DEFINE_string(
1027        'delimiter',
1028        None,
1029        u'The delimiter used to separate cell values. This can only consist '
1030        u"of a single character. Default is ','.",
1031        flag_values=fv)
1032    flags.DEFINE_string(
1033        'encoding',
1034        None,
1035        u"The encoding of the content. Default is UTF-8. Use 'auto-detect' if"
1036        u' you are unsure of the encoding.',
1037        flag_values=fv)
1038    flags.DEFINE_string(
1039        'upload_filename',
1040        '',
1041        'Filename to use for upload.',
1042        flag_values=fv)
1043    flags.DEFINE_string(
1044        'upload_mime_type',
1045        '',
1046        'MIME type to use for the upload. Only needed if the extension on '
1047        '--upload_filename does not determine the correct (or any) MIME '
1048        'type.',
1049        flag_values=fv)
1050
1051  def RunWithArgs(self, name):
1052    """Import a new table.
1053
1054    Args:
1055      name: The name to be assigned to the new table.
1056
1057    Flags:
1058      delimiter: The delimiter used to separate cell values. This can only
1059        consist of a single character. Default is ','.
1060      encoding: The encoding of the content. Default is UTF-8. Use 'auto-
1061        detect' if you are unsure of the encoding.
1062      upload_filename: Filename to use for upload.
1063      upload_mime_type: MIME type to use for the upload. Only needed if the
1064        extension on --upload_filename does not determine the correct (or any)
1065        MIME type.
1066    """
1067    client = GetClientFromFlags()
1068    global_params = GetGlobalParamsFromFlags()
1069    request = messages.FusiontablesTableImportTableRequest(
1070        name=name.decode('utf8'),
1071        )
1072    if FLAGS['delimiter'].present:
1073      request.delimiter = FLAGS.delimiter.decode('utf8')
1074    if FLAGS['encoding'].present:
1075      request.encoding = FLAGS.encoding.decode('utf8')
1076    upload = None
1077    if FLAGS.upload_filename:
1078      upload = apitools_base.Upload.FromFile(
1079          FLAGS.upload_filename, FLAGS.upload_mime_type,
1080          progress_callback=apitools_base.UploadProgressPrinter,
1081          finish_callback=apitools_base.UploadCompletePrinter)
1082    result = client.table.ImportTable(
1083        request, global_params=global_params, upload=upload)
1084    print apitools_base_cli.FormatOutput(result)
1085
1086
1087class TableInsert(apitools_base_cli.NewCmd):
1088  """Command wrapping table.Insert."""
1089
1090  usage = """table_insert"""
1091
1092  def __init__(self, name, fv):
1093    super(TableInsert, self).__init__(name, fv)
1094    flags.DEFINE_string(
1095        'attribution',
1096        None,
1097        u'Optional attribution assigned to the table.',
1098        flag_values=fv)
1099    flags.DEFINE_string(
1100        'attributionLink',
1101        None,
1102        u'Optional link for attribution.',
1103        flag_values=fv)
1104    flags.DEFINE_string(
1105        'baseTableIds',
1106        None,
1107        u'Optional base table identifier if this table is a view or merged '
1108        u'table.',
1109        flag_values=fv)
1110    flags.DEFINE_string(
1111        'columns',
1112        None,
1113        u'Columns in the table.',
1114        flag_values=fv)
1115    flags.DEFINE_string(
1116        'description',
1117        None,
1118        u'Optional description assigned to the table.',
1119        flag_values=fv)
1120    flags.DEFINE_boolean(
1121        'isExportable',
1122        None,
1123        u'Variable for whether table is exportable.',
1124        flag_values=fv)
1125    flags.DEFINE_string(
1126        'kind',
1127        u'fusiontables#table',
1128        u'Type name: a template for an individual table.',
1129        flag_values=fv)
1130    flags.DEFINE_string(
1131        'name',
1132        None,
1133        u'Name assigned to a table.',
1134        flag_values=fv)
1135    flags.DEFINE_string(
1136        'sql',
1137        None,
1138        u'Optional sql that encodes the table definition for derived tables.',
1139        flag_values=fv)
1140    flags.DEFINE_string(
1141        'tableId',
1142        None,
1143        u'Encrypted unique alphanumeric identifier for the table.',
1144        flag_values=fv)
1145
1146  def RunWithArgs(self):
1147    """Creates a new table.
1148
1149    Flags:
1150      attribution: Optional attribution assigned to the table.
1151      attributionLink: Optional link for attribution.
1152      baseTableIds: Optional base table identifier if this table is a view or
1153        merged table.
1154      columns: Columns in the table.
1155      description: Optional description assigned to the table.
1156      isExportable: Variable for whether table is exportable.
1157      kind: Type name: a template for an individual table.
1158      name: Name assigned to a table.
1159      sql: Optional sql that encodes the table definition for derived tables.
1160      tableId: Encrypted unique alphanumeric identifier for the table.
1161    """
1162    client = GetClientFromFlags()
1163    global_params = GetGlobalParamsFromFlags()
1164    request = messages.Table(
1165        )
1166    if FLAGS['attribution'].present:
1167      request.attribution = FLAGS.attribution.decode('utf8')
1168    if FLAGS['attributionLink'].present:
1169      request.attributionLink = FLAGS.attributionLink.decode('utf8')
1170    if FLAGS['baseTableIds'].present:
1171      request.baseTableIds = [x.decode('utf8') for x in FLAGS.baseTableIds]
1172    if FLAGS['columns'].present:
1173      request.columns = [apitools_base.JsonToMessage(messages.Column, x) for x in FLAGS.columns]
1174    if FLAGS['description'].present:
1175      request.description = FLAGS.description.decode('utf8')
1176    if FLAGS['isExportable'].present:
1177      request.isExportable = FLAGS.isExportable
1178    if FLAGS['kind'].present:
1179      request.kind = FLAGS.kind.decode('utf8')
1180    if FLAGS['name'].present:
1181      request.name = FLAGS.name.decode('utf8')
1182    if FLAGS['sql'].present:
1183      request.sql = FLAGS.sql.decode('utf8')
1184    if FLAGS['tableId'].present:
1185      request.tableId = FLAGS.tableId.decode('utf8')
1186    result = client.table.Insert(
1187        request, global_params=global_params)
1188    print apitools_base_cli.FormatOutput(result)
1189
1190
1191class TableList(apitools_base_cli.NewCmd):
1192  """Command wrapping table.List."""
1193
1194  usage = """table_list"""
1195
1196  def __init__(self, name, fv):
1197    super(TableList, self).__init__(name, fv)
1198    flags.DEFINE_integer(
1199        'maxResults',
1200        None,
1201        u'Maximum number of styles to return. Optional. Default is 5.',
1202        flag_values=fv)
1203    flags.DEFINE_string(
1204        'pageToken',
1205        None,
1206        u'Continuation token specifying which result page to return. '
1207        u'Optional.',
1208        flag_values=fv)
1209
1210  def RunWithArgs(self):
1211    """Retrieves a list of tables a user owns.
1212
1213    Flags:
1214      maxResults: Maximum number of styles to return. Optional. Default is 5.
1215      pageToken: Continuation token specifying which result page to return.
1216        Optional.
1217    """
1218    client = GetClientFromFlags()
1219    global_params = GetGlobalParamsFromFlags()
1220    request = messages.FusiontablesTableListRequest(
1221        )
1222    if FLAGS['maxResults'].present:
1223      request.maxResults = FLAGS.maxResults
1224    if FLAGS['pageToken'].present:
1225      request.pageToken = FLAGS.pageToken.decode('utf8')
1226    result = client.table.List(
1227        request, global_params=global_params)
1228    print apitools_base_cli.FormatOutput(result)
1229
1230
1231class TablePatch(apitools_base_cli.NewCmd):
1232  """Command wrapping table.Patch."""
1233
1234  usage = """table_patch <tableId>"""
1235
1236  def __init__(self, name, fv):
1237    super(TablePatch, self).__init__(name, fv)
1238    flags.DEFINE_boolean(
1239        'replaceViewDefinition',
1240        None,
1241        u'Should the view definition also be updated? The specified view '
1242        u'definition replaces the existing one. Only a view can be updated '
1243        u'with a new definition.',
1244        flag_values=fv)
1245    flags.DEFINE_string(
1246        'table',
1247        None,
1248        u'A Table resource to be passed as the request body.',
1249        flag_values=fv)
1250
1251  def RunWithArgs(self, tableId):
1252    """Updates an existing table. Unless explicitly requested, only the name,
1253    description, and attribution will be updated. This method supports patch
1254    semantics.
1255
1256    Args:
1257      tableId: ID of the table that is being updated.
1258
1259    Flags:
1260      replaceViewDefinition: Should the view definition also be updated? The
1261        specified view definition replaces the existing one. Only a view can
1262        be updated with a new definition.
1263      table: A Table resource to be passed as the request body.
1264    """
1265    client = GetClientFromFlags()
1266    global_params = GetGlobalParamsFromFlags()
1267    request = messages.FusiontablesTablePatchRequest(
1268        tableId=tableId.decode('utf8'),
1269        )
1270    if FLAGS['replaceViewDefinition'].present:
1271      request.replaceViewDefinition = FLAGS.replaceViewDefinition
1272    if FLAGS['table'].present:
1273      request.table = apitools_base.JsonToMessage(messages.Table, FLAGS.table)
1274    result = client.table.Patch(
1275        request, global_params=global_params)
1276    print apitools_base_cli.FormatOutput(result)
1277
1278
1279class TableUpdate(apitools_base_cli.NewCmd):
1280  """Command wrapping table.Update."""
1281
1282  usage = """table_update <tableId>"""
1283
1284  def __init__(self, name, fv):
1285    super(TableUpdate, self).__init__(name, fv)
1286    flags.DEFINE_boolean(
1287        'replaceViewDefinition',
1288        None,
1289        u'Should the view definition also be updated? The specified view '
1290        u'definition replaces the existing one. Only a view can be updated '
1291        u'with a new definition.',
1292        flag_values=fv)
1293    flags.DEFINE_string(
1294        'table',
1295        None,
1296        u'A Table resource to be passed as the request body.',
1297        flag_values=fv)
1298
1299  def RunWithArgs(self, tableId):
1300    """Updates an existing table. Unless explicitly requested, only the name,
1301    description, and attribution will be updated.
1302
1303    Args:
1304      tableId: ID of the table that is being updated.
1305
1306    Flags:
1307      replaceViewDefinition: Should the view definition also be updated? The
1308        specified view definition replaces the existing one. Only a view can
1309        be updated with a new definition.
1310      table: A Table resource to be passed as the request body.
1311    """
1312    client = GetClientFromFlags()
1313    global_params = GetGlobalParamsFromFlags()
1314    request = messages.FusiontablesTableUpdateRequest(
1315        tableId=tableId.decode('utf8'),
1316        )
1317    if FLAGS['replaceViewDefinition'].present:
1318      request.replaceViewDefinition = FLAGS.replaceViewDefinition
1319    if FLAGS['table'].present:
1320      request.table = apitools_base.JsonToMessage(messages.Table, FLAGS.table)
1321    result = client.table.Update(
1322        request, global_params=global_params)
1323    print apitools_base_cli.FormatOutput(result)
1324
1325
1326class TaskDelete(apitools_base_cli.NewCmd):
1327  """Command wrapping task.Delete."""
1328
1329  usage = """task_delete <tableId> <taskId>"""
1330
1331  def __init__(self, name, fv):
1332    super(TaskDelete, self).__init__(name, fv)
1333
1334  def RunWithArgs(self, tableId, taskId):
1335    """Deletes the task, unless already started.
1336
1337    Args:
1338      tableId: Table from which the task is being deleted.
1339      taskId: A string attribute.
1340    """
1341    client = GetClientFromFlags()
1342    global_params = GetGlobalParamsFromFlags()
1343    request = messages.FusiontablesTaskDeleteRequest(
1344        tableId=tableId.decode('utf8'),
1345        taskId=taskId.decode('utf8'),
1346        )
1347    result = client.task.Delete(
1348        request, global_params=global_params)
1349    print apitools_base_cli.FormatOutput(result)
1350
1351
1352class TaskGet(apitools_base_cli.NewCmd):
1353  """Command wrapping task.Get."""
1354
1355  usage = """task_get <tableId> <taskId>"""
1356
1357  def __init__(self, name, fv):
1358    super(TaskGet, self).__init__(name, fv)
1359
1360  def RunWithArgs(self, tableId, taskId):
1361    """Retrieves a specific task by its id.
1362
1363    Args:
1364      tableId: Table to which the task belongs.
1365      taskId: A string attribute.
1366    """
1367    client = GetClientFromFlags()
1368    global_params = GetGlobalParamsFromFlags()
1369    request = messages.FusiontablesTaskGetRequest(
1370        tableId=tableId.decode('utf8'),
1371        taskId=taskId.decode('utf8'),
1372        )
1373    result = client.task.Get(
1374        request, global_params=global_params)
1375    print apitools_base_cli.FormatOutput(result)
1376
1377
1378class TaskList(apitools_base_cli.NewCmd):
1379  """Command wrapping task.List."""
1380
1381  usage = """task_list <tableId>"""
1382
1383  def __init__(self, name, fv):
1384    super(TaskList, self).__init__(name, fv)
1385    flags.DEFINE_integer(
1386        'maxResults',
1387        None,
1388        u'Maximum number of columns to return. Optional. Default is 5.',
1389        flag_values=fv)
1390    flags.DEFINE_string(
1391        'pageToken',
1392        None,
1393        'A string attribute.',
1394        flag_values=fv)
1395    flags.DEFINE_integer(
1396        'startIndex',
1397        None,
1398        'A integer attribute.',
1399        flag_values=fv)
1400
1401  def RunWithArgs(self, tableId):
1402    """Retrieves a list of tasks.
1403
1404    Args:
1405      tableId: Table whose tasks are being listed.
1406
1407    Flags:
1408      maxResults: Maximum number of columns to return. Optional. Default is 5.
1409      pageToken: A string attribute.
1410      startIndex: A integer attribute.
1411    """
1412    client = GetClientFromFlags()
1413    global_params = GetGlobalParamsFromFlags()
1414    request = messages.FusiontablesTaskListRequest(
1415        tableId=tableId.decode('utf8'),
1416        )
1417    if FLAGS['maxResults'].present:
1418      request.maxResults = FLAGS.maxResults
1419    if FLAGS['pageToken'].present:
1420      request.pageToken = FLAGS.pageToken.decode('utf8')
1421    if FLAGS['startIndex'].present:
1422      request.startIndex = FLAGS.startIndex
1423    result = client.task.List(
1424        request, global_params=global_params)
1425    print apitools_base_cli.FormatOutput(result)
1426
1427
1428class TemplateDelete(apitools_base_cli.NewCmd):
1429  """Command wrapping template.Delete."""
1430
1431  usage = """template_delete <tableId> <templateId>"""
1432
1433  def __init__(self, name, fv):
1434    super(TemplateDelete, self).__init__(name, fv)
1435
1436  def RunWithArgs(self, tableId, templateId):
1437    """Deletes a template
1438
1439    Args:
1440      tableId: Table from which the template is being deleted
1441      templateId: Identifier for the template which is being deleted
1442    """
1443    client = GetClientFromFlags()
1444    global_params = GetGlobalParamsFromFlags()
1445    request = messages.FusiontablesTemplateDeleteRequest(
1446        tableId=tableId.decode('utf8'),
1447        templateId=templateId,
1448        )
1449    result = client.template.Delete(
1450        request, global_params=global_params)
1451    print apitools_base_cli.FormatOutput(result)
1452
1453
1454class TemplateGet(apitools_base_cli.NewCmd):
1455  """Command wrapping template.Get."""
1456
1457  usage = """template_get <tableId> <templateId>"""
1458
1459  def __init__(self, name, fv):
1460    super(TemplateGet, self).__init__(name, fv)
1461
1462  def RunWithArgs(self, tableId, templateId):
1463    """Retrieves a specific template by its id
1464
1465    Args:
1466      tableId: Table to which the template belongs
1467      templateId: Identifier for the template that is being requested
1468    """
1469    client = GetClientFromFlags()
1470    global_params = GetGlobalParamsFromFlags()
1471    request = messages.FusiontablesTemplateGetRequest(
1472        tableId=tableId.decode('utf8'),
1473        templateId=templateId,
1474        )
1475    result = client.template.Get(
1476        request, global_params=global_params)
1477    print apitools_base_cli.FormatOutput(result)
1478
1479
1480class TemplateInsert(apitools_base_cli.NewCmd):
1481  """Command wrapping template.Insert."""
1482
1483  usage = """template_insert <tableId>"""
1484
1485  def __init__(self, name, fv):
1486    super(TemplateInsert, self).__init__(name, fv)
1487    flags.DEFINE_string(
1488        'automaticColumnNames',
1489        None,
1490        u'List of columns from which the template is to be automatically '
1491        u'constructed. Only one of body or automaticColumns can be specified.',
1492        flag_values=fv)
1493    flags.DEFINE_string(
1494        'body',
1495        None,
1496        u'Body of the template. It contains HTML with {column_name} to insert'
1497        u' values from a particular column. The body is sanitized to remove '
1498        u'certain tags, e.g., script. Only one of body or automaticColumns '
1499        u'can be specified.',
1500        flag_values=fv)
1501    flags.DEFINE_string(
1502        'kind',
1503        u'fusiontables#template',
1504        u'Type name: a template for the info window contents. The template '
1505        u'can either include an HTML body or a list of columns from which the'
1506        u' template is computed automatically.',
1507        flag_values=fv)
1508    flags.DEFINE_string(
1509        'name',
1510        None,
1511        u'Optional name assigned to a template.',
1512        flag_values=fv)
1513    flags.DEFINE_integer(
1514        'templateId',
1515        None,
1516        u'Identifier for the template, unique within the context of a '
1517        u'particular table.',
1518        flag_values=fv)
1519
1520  def RunWithArgs(self, tableId):
1521    """Creates a new template for the table.
1522
1523    Args:
1524      tableId: Identifier for the table for which the template is defined.
1525
1526    Flags:
1527      automaticColumnNames: List of columns from which the template is to be
1528        automatically constructed. Only one of body or automaticColumns can be
1529        specified.
1530      body: Body of the template. It contains HTML with {column_name} to
1531        insert values from a particular column. The body is sanitized to
1532        remove certain tags, e.g., script. Only one of body or
1533        automaticColumns can be specified.
1534      kind: Type name: a template for the info window contents. The template
1535        can either include an HTML body or a list of columns from which the
1536        template is computed automatically.
1537      name: Optional name assigned to a template.
1538      templateId: Identifier for the template, unique within the context of a
1539        particular table.
1540    """
1541    client = GetClientFromFlags()
1542    global_params = GetGlobalParamsFromFlags()
1543    request = messages.Template(
1544        tableId=tableId.decode('utf8'),
1545        )
1546    if FLAGS['automaticColumnNames'].present:
1547      request.automaticColumnNames = [x.decode('utf8') for x in FLAGS.automaticColumnNames]
1548    if FLAGS['body'].present:
1549      request.body = FLAGS.body.decode('utf8')
1550    if FLAGS['kind'].present:
1551      request.kind = FLAGS.kind.decode('utf8')
1552    if FLAGS['name'].present:
1553      request.name = FLAGS.name.decode('utf8')
1554    if FLAGS['templateId'].present:
1555      request.templateId = FLAGS.templateId
1556    result = client.template.Insert(
1557        request, global_params=global_params)
1558    print apitools_base_cli.FormatOutput(result)
1559
1560
1561class TemplateList(apitools_base_cli.NewCmd):
1562  """Command wrapping template.List."""
1563
1564  usage = """template_list <tableId>"""
1565
1566  def __init__(self, name, fv):
1567    super(TemplateList, self).__init__(name, fv)
1568    flags.DEFINE_integer(
1569        'maxResults',
1570        None,
1571        u'Maximum number of templates to return. Optional. Default is 5.',
1572        flag_values=fv)
1573    flags.DEFINE_string(
1574        'pageToken',
1575        None,
1576        u'Continuation token specifying which results page to return. '
1577        u'Optional.',
1578        flag_values=fv)
1579
1580  def RunWithArgs(self, tableId):
1581    """Retrieves a list of templates.
1582
1583    Args:
1584      tableId: Identifier for the table whose templates are being requested
1585
1586    Flags:
1587      maxResults: Maximum number of templates to return. Optional. Default is
1588        5.
1589      pageToken: Continuation token specifying which results page to return.
1590        Optional.
1591    """
1592    client = GetClientFromFlags()
1593    global_params = GetGlobalParamsFromFlags()
1594    request = messages.FusiontablesTemplateListRequest(
1595        tableId=tableId.decode('utf8'),
1596        )
1597    if FLAGS['maxResults'].present:
1598      request.maxResults = FLAGS.maxResults
1599    if FLAGS['pageToken'].present:
1600      request.pageToken = FLAGS.pageToken.decode('utf8')
1601    result = client.template.List(
1602        request, global_params=global_params)
1603    print apitools_base_cli.FormatOutput(result)
1604
1605
1606class TemplatePatch(apitools_base_cli.NewCmd):
1607  """Command wrapping template.Patch."""
1608
1609  usage = """template_patch <tableId> <templateId>"""
1610
1611  def __init__(self, name, fv):
1612    super(TemplatePatch, self).__init__(name, fv)
1613    flags.DEFINE_string(
1614        'automaticColumnNames',
1615        None,
1616        u'List of columns from which the template is to be automatically '
1617        u'constructed. Only one of body or automaticColumns can be specified.',
1618        flag_values=fv)
1619    flags.DEFINE_string(
1620        'body',
1621        None,
1622        u'Body of the template. It contains HTML with {column_name} to insert'
1623        u' values from a particular column. The body is sanitized to remove '
1624        u'certain tags, e.g., script. Only one of body or automaticColumns '
1625        u'can be specified.',
1626        flag_values=fv)
1627    flags.DEFINE_string(
1628        'kind',
1629        u'fusiontables#template',
1630        u'Type name: a template for the info window contents. The template '
1631        u'can either include an HTML body or a list of columns from which the'
1632        u' template is computed automatically.',
1633        flag_values=fv)
1634    flags.DEFINE_string(
1635        'name',
1636        None,
1637        u'Optional name assigned to a template.',
1638        flag_values=fv)
1639
1640  def RunWithArgs(self, tableId, templateId):
1641    """Updates an existing template. This method supports patch semantics.
1642
1643    Args:
1644      tableId: Identifier for the table for which the template is defined.
1645      templateId: Identifier for the template, unique within the context of a
1646        particular table.
1647
1648    Flags:
1649      automaticColumnNames: List of columns from which the template is to be
1650        automatically constructed. Only one of body or automaticColumns can be
1651        specified.
1652      body: Body of the template. It contains HTML with {column_name} to
1653        insert values from a particular column. The body is sanitized to
1654        remove certain tags, e.g., script. Only one of body or
1655        automaticColumns can be specified.
1656      kind: Type name: a template for the info window contents. The template
1657        can either include an HTML body or a list of columns from which the
1658        template is computed automatically.
1659      name: Optional name assigned to a template.
1660    """
1661    client = GetClientFromFlags()
1662    global_params = GetGlobalParamsFromFlags()
1663    request = messages.Template(
1664        tableId=tableId.decode('utf8'),
1665        templateId=templateId,
1666        )
1667    if FLAGS['automaticColumnNames'].present:
1668      request.automaticColumnNames = [x.decode('utf8') for x in FLAGS.automaticColumnNames]
1669    if FLAGS['body'].present:
1670      request.body = FLAGS.body.decode('utf8')
1671    if FLAGS['kind'].present:
1672      request.kind = FLAGS.kind.decode('utf8')
1673    if FLAGS['name'].present:
1674      request.name = FLAGS.name.decode('utf8')
1675    result = client.template.Patch(
1676        request, global_params=global_params)
1677    print apitools_base_cli.FormatOutput(result)
1678
1679
1680class TemplateUpdate(apitools_base_cli.NewCmd):
1681  """Command wrapping template.Update."""
1682
1683  usage = """template_update <tableId> <templateId>"""
1684
1685  def __init__(self, name, fv):
1686    super(TemplateUpdate, self).__init__(name, fv)
1687    flags.DEFINE_string(
1688        'automaticColumnNames',
1689        None,
1690        u'List of columns from which the template is to be automatically '
1691        u'constructed. Only one of body or automaticColumns can be specified.',
1692        flag_values=fv)
1693    flags.DEFINE_string(
1694        'body',
1695        None,
1696        u'Body of the template. It contains HTML with {column_name} to insert'
1697        u' values from a particular column. The body is sanitized to remove '
1698        u'certain tags, e.g., script. Only one of body or automaticColumns '
1699        u'can be specified.',
1700        flag_values=fv)
1701    flags.DEFINE_string(
1702        'kind',
1703        u'fusiontables#template',
1704        u'Type name: a template for the info window contents. The template '
1705        u'can either include an HTML body or a list of columns from which the'
1706        u' template is computed automatically.',
1707        flag_values=fv)
1708    flags.DEFINE_string(
1709        'name',
1710        None,
1711        u'Optional name assigned to a template.',
1712        flag_values=fv)
1713
1714  def RunWithArgs(self, tableId, templateId):
1715    """Updates an existing template
1716
1717    Args:
1718      tableId: Identifier for the table for which the template is defined.
1719      templateId: Identifier for the template, unique within the context of a
1720        particular table.
1721
1722    Flags:
1723      automaticColumnNames: List of columns from which the template is to be
1724        automatically constructed. Only one of body or automaticColumns can be
1725        specified.
1726      body: Body of the template. It contains HTML with {column_name} to
1727        insert values from a particular column. The body is sanitized to
1728        remove certain tags, e.g., script. Only one of body or
1729        automaticColumns can be specified.
1730      kind: Type name: a template for the info window contents. The template
1731        can either include an HTML body or a list of columns from which the
1732        template is computed automatically.
1733      name: Optional name assigned to a template.
1734    """
1735    client = GetClientFromFlags()
1736    global_params = GetGlobalParamsFromFlags()
1737    request = messages.Template(
1738        tableId=tableId.decode('utf8'),
1739        templateId=templateId,
1740        )
1741    if FLAGS['automaticColumnNames'].present:
1742      request.automaticColumnNames = [x.decode('utf8') for x in FLAGS.automaticColumnNames]
1743    if FLAGS['body'].present:
1744      request.body = FLAGS.body.decode('utf8')
1745    if FLAGS['kind'].present:
1746      request.kind = FLAGS.kind.decode('utf8')
1747    if FLAGS['name'].present:
1748      request.name = FLAGS.name.decode('utf8')
1749    result = client.template.Update(
1750        request, global_params=global_params)
1751    print apitools_base_cli.FormatOutput(result)
1752
1753
1754def main(_):
1755  appcommands.AddCmd('pyshell', PyShell)
1756  appcommands.AddCmd('column_delete', ColumnDelete)
1757  appcommands.AddCmd('column_get', ColumnGet)
1758  appcommands.AddCmd('column_insert', ColumnInsert)
1759  appcommands.AddCmd('column_list', ColumnList)
1760  appcommands.AddCmd('column_patch', ColumnPatch)
1761  appcommands.AddCmd('column_update', ColumnUpdate)
1762  appcommands.AddCmd('query_sql', QuerySql)
1763  appcommands.AddCmd('query_sqlGet', QuerySqlGet)
1764  appcommands.AddCmd('style_delete', StyleDelete)
1765  appcommands.AddCmd('style_get', StyleGet)
1766  appcommands.AddCmd('style_insert', StyleInsert)
1767  appcommands.AddCmd('style_list', StyleList)
1768  appcommands.AddCmd('style_patch', StylePatch)
1769  appcommands.AddCmd('style_update', StyleUpdate)
1770  appcommands.AddCmd('table_copy', TableCopy)
1771  appcommands.AddCmd('table_delete', TableDelete)
1772  appcommands.AddCmd('table_get', TableGet)
1773  appcommands.AddCmd('table_importRows', TableImportRows)
1774  appcommands.AddCmd('table_importTable', TableImportTable)
1775  appcommands.AddCmd('table_insert', TableInsert)
1776  appcommands.AddCmd('table_list', TableList)
1777  appcommands.AddCmd('table_patch', TablePatch)
1778  appcommands.AddCmd('table_update', TableUpdate)
1779  appcommands.AddCmd('task_delete', TaskDelete)
1780  appcommands.AddCmd('task_get', TaskGet)
1781  appcommands.AddCmd('task_list', TaskList)
1782  appcommands.AddCmd('template_delete', TemplateDelete)
1783  appcommands.AddCmd('template_get', TemplateGet)
1784  appcommands.AddCmd('template_insert', TemplateInsert)
1785  appcommands.AddCmd('template_list', TemplateList)
1786  appcommands.AddCmd('template_patch', TemplatePatch)
1787  appcommands.AddCmd('template_update', TemplateUpdate)
1788
1789  apitools_base_cli.SetupLogger()
1790  if hasattr(appcommands, 'SetDefaultCommand'):
1791    appcommands.SetDefaultCommand('pyshell')
1792
1793
1794run_main = apitools_base_cli.run_main
1795
1796if __name__ == '__main__':
1797  appcommands.Run()
1798