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 5import os 6import subprocess 7 8from telemetry.core.platform import platform_backend 9from telemetry.util import support_binaries 10 11 12class 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.GetOSName()) 22 assert flush_command, 'You must build clear_system_cache first' 23 24 args = [] 25 directory_contents = os.listdir(directory) 26 for item in directory_contents: 27 if not ignoring or item not in ignoring: 28 args.append(os.path.join(directory, item)) 29 30 # According to msdn: 31 # http://msdn.microsoft.com/en-us/library/ms682425%28VS.85%29.aspx 32 # there's a maximum allowable command line of 32,768 characters on windows. 33 while args: 34 # Small note about [:256] and [256:] 35 # [:N] will return a list with the first N elements, ie. 36 # with [1,2,3,4,5], [:2] -> [1,2], and [2:] -> [3,4,5] 37 # with [1,2,3,4,5], [:5] -> [1,2,3,4,5] and [5:] -> [] 38 subprocess.check_call([flush_command, '--recurse'] + args[:256]) 39 args = args[256:] 40