Created
December 14, 2011 01:58
-
-
Save thewtex/1474883 to your computer and use it in GitHub Desktop.
itk registration name refactoring rename files and modules
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import csv | |
import os | |
import sys | |
import subprocess | |
if len(sys.argv) < 2: | |
print('input class name CSV file') | |
sys.exit(1) | |
class_name_csv_file = sys.argv[1] | |
class_names = csv.reader( open(class_name_csv_file, 'r') ) | |
old_new_names = [] | |
for row in class_names: | |
old_new_names.append(row) | |
cwd = os.getcwd() | |
cwd_len = len(cwd) + 1 | |
for root, dirs, filenames in os.walk(cwd): | |
for filename in filenames: | |
for old, new in old_new_names: | |
if filename.find(old) > -1: | |
old_name = os.path.join(root, filename)[cwd_len:] | |
new_name = os.path.join(root, filename.replace(old,new))[cwd_len:] | |
if old_name.find('.git') == -1 and os.path.exists(old_name): | |
call = ['git', 'mv', old_name, new_name] | |
subprocess.check_call(call) | |
call = ['git', 'mv', 'Modules/Registration/HighDimensionalMetrics/', 'Modules/Registration/Metricsv4/'] | |
subprocess.check_call(call) | |
call = ['git', 'mv', 'Modules/Registration/HighDimensionalRegistrationMethods/', 'Modules/Registration/RegistrationMethodsv4/'] | |
subprocess.check_call(call) | |
call = ['git', 'mv', 'Modules/Numerics/HighDimensionalOptimizers/', 'Modules/Numerics/Optimizersv4/'] | |
subprocess.check_call(call) | |
call = ['git', 'commit', '-a', '-m', 'ENH: Registration name refactoring Part 1/2'] | |
subprocess.check_call(call) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment