def main(argv):
  try:
    argv = FLAGS(argv)
  except gflags.FlagsError, e:
    logging.error('%s\\nUsage: %s ARGS\\n%s', e, argv[0], FLAGS)
    sys.exit(1)

  # Set the logging according to the command-line flag
  numeric_level = getattr(logging, FLAGS.logging_level.upper())
  if not isinstance(numeric_level, int):
    logging.error('Invalid log level: %s', FLAGS.logging_level)
  logging.basicConfig(level=numeric_level)
  if FLAGS.logging_level == 'DEBUG': httplib2.debuglevel = 1

  auth_http = get_auth_http()
  project_id = get_project_id()
  gcs_client = init_client(auth_http, project_id)

  commands = [
      gcs_commands.GetBucketsCommand('Get all buckets', gcs_client),
      gcs_commands.GetBucketCommand('Get a bucket', gcs_client),
      gcs_commands.GetBucketCorsCommand('Get bucket CORS', gcs_client),
      gcs_commands.GetBucketLocationCommand('Get bucket location', gcs_client),
      gcs_commands.InsertBucketCommand('Create a bucket', gcs_client),
      gcs_commands.SetBucketCorsCommand('Set bucket CORS', gcs_client),
      gcs_commands.DeleteBucketCommand('Delete a bucket', gcs_client),
      gcs_commands.GetObjectCommand('Download an object', gcs_client),
      gcs_commands.GetObjectAclsCommand('Get object ACLs', gcs_client),
      gcs_commands.GetObjectMetadataCommand('Get object metadata', gcs_client),
      gcs_commands.InsertObjectCommand('Upload an object', gcs_client),
      gcs_commands.CopyObjectCommand('Copy an object', gcs_client),
      gcs_commands.DeleteObjectCommand('Delete an object', gcs_client),
  ]

  while True:
    print 'What would you like to do? Enter the number.'
    for i in range(len(commands)):
      print '%d: %s' % (i, commands[i].description)
    print '%d: Quit' % len(commands)

    selection = raw_input('Enter your selection: ')
    try:
      selection = int(selection)
    except ValueError, e:
      logging.error('Enter a number.')
      continue

    if selection > len(commands) or selection < 0:
      logging.error('Selection not recognized.')
      continue

    if selection == len(commands): break

    try:
      commands[selection].run_command()
    except Exception, e:
      logging.error('Error running command. Please try again.')
      logging.error(e)
Main application control.
dataset/ETHPy150Open googlearchive/storage-getting-started-python/main.py/main