fix: use print() function in both Python 2 and Python 3 (#18395)
Legacy print statements are syntax errors in Python 3 but print() function works as expected in both Python 2 and Python 3. Old style exceptions are syntax errors in Python 3 but new style exceptions work as expected in both Python 2 and Python 3.
This commit is contained in:
parent
7d0a93858d
commit
1d6e5e6e70
18 changed files with 62 additions and 894 deletions
|
@ -1,5 +1,6 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
from __future__ import print_function
|
||||
import errno
|
||||
import os
|
||||
import platform
|
||||
|
@ -47,7 +48,8 @@ def get_env_var(name):
|
|||
# TODO Remove ATOM_SHELL_* fallback values
|
||||
value = os.environ.get('ATOM_SHELL_' + name, '')
|
||||
if value:
|
||||
print 'Warning: Use $ELECTRON_' + name + ' instead of $ATOM_SHELL_' + name
|
||||
print('Warning: Use $ELECTRON_' + name +
|
||||
' instead of $ATOM_SHELL_' + name)
|
||||
return value
|
||||
|
||||
|
||||
|
@ -63,7 +65,7 @@ def s3_config():
|
|||
|
||||
|
||||
def enable_verbose_mode():
|
||||
print 'Running in verbose mode'
|
||||
print('Running in verbose mode')
|
||||
global verbose_mode
|
||||
verbose_mode = True
|
||||
|
||||
|
|
|
@ -11,6 +11,11 @@ PYYAML_LIB_DIR = os.path.join(VENDOR_DIR, 'pyyaml', 'lib')
|
|||
sys.path.append(PYYAML_LIB_DIR)
|
||||
import yaml #pylint: disable=wrong-import-position,wrong-import-order
|
||||
|
||||
try:
|
||||
basestring # Python 2
|
||||
except NameError: # Python 3
|
||||
basestring = str # pylint: disable=redefined-builtin
|
||||
|
||||
|
||||
class Verbosity:
|
||||
CHATTY = 'chatty' # stdout and stderr
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
from __future__ import print_function
|
||||
import atexit
|
||||
import contextlib
|
||||
import datetime
|
||||
|
@ -64,7 +65,7 @@ def download(text, url, path):
|
|||
if hasattr(ssl, '_create_unverified_context'):
|
||||
ssl._create_default_https_context = ssl._create_unverified_context
|
||||
|
||||
print "Downloading %s to %s" % (url, path)
|
||||
print("Downloading %s to %s" % (url, path))
|
||||
web_file = urllib2.urlopen(url)
|
||||
file_size = int(web_file.info().getheaders("Content-Length")[0])
|
||||
downloaded_size = 0
|
||||
|
@ -83,12 +84,12 @@ def download(text, url, path):
|
|||
if not ci:
|
||||
percent = downloaded_size * 100. / file_size
|
||||
status = "\r%s %10d [%3.1f%%]" % (text, downloaded_size, percent)
|
||||
print status,
|
||||
print(status, end=' ')
|
||||
|
||||
if ci:
|
||||
print "%s done." % (text)
|
||||
print("%s done." % (text))
|
||||
else:
|
||||
print
|
||||
print()
|
||||
return path
|
||||
|
||||
|
||||
|
@ -148,15 +149,15 @@ def execute(argv, env=None, cwd=None):
|
|||
if env is None:
|
||||
env = os.environ
|
||||
if is_verbose_mode():
|
||||
print ' '.join(argv)
|
||||
print(' '.join(argv))
|
||||
try:
|
||||
output = subprocess.check_output(argv, stderr=subprocess.STDOUT,
|
||||
env=env, cwd=cwd)
|
||||
if is_verbose_mode():
|
||||
print output
|
||||
print(output)
|
||||
return output
|
||||
except subprocess.CalledProcessError as e:
|
||||
print e.output
|
||||
print(e.output)
|
||||
raise e
|
||||
|
||||
|
||||
|
@ -164,11 +165,11 @@ def execute_stdout(argv, env=None, cwd=None):
|
|||
if env is None:
|
||||
env = os.environ
|
||||
if is_verbose_mode():
|
||||
print ' '.join(argv)
|
||||
print(' '.join(argv))
|
||||
try:
|
||||
subprocess.check_call(argv, env=env, cwd=cwd)
|
||||
except subprocess.CalledProcessError as e:
|
||||
print e.output
|
||||
print(e.output)
|
||||
raise e
|
||||
else:
|
||||
execute(argv, env, cwd)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue