Replace GetHostSize with a cross-platform implementation.

This is in preparation for Telemetry for Android devices with a Mac host.

BUG=355646

Review URL: https://codereview.chromium.org/201443017

git-svn-id: http://src.chromium.org/svn/trunk/src/build@259265 4ff67af0-8c30-449e-8e8b-ad334ec8d88c
This commit is contained in:
tonyg@chromium.org 2014-03-25 18:28:56 +00:00
Родитель a79ec8edc6
Коммит b62fcac6f2
2 изменённых файлов: 20 добавлений и 5 удалений

Просмотреть файл

@ -26,6 +26,7 @@ import cmd_helper
import constants
import screenshot
import system_properties
from utils import host_utils
try:
from pylib import pexpect
@ -1001,10 +1002,7 @@ class AndroidCommands(object):
if host_path_mtime == os.stat(host_path).st_mtime:
return
def GetHostSize(path):
return int(cmd_helper.GetCmdOutput(['du', '-sb', path]).split()[0])
size = GetHostSize(host_path)
size = host_utils.GetRecursiveDiskUsage(host_path)
self._pushed_files.append(device_path)
self._potential_push_size += size
@ -1039,7 +1037,8 @@ class AndroidCommands(object):
diff_size = 0
if len(changed_files) <= MAX_INDIVIDUAL_PUSHES:
diff_size = sum(GetHostSize(f[0]) for f in changed_files)
diff_size = sum(host_utils.GetRecursiveDiskUsage(f[0])
for f in changed_files)
# TODO(craigdh): Replace this educated guess with a heuristic that
# approximates the push time for each method.

Просмотреть файл

@ -0,0 +1,16 @@
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import os
def GetRecursiveDiskUsage(path):
"""Returns the disk usage in bytes of |path|. Similar to `du -sb |path|`."""
running_size = os.path.getsize(path)
if os.path.isdir(path):
for root, dirs, files in os.walk(path):
running_size += sum([os.path.getsize(os.path.join(root, f))
for f in files + dirs])
return running_size