#!/usr/bin/env python
# Copyright 2015 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.

"""Script that deletes all files (but not directories) in a given directory."""

import os
import sys


def main(args):
  if not args or len(args) != 1:
    print >> sys.stderr, 'Please specify a single directory as an argument.'
    return 1

  clean_dir = args[0]
  if not os.path.isdir(clean_dir):
    print >> sys.stderr, '%s does not exist or is not a directory!' % clean_dir
    return 2

  for filename in os.listdir(clean_dir):
    file_path = os.path.join(clean_dir, filename)
    if os.path.isfile(file_path):
      try:
        os.remove(file_path)
        print 'Removed %s' % file_path
      except OSError as e:
        # Don't fail if we cannot delete a file.
        print e
  return 0


if __name__ == '__main__':
  sys.exit(main(sys.argv[1:]))

#!/usr/bin/env python
# Copyright 2015 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.

"""Script that deletes all files (but not directories) in a given directory."""

import os
import sys


def main(args):
  if not args or len(args) != 1:
    print >> sys.stderr, 'Please specify a single directory as an argument.'
    return 1

  clean_dir = args[0]
  if not os.path.isdir(clean_dir):
    print 'Cannot find any directory at %s. Skipping cleaning.' % clean_dir
    return 0

  for filename in os.listdir(clean_dir):
    file_path = os.path.join(clean_dir, filename)
    if os.path.isfile(file_path):
      try:
        os.remove(file_path)
        print 'Removed %s' % file_path
      except OSError as e:
        # Don't fail if we cannot delete a file.
        print e
  return 0


if __name__ == '__main__':
  sys.exit(main(sys.argv[1:]))

Make clean script return successful if clean dir is missing.
WebRTC: Make clean script return successful if clean dir is missing.

I thought it would be good to have the script fail for an
incorrectly specified directory, but the out/ dir is missing
on fresh installed slave machines, so better just skip cleaning
with a line printed to stdout instead when the dir is missing.

TESTED=Ran the script locally with an invalid dir argument.

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

git-svn-id: 239fca9b83025a0b6f823aeeca02ba5be3d9fd76@294057 0039d316-1c4b-4281-b951-d872f2087c98
