From 756834554c563b74154f57b23f354bbc0e8569f3 Mon Sep 17 00:00:00 2001 From: Francisco Redondo Marchena Date: Fri, 1 Aug 2014 17:17:58 +0000 Subject: WIP: Play with migrate-chunks --- scripts/migrate-chunks | 45 +++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/scripts/migrate-chunks b/scripts/migrate-chunks index 2e7ebc0d..08899e1a 100755 --- a/scripts/migrate-chunks +++ b/scripts/migrate-chunks @@ -20,15 +20,13 @@ loader = morphlib.morphloader.MorphologyLoader() morphs = [m for m in sb.load_all_morphologies(loader)] print 'Found %d morphologies in total' % len(morphs) -# separate the morphologies by type -chunks = [m for m in morphs if m['kind'] == 'chunk'] -print 'There are: %d chunks' % len(chunks) -strata = [m for m in morphs if m['kind'] == 'stratum'] -print ' %d strata' % len(strata) -systems = [m for m in morphs if m['kind'] == 'system'] -print ' %d systems' % len(systems) -clusters = [m for m in morphs if m['kind'] == 'cluster'] -print ' %d clusters' % len(clusters) + +# Harvest all the morphologies on the directory +morphologies = { 'chunk': '', 'stratum': '', 'system' : '', 'cluster': '' } + +for key in morphologies.iterkeys(): + morphologies[key] = [m for m in morphs if m['kind'] == key] + print 'There are: %d %s' %(len(morphologies[key]), key) # organise the definitions repo definitions_repo = sb.get_git_directory_name(sb.root_repository_url) @@ -37,16 +35,23 @@ def move_morphs(morphs, kind): subdir = os.path.join(definitions_repo, kind) subprocess.call(['mkdir', subdir]) for morph in morphs: - new_location = os.path.join(subdir, morph.filename) - subprocess.call(['git', 'mv', morph.filename, new_location]) - morph.filename = new_location - subprocess.call(['git', 'commit', '--quiet', '-m', - 'Move %s into subdirectory' % kind]) - -move_morphs(chunks, 'chunks') -move_morphs(strata, 'strata') + new_location = os.path.join(subdir, morph.filename.replace('-' + kind,'',1)) + print '%s' % new_location + #subprocess.call(['git', 'mv', morph.filename, new_location]) + #morph.filename = new_location + #subprocess.call(['git', 'commit', '--quiet', '-m', + # 'Move %s into subdirectory' % kind]m + +for key in morphologies.iterkeys(): + if key in ['cluster', 'system']: + move_morphs(morphologies[key], key) + +sys.exit(0) +#move_morphs(chunks, 'chunks') +#move_morphs(strata, 'strata') move_morphs(systems, 'systems') -move_morphs(clusters, 'clusters') +#move_morphs(clusters, 'clusters') +sys.exit(0) # get a list of ALL the chunks chunk_map = {} @@ -116,8 +121,8 @@ for chunk in new_chunks: morph = morphlib.util.sanitise_morphology_path(chunk) path = os.path.join(definitions_repo, os.path.join('chunks', morph)) subprocess.call(['mv', morph, path]) - subprocess.call(['git', 'add', path]) -subprocess.call(['git', 'commit', '-m', 'Add chunk morphologies']) + #subprocess.call(['git', 'add', path]) +#subprocess.call(['git', 'commit', '-m', 'Add chunk morphologies']) # update the chunk specs in the strata for stratum in strata: -- cgit v1.2.1