Skip to content

Commit

Permalink
//build: Convert print statements to Python 3 style
Browse files Browse the repository at this point in the history
Ran "2to3 -w -n -f print ./base" and manually added imports.
There are no intended behaviour changes.

Bug: 941669
Change-Id: Ie2830e213eae3a5d7753ce503020e02811b726d1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1585890
Commit-Queue: Raul Tambre <raul@tambre.ee>
Reviewed-by: Nico Weber <thakis@chromium.org>
Reviewed-by: Dirk Pranke <dpranke@chromium.org>
Auto-Submit: Raul Tambre <raul@tambre.ee>
Cr-Commit-Position: refs/heads/master@{#658917}
  • Loading branch information
tambry authored and Commit Bot committed May 12, 2019
1 parent 659ba6a commit 9e24293
Show file tree
Hide file tree
Showing 74 changed files with 475 additions and 326 deletions.
6 changes: 4 additions & 2 deletions build/android/adb_command_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

"""Utility for reading / writing command-line flag files on device(s)."""

from __future__ import print_function

import argparse
import logging
import sys
Expand Down Expand Up @@ -80,14 +82,14 @@ def update_flags(device):

updated_values = all_devices.pMap(update_flags).pGet(None)

print '%sCurrent flags (in %s):' % (action, args.name)
print('%sCurrent flags (in %s):' % (action, args.name))
for d, desc, flags in updated_values:
if flags:
# Shell-quote flags for easy copy/paste as new args on the terminal.
quoted_flags = ' '.join(cmd_helper.SingleQuote(f) for f in sorted(flags))
else:
quoted_flags = '( empty )'
print ' %s (%s): %s' % (d, desc, quoted_flags)
print(' %s (%s): %s' % (d, desc, quoted_flags))

return 0

Expand Down
8 changes: 5 additions & 3 deletions build/android/adb_logcat_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
early enough to not miss anything.
"""

from __future__ import print_function

import logging
import os
import re
Expand Down Expand Up @@ -98,7 +100,7 @@ def main(base_dir, adb_cmd='adb'):
"""Monitor adb forever. Expects a SIGINT (Ctrl-C) to kill."""
# We create the directory to ensure 'run once' semantics
if os.path.exists(base_dir):
print 'adb_logcat_monitor: %s already exists? Cleaning' % base_dir
print('adb_logcat_monitor: %s already exists? Cleaning' % base_dir)
shutil.rmtree(base_dir, ignore_errors=True)

os.makedirs(base_dir)
Expand Down Expand Up @@ -150,7 +152,7 @@ def SigtermHandler(_signum, _unused_frame):

if __name__ == '__main__':
if 2 <= len(sys.argv) <= 3:
print 'adb_logcat_monitor: Initializing'
print('adb_logcat_monitor: Initializing')
sys.exit(main(*sys.argv[1:3]))

print 'Usage: %s <base_dir> [<adb_binary_path>]' % sys.argv[0]
print('Usage: %s <base_dir> [<adb_binary_path>]' % sys.argv[0])
67 changes: 34 additions & 33 deletions build/android/apk_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
# Using colorama.Fore/Back/Style members
# pylint: disable=no-member

from __future__ import print_function

import argparse
import collections
import json
Expand Down Expand Up @@ -222,7 +224,7 @@ def Install(device):
if ShouldWarnFakeFeatureModuleInstallFlag(device):
msg = ('Command line has no %s: Fake modules will be ignored.' %
FAKE_FEATURE_MODULE_INSTALL)
print _Colorize(msg, colorama.Fore.YELLOW + colorama.Style.BRIGHT)
print(_Colorize(msg, colorama.Fore.YELLOW + colorama.Style.BRIGHT))

InstallFakeModules(device)

Expand Down Expand Up @@ -346,8 +348,8 @@ def launch(device):
device.StartActivity(launch_intent)
device_utils.DeviceUtils.parallel(devices).pMap(launch)
if wait_for_java_debugger:
print ('Waiting for debugger to attach to process: ' +
_Colorize(debug_process_name, colorama.Fore.YELLOW))
print('Waiting for debugger to attach to process: ' +
_Colorize(debug_process_name, colorama.Fore.YELLOW))


def _ChangeFlags(devices, argv, command_line_flags_file):
Expand Down Expand Up @@ -399,8 +401,8 @@ def _RunGdb(device, package_name, debug_process_name, pid, output_directory,
if target_cpu:
cmd.append('--target-arch=%s' % _TargetCpuToTargetArch(target_cpu))
logging.warning('Running: %s', ' '.join(pipes.quote(x) for x in cmd))
print _Colorize(
'All subsequent output is from adb_gdb script.', colorama.Fore.YELLOW)
print(_Colorize('All subsequent output is from adb_gdb script.',
colorama.Fore.YELLOW))
os.execv(gdb_script_path, cmd)


Expand Down Expand Up @@ -431,13 +433,12 @@ def mem_usage_helper(d):
all_results = parallel_devices.pMap(mem_usage_helper).pGet(None)
for result in _PrintPerDeviceOutput(devices, all_results):
if not result:
print 'No processes found.'
print('No processes found.')
else:
for name, usage in sorted(result):
print _Colorize(
'==== Output of "dumpsys meminfo %s" ====' % name,
colorama.Fore.GREEN)
print usage
print(_Colorize('==== Output of "dumpsys meminfo %s" ====' % name,
colorama.Fore.GREEN))
print(usage)


def _DuHelper(device, path_spec, run_as=None):
Expand Down Expand Up @@ -609,15 +610,15 @@ def disk_usage_helper(d):
compilation_filter)

def print_sizes(desc, sizes):
print '%s: %d KiB' % (desc, sum(sizes.itervalues()))
print('%s: %d KiB' % (desc, sum(sizes.itervalues())))
for path, size in sorted(sizes.iteritems()):
print ' %s: %s KiB' % (path, size)
print(' %s: %s KiB' % (path, size))

parallel_devices = device_utils.DeviceUtils.parallel(devices)
all_results = parallel_devices.pMap(disk_usage_helper).pGet(None)
for result in _PrintPerDeviceOutput(devices, all_results):
if not result:
print 'APK is not installed.'
print('APK is not installed.')
continue

(data_dir_sizes, code_cache_sizes, apk_sizes, lib_sizes, odex_sizes,
Expand All @@ -634,7 +635,7 @@ def print_sizes(desc, sizes):
if show_warning:
logging.warning('For a more realistic odex size, run:')
logging.warning(' %s compile-dex [speed|speed-profile]', sys.argv[0])
print 'Total: %s KiB (%.1f MiB)' % (total, total / 1024.0)
print('Total: %s KiB (%.1f MiB)' % (total, total / 1024.0))


class _LogcatProcessor(object):
Expand Down Expand Up @@ -801,13 +802,13 @@ def _RunPs(devices, package_name):
lambda d: _GetPackageProcesses(d, package_name)).pGet(None)
for processes in _PrintPerDeviceOutput(devices, all_processes):
if not processes:
print 'No processes found.'
print('No processes found.')
else:
proc_map = collections.defaultdict(list)
for p in processes:
proc_map[p.name].append(str(p.pid))
for name, pids in sorted(proc_map.items()):
print name, ','.join(pids)
print(name, ','.join(pids))


def _RunShell(devices, package_name, cmd):
Expand All @@ -817,17 +818,17 @@ def _RunShell(devices, package_name, cmd):
cmd, run_as=package_name).pGet(None)
for output in _PrintPerDeviceOutput(devices, outputs):
for line in output:
print line
print(line)
else:
adb_path = adb_wrapper.AdbWrapper.GetAdbPath()
cmd = [adb_path, '-s', devices[0].serial, 'shell']
# Pre-N devices do not support -t flag.
if devices[0].build_version_sdk >= version_codes.NOUGAT:
cmd += ['-t', 'run-as', package_name]
else:
print 'Upon entering the shell, run:'
print 'run-as', package_name
print
print('Upon entering the shell, run:')
print('run-as', package_name)
print()
os.execv(adb_path, cmd)


Expand All @@ -838,7 +839,7 @@ def _RunCompileDex(devices, package_name, compilation_filter):
outputs = parallel_devices.RunShellCommand(cmd, timeout=120).pGet(None)
for output in _PrintPerDeviceOutput(devices, outputs):
for line in output:
print line
print(line)


def _RunProfile(device, package_name, host_build_directory, pprof_out_path,
Expand All @@ -858,7 +859,7 @@ def _RunProfile(device, package_name, host_build_directory, pprof_out_path,

simpleperf.ConvertSimpleperfToPprof(host_simpleperf_out_path,
host_build_directory, pprof_out_path)
print textwrap.dedent("""
print(textwrap.dedent("""
Profile data written to %(s)s.
To view profile as a call graph in browser:
Expand All @@ -868,7 +869,7 @@ def _RunProfile(device, package_name, host_build_directory, pprof_out_path,
pprof -top %(s)s
pprof has many useful customization options; `pprof --help` for details.
""" % {'s': pprof_out_path})
""" % {'s': pprof_out_path}))


def _GenerateAvailableDevicesMessage(devices):
Expand All @@ -894,11 +895,11 @@ def flags_helper(d):

parallel_devices = device_utils.DeviceUtils.parallel(devices)
outputs = parallel_devices.pMap(flags_helper).pGet(None)
print 'Existing flags per-device (via /data/local/tmp/{}):'.format(
command_line_flags_file)
print('Existing flags per-device (via /data/local/tmp/{}):'.format(
command_line_flags_file))
for flags in _PrintPerDeviceOutput(devices, outputs, single_line=True):
quoted_flags = ' '.join(pipes.quote(f) for f in flags)
print quoted_flags or 'No flags set.'
print(quoted_flags or 'No flags set.')


def _DeviceCachePath(device, output_directory):
Expand Down Expand Up @@ -1134,7 +1135,7 @@ class _DevicesCommand(_Command):
all_devices_by_default = True

def Run(self):
print _GenerateAvailableDevicesMessage(self.devices)
print(_GenerateAvailableDevicesMessage(self.devices))


class _PackageInfoCommand(_Command):
Expand All @@ -1148,12 +1149,12 @@ class _PackageInfoCommand(_Command):

def Run(self):
# Format all (even ints) as strings, to handle cases where APIs return None
print 'Package name: "%s"' % self.args.package_name
print 'versionCode: %s' % self.apk_helper.GetVersionCode()
print 'versionName: "%s"' % self.apk_helper.GetVersionName()
print 'minSdkVersion: %s' % self.apk_helper.GetMinSdkVersion()
print 'targetSdkVersion: %s' % self.apk_helper.GetTargetSdkVersion()
print 'Supported ABIs: %r' % self.apk_helper.GetAbis()
print('Package name: "%s"' % self.args.package_name)
print('versionCode: %s' % self.apk_helper.GetVersionCode())
print('versionName: "%s"' % self.apk_helper.GetVersionName())
print('minSdkVersion: %s' % self.apk_helper.GetMinSdkVersion())
print('targetSdkVersion: %s' % self.apk_helper.GetTargetSdkVersion())
print('Supported ABIs: %r' % self.apk_helper.GetAbis())


class _InstallCommand(_Command):
Expand Down
5 changes: 3 additions & 2 deletions build/android/asan_symbolize.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

from __future__ import print_function

import collections
import optparse
Expand Down Expand Up @@ -105,9 +106,9 @@ def _PrintSymbolized(asan_input, arch):
# that usually one wants to display the last list item, not the first.
# The code below takes the first, is this the best choice here?
s = all_symbols[m.library][m.rel_address][0]
print '%s%s %s %s' % (m.prefix, m.pos, s[0], s[1])
print('%s%s %s %s' % (m.prefix, m.pos, s[0], s[1]))
else:
print log_line.raw
print(log_line.raw)


def main():
Expand Down
6 changes: 4 additions & 2 deletions build/android/binary_size/apk_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

from __future__ import print_function

import argparse
import os
import sys
Expand Down Expand Up @@ -38,10 +40,10 @@ def MaybeDownloadApk(builder, milestone, apk, download_path, bucket):
sha1_path = apk_path + '.sha1'
base_url = os.path.join(bucket, builder, milestone)
if os.path.exists(apk_path):
print '%s already exists' % apk_path
print('%s already exists' % apk_path)
return apk_path
elif not os.path.exists(sha1_path):
print 'Skipping %s, file not found' % sha1_path
print('Skipping %s, file not found' % sha1_path)
return None
else:
download_from_google_storage.download_from_google_storage(
Expand Down
6 changes: 4 additions & 2 deletions build/android/diff_resource_sizes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

"""Runs resource_sizes.py on two apks and outputs the diff."""

from __future__ import print_function

import argparse
import json
import logging
Expand Down Expand Up @@ -152,7 +154,7 @@ def main():
try:
subprocess.check_output(base_args, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e:
print e.output
print(e.output)
raise

diff_args = shared_args + ['--output-dir', diff_dir, args.diff_apk]
Expand All @@ -161,7 +163,7 @@ def main():
try:
subprocess.check_output(diff_args, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e:
print e.output
print(e.output)
raise

# Combine the separate results
Expand Down
10 changes: 6 additions & 4 deletions build/android/dump_apk_resource_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

"""A script to parse and dump localized strings in resource.arsc files."""

from __future__ import print_function

import argparse
import collections
import contextlib
Expand Down Expand Up @@ -207,13 +209,13 @@ def AddValue(self, res_name, res_config, res_value):
else:
# Sanity check: the resource name should be the same for all chunks.
# Resource ID is redefined with a different name!!
print 'WARNING: Resource key ignored (%s, should be %s)' % (
res_name, self.res_name)
print('WARNING: Resource key ignored (%s, should be %s)' %
(res_name, self.res_name))

if self.res_values.setdefault(res_config, res_value) is not res_value:
print 'WARNING: Duplicate value definition for [config %s]: %s ' \
print('WARNING: Duplicate value definition for [config %s]: %s ' \
'(already has %s)' % (
res_config, res_value, self.res_values[res_config])
res_config, res_value, self.res_values[res_config]))

def ToStringList(self, res_id):
"""Convert entry to string list for human-friendly output."""
Expand Down
6 changes: 4 additions & 2 deletions build/android/generate_emma_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

"""Aggregates EMMA coverage files to produce html output."""

from __future__ import print_function

import fnmatch
import json
import optparse
Expand Down Expand Up @@ -61,8 +63,8 @@ def main():
# Filter out zero-length files. These are created by emma_instr.py when a
# target has no classes matching the coverage filter.
metadata_files = [f for f in metadata_files if os.path.getsize(f)]
print 'Found coverage files: %s' % str(coverage_files)
print 'Found metadata files: %s' % str(metadata_files)
print('Found coverage files: %s' % str(coverage_files))
print('Found metadata files: %s' % str(metadata_files))

sources = []
for f in metadata_files:
Expand Down
8 changes: 5 additions & 3 deletions build/android/gradle/gn_to_cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
The first is recommended, as it will auto-update.
"""

from __future__ import print_function

import functools
import json
import posixpath
Expand Down Expand Up @@ -513,8 +515,8 @@ def WriteTarget(out, target, project):
out.write('\n')

if target.cmake_type is None:
print 'Target {} has unknown target type {}, skipping.'.format(
target.gn_name, target.gn_type)
print('Target {} has unknown target type {}, skipping.'.format(
target.gn_name, target.gn_type))
return

SetVariable(out, 'target', target.cmake_name)
Expand Down Expand Up @@ -672,7 +674,7 @@ def WriteProject(project):

def main():
if len(sys.argv) != 2:
print 'Usage: ' + sys.argv[0] + ' <json_file_name>'
print('Usage: ' + sys.argv[0] + ' <json_file_name>')
exit(1)

json_path = sys.argv[1]
Expand Down
Loading

0 comments on commit 9e24293

Please sign in to comment.