| Index: tools/cr/cr/commands/clobber.py
|
| diff --git a/tools/cr/cr/commands/clobber.py b/tools/cr/cr/commands/clobber.py
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..1e642a643165653dc3667d2bd6f3484d13da1da0
|
| --- /dev/null
|
| +++ b/tools/cr/cr/commands/clobber.py
|
| @@ -0,0 +1,50 @@
|
| +# 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.
|
| +
|
| +"""A module for the clobber command."""
|
| +
|
| +import os
|
| +import shutil
|
| +
|
| +import cr
|
| +
|
| +
|
| +class ClobberCommand(cr.Command):
|
| + """The implementation of the clobber command.
|
| +
|
| + The clobber command removes all generated files from the output directory.
|
| + """
|
| +
|
| + def __init__(self):
|
| + super(ClobberCommand, self).__init__()
|
| + self.help = 'Clobber the current output directory'
|
| + self.description = ("""
|
| + This deletes all generated files from the output directory.
|
| + """)
|
| +
|
| + def Run(self):
|
| + self.Clobber()
|
| +
|
| + @classmethod
|
| + def Clobber(cls):
|
| + """Performs the clobber."""
|
| + build_dir = cr.context.Get('CR_BUILD_DIR')
|
| + verbose = cr.context.verbose >= 3 or cr.context.dry_run
|
| + delete = not cr.context.dry_run
|
| + print 'Clobbering...'
|
| + for f in os.listdir(build_dir):
|
| + if f == cr.base.client.CLIENT_CONFIG_PATH:
|
| + continue
|
| + path = os.path.join(build_dir, f)
|
| + if os.path.isfile(path):
|
| + if verbose:
|
| + print 'Delete file %s' % path
|
| + if delete:
|
| + os.unlink(path)
|
| + elif os.path.isdir(path):
|
| + if verbose:
|
| + print 'Delete folder %s' % path
|
| + if delete:
|
| + shutil.rmtree(path)
|
| + print 'Done'
|
|
|