(Hopefully) short-lived script to rework the directory structure from core /
playground / oneoffs to public / private. Currently implemented as an svn -> svn merge, but will have to be tweaked to do a proper svn -> git merge. git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@5964 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
parent
49b021d435
commit
fbb68ae94c
|
|
@ -0,0 +1,97 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import fnmatch,os,string,sys
|
||||||
|
|
||||||
|
def add_directory(dirname):
|
||||||
|
parent = os.path.dirname(dirname)
|
||||||
|
if not os.path.exists(parent) and parent != '':
|
||||||
|
add_directory(parent)
|
||||||
|
if not os.path.exists(dirname):
|
||||||
|
print 'creating directory',dirname
|
||||||
|
os.makedirs(dirname)
|
||||||
|
os.system('svn add %s'%dirname)
|
||||||
|
|
||||||
|
def remove_directory(dirname):
|
||||||
|
if os.path.exists(dirname):
|
||||||
|
print 'removing directory',dirname
|
||||||
|
os.system('svn rm %s'%dirname)
|
||||||
|
# os.system('rm -rf %s'%dirname)
|
||||||
|
|
||||||
|
def move_file(source_filename,target_filename):
|
||||||
|
print 'moving %s to %s' % (source_filename,target_filename)
|
||||||
|
os.system('svn mv %s %s'%(source_filename,target_filename))
|
||||||
|
# os.system('mv %s %s'%(source_filename,target_filename))
|
||||||
|
|
||||||
|
target_public = 'public'
|
||||||
|
target_private = 'private'
|
||||||
|
|
||||||
|
base_excludes = ['.svn','archive','tribble','integrationtests','settings',target_public,target_private]
|
||||||
|
private_paths = ['playground','oneoffprojects','oneoffs','archive','analysis','alignment','bwa','c','lua','matlab','perl','python','ruby','R','shell']
|
||||||
|
paths_to_trim = ['playground','oneoffprojects','oneoffs']
|
||||||
|
source_extensions = ['*.java','*.scala']
|
||||||
|
|
||||||
|
def intersect(a,b):
|
||||||
|
return list(set(a) & set(b))
|
||||||
|
|
||||||
|
def is_source_file(file):
|
||||||
|
for source_extension in source_extensions:
|
||||||
|
if fnmatch.fnmatch(file,source_extension):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def modify_path(path):
|
||||||
|
tokens = path.split('/')
|
||||||
|
# compute proper target path: public or private?
|
||||||
|
if(intersect(tokens,private_paths)):
|
||||||
|
# kill private directory indicator only if private directory indicator is not the first element in the path.
|
||||||
|
modified_tokens = [token for token in tokens if token not in paths_to_trim]
|
||||||
|
return string.join(modified_tokens,'/').replace('./',target_private+'/')
|
||||||
|
else:
|
||||||
|
return path.replace('./',target_public+'/')
|
||||||
|
|
||||||
|
add_directory(target_public)
|
||||||
|
add_directory(target_private)
|
||||||
|
|
||||||
|
# just move archive wholesale; don't worry about processing at this point.
|
||||||
|
move_file('archive',target_private)
|
||||||
|
|
||||||
|
for root,dirs,files in os.walk('.'):
|
||||||
|
# filter out non-processed files from root directory and base_excludes
|
||||||
|
tokens = string.split(root,'/')
|
||||||
|
if len(tokens) == 1:
|
||||||
|
continue
|
||||||
|
if len(intersect(tokens,base_excludes)) > 0:
|
||||||
|
continue
|
||||||
|
|
||||||
|
# handle file move
|
||||||
|
for file in ["%s/%s"%(root,file) for file in files]:
|
||||||
|
modified_path = modify_path(file)
|
||||||
|
dirname = os.path.dirname(modified_path)
|
||||||
|
add_directory(dirname)
|
||||||
|
move_file(file,dirname)
|
||||||
|
|
||||||
|
# handle source code modification
|
||||||
|
for root,dirs,files in os.walk('.'):
|
||||||
|
# process only public and private directories
|
||||||
|
if not (root.startswith('./'+target_public) or root.startswith('./'+target_private)):
|
||||||
|
continue
|
||||||
|
for file in ["%s/%s"%(root,file) for file in files if is_source_file(file)]:
|
||||||
|
f = open(file,'r')
|
||||||
|
lines = f.readlines()
|
||||||
|
for i in range(len(lines)):
|
||||||
|
line = lines[i]
|
||||||
|
if line.startswith('package') or line.startswith('import'):
|
||||||
|
tokens = line.split('.')
|
||||||
|
if intersect(tokens,private_paths):
|
||||||
|
tokens = [token for token in tokens if token not in paths_to_trim]
|
||||||
|
modified_line = string.join(tokens,'.')
|
||||||
|
print "%s: '%s' => '%s'" % (file,line.rstrip(),modified_line.rstrip())
|
||||||
|
lines[i] = modified_line
|
||||||
|
f.close()
|
||||||
|
f = open(file,'w')
|
||||||
|
f.writelines(lines)
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
for file in os.listdir('.'):
|
||||||
|
if os.path.isdir(file) and not file in base_excludes and not file.startswith(target_public) and not file.startswith(target_private):
|
||||||
|
remove_directory(file)
|
||||||
Loading…
Reference in New Issue