Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(40)

Unified Diff: tools/cr/cr/commands/clobber.py

Issue 703533003: Add cr clobber command. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update for review feedback Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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'
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698