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

Unified Diff: tools/tests/factory_configuration/rename_builders.py

Issue 14517004: Change Builder Names, MkIII (Closed) Base URL: http://skia.googlecode.com/svn/buildbot/
Patch Set: Created 7 years, 8 months 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
Index: tools/tests/factory_configuration/rename_builders.py
===================================================================
--- tools/tests/factory_configuration/rename_builders.py (revision 0)
+++ tools/tests/factory_configuration/rename_builders.py (revision 0)
@@ -0,0 +1,104 @@
+# Copyright (c) 2013 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.
+
+""" Changes builder names in the expected factory configurations. """
+
+
+import os
+import json
+import re
+import subprocess
+import sys
+
+
+EXPECTED_DIR = os.path.join(os.path.dirname(__file__), 'expected')
+if os.name == 'nt':
+ SVN = 'svn.bat'
+else:
+ SVN = 'svn'
+
+
+def CheckName(builder_name):
+ if not re.match('^[\w\-_\.]+$', builder_name):
+ raise ValueError('"%s" is not a valid builder name.' % builder_name)
+
+
+def ExistingBuilders():
+ builders = os.listdir(EXPECTED_DIR)
+ builders.sort()
+ for builder_file in builders:
+ if not builder_file.startswith('.'):
+ yield builder_file
+
+
+def CreateMappingTemplate(mapping_file):
+ mapping = {}
+ for builder_file in ExistingBuilders():
+ mapping[builder_file] = ''
+ with open(mapping_file, 'w') as f:
+ json.dump(mapping, f, indent=4, sort_keys=True)
+ print 'Created mapping template file in %s' % mapping_file
+
+
+def Rename(old_name, new_name):
+ print 'Changing "%s" to "%s".' % (old_name, new_name)
+ old_file_path = os.path.join(EXPECTED_DIR, old_name)
+ new_file_path = os.path.join(EXPECTED_DIR, new_name)
+
+ # Verify the new file names.
+ CheckName(old_name)
+ CheckName(new_name)
+ if not os.path.isfile(old_file_path):
+ raise Exception('Config file for "%s" does not exist!' % old_file_path)
+ if os.path.isfile(new_file_path):
+ raise Exception('Config file for "%s" already exists!' % new_file_path)
+
+ # Read the old builder configuration.
+ with open(old_file_path) as old_file:
+ old_file_contents = old_file.read()
+
+ # Use "svn mv" to create the new file so that the diff only shows the changes.
+ subprocess.call([SVN, 'mv', old_file_path, new_file_path])
+
+ # Replace any instances of old_name with new_name in file_contents.
+ new_file_contents = old_file_contents.replace(old_name, new_name)
+
+ # Write the new builder configuration.
+ with open(new_file_path, 'w') as new_file:
+ new_file.write(new_file_contents)
+
+
+def main(argv):
+ if len(argv) > 1:
+ if argv[1] == '--create-mapping-template':
+ if len(argv) == 3:
+ mapping_file = argv[2]
+ elif len(argv) == 2:
+ mapping_file = 'mapping.json'
+ else:
+ raise Exception('')
+ CreateMappingTemplate(mapping_file)
+ return
+ else:
+ with open(argv[1]) as f:
+ mapping = json.load(f)
+ for builder_file in ExistingBuilders():
+ if not builder_file in mapping:
+ raise Exception('Your mapping file contains no mapping for "%s"' % \
+ builder_file)
+ else:
+ print ('No mapping file provided. Next time you can provide a '
+ 'JSON-formatted file which maps old names to new names.')
+ mapping = {}
+ for builder_file in ExistingBuilders():
+ new_name = raw_input('New name for %s: ' % builder_file)
+ mapping[builder_file] = new_name
+ break
+
+ for old_name, new_name in mapping.iteritems():
+ Rename(old_name, new_name)
+
+
+if '__main__' == __name__:
+ sys.exit(main(sys.argv))

Powered by Google App Engine
This is Rietveld 408576698