def main()

in marketplace/deployer_util/separate_tester_resources.py [0:0]


def main():

  parser = ArgumentParser(description=_PROG_HELP)
  parser.add_argument(
      "--app_name", required=True, help="the name of the application instance")
  parser.add_argument(
      "--app_uid", required=True, help="the uid of the application instance")
  parser.add_argument(
      "--app_api_version",
      required=True,
      help="apiVersion of the Application CRD")
  parser.add_argument(
      "--manifests", required=True, help="the configuration for tests")
  parser.add_argument(
      "--out_manifests",
      required=True,
      help="the file to write non-test resources to")
  parser.add_argument(
      "--out_test_manifests",
      required=True,
      help="the file to write test resources to")
  args = parser.parse_args()

  if os.path.isfile(args.manifests):
    resources = load_resources_yaml(args.manifests)
  else:
    resources = []
    for filename in os.listdir(args.manifests):
      resources += load_resources_yaml(os.path.join(args.manifests, filename))

  test_resources = []
  nontest_resources = []
  for resource in resources:
    full_name = "{}/{}".format(resource['kind'],
                               deep_get(resource, 'metadata', 'name'))
    if deep_get(resource, 'metadata', 'annotations',
                GOOGLE_CLOUD_TEST) == 'test':
      print("INFO Tester resource: {}".format(full_name))
      set_app_resource_ownership(
          app_uid=args.app_uid,
          app_name=args.app_name,
          app_api_version=args.app_api_version,
          resource=resource)
      test_resources.append(resource)
    else:
      print("INFO Prod resource: {}".format(full_name))
      nontest_resources.append(resource)

  if nontest_resources:
    with open(args.out_manifests, "w", encoding='utf-8') as outfile:
      yaml.safe_dump_all(nontest_resources, outfile, default_flow_style=False)

  if test_resources:
    with open(args.out_test_manifests, "a", encoding='utf-8') as test_outfile:
      yaml.safe_dump_all(test_resources, test_outfile, default_flow_style=False)