Upstream version 11.40.277.0
[platform/framework/web/crosswalk.git] / src / tools / telemetry / telemetry / core / platform / desktop_platform_backend.py
1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 import os
6 import subprocess
7
8 from telemetry.core.platform import platform_backend
9 from telemetry.util import support_binaries
10
11
12 class DesktopPlatformBackend(platform_backend.PlatformBackend):
13
14   # This is an abstract class. It is OK to have abstract methods.
15   # pylint: disable=W0223
16
17   def FlushSystemCacheForDirectory(self, directory, ignoring=None):
18     assert directory and os.path.exists(directory), \
19         'Target directory %s must exist' % directory
20     flush_command = support_binaries.FindPath('clear_system_cache',
21                                               self.GetArchName(),
22                                               self.GetOSName())
23     assert flush_command, 'You must build clear_system_cache first'
24
25     args = []
26     directory_contents = os.listdir(directory)
27     for item in directory_contents:
28       if not ignoring or item not in ignoring:
29         args.append(os.path.join(directory, item))
30
31     # According to msdn:
32     # http://msdn.microsoft.com/en-us/library/ms682425%28VS.85%29.aspx
33     # there's a maximum allowable command line of 32,768 characters on windows.
34     while args:
35       # Small note about [:256] and [256:]
36       # [:N] will return a list with the first N elements, ie.
37       # with [1,2,3,4,5], [:2] -> [1,2], and [2:] -> [3,4,5]
38       # with [1,2,3,4,5], [:5] -> [1,2,3,4,5] and [5:] -> []
39       subprocess.check_call([flush_command, '--recurse'] + args[:256])
40       args = args[256:]