Files
impala/bin/jenkins/dockerized-impala-preserve-vars.py
Joe McDonnell 2b550634d2 IMPALA-11952 (part 2): Fix print function syntax
Python 3 now treats print as a function and requires
the parenthesis in invocation.

print "Hello World!"
is now:
print("Hello World!")

This fixes all locations to use the function
invocation. This is more complicated when the output
is being redirected to a file or when avoiding the
usual newline.

print >> sys.stderr , "Hello World!"
is now:
print("Hello World!", file=sys.stderr)

To support this properly and guarantee equivalent behavior
between python 2 and python 3, all files that use print
now add this import:
from __future__ import print_function

This also fixes random flake8 issues that intersect with
the changes.

Testing:
 - check-python-syntax.sh shows no errors related to print

Change-Id: Ib634958369ad777a41e72d80c8053b74384ac351
Reviewed-on: http://gerrit.cloudera.org:8080/19552
Reviewed-by: Joe McDonnell <joemcdonnell@cloudera.com>
Reviewed-by: Michael Smith <michael.smith@cloudera.com>
Tested-by: Michael Smith <michael.smith@cloudera.com>
2023-02-28 17:11:50 +00:00

58 lines
2.2 KiB
Python
Executable File

#!/usr/bin/env python
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
# Since dockerized-impala-bootstrap-and-test.sh does a full re-login
# as part of calling dockerized-impala-run-tests.sh, it loses
# environment variables. Preserving the environment variables are important
# for parameterized Jenkins jobs. This script takes a list of environment
# variables and preserves them by adding export statements to
# bin/impala-config-local.sh.
#
# Usage: dockerized-impala-preserve-vars.py [env var1] [env var2] ...
# If an environment variable is not defined in the current environment,
# it is omitted with a warning.
from __future__ import print_function
import sys
import os
def main():
if len(sys.argv) <= 1:
print("Usage: {0} [env vars]".format(sys.argv[0]))
sys.exit(1)
if "IMPALA_HOME" not in os.environ:
print("ERROR: IMPALA_HOME must be defined")
sys.exit(1)
impala_home = os.environ["IMPALA_HOME"]
# Append to the end of bin/impala-config-local.sh
with open("{0}/bin/impala-config-local.sh".format(impala_home), "a") as f:
for env_var in sys.argv[1:]:
if env_var not in os.environ:
print("{0} is not defined in the environment, skipping...".format(env_var))
continue
new_export = "export {0}=\"{1}\"".format(env_var, os.environ[env_var])
print("Adding '{0}' to bin/impala-config-local.sh".format(new_export))
f.write("{0}\n".format(new_export))
if __name__ == "__main__": main()