summaryrefslogtreecommitdiff
path: root/scripts/migrate-chunks
diff options
context:
space:
mode:
authorFrancisco Redondo Marchena <francisco.marchena@codethink.co.uk>2014-08-13 13:03:26 +0000
committerFrancisco Redondo Marchena <francisco.marchena@codethink.co.uk>2014-08-13 13:03:26 +0000
commitf7aa084baee522091608b2bfabf9930aab225057 (patch)
tree0f3b70df048d5f92a9adb5fa12889e42c738bd73 /scripts/migrate-chunks
parent82e3132d12e3accaed18704c4984a71fc7dfce44 (diff)
downloaddefinitions-f7aa084baee522091608b2bfabf9930aab225057.tar.gz
Add move_file function and reorder the script
Diffstat (limited to 'scripts/migrate-chunks')
-rwxr-xr-xscripts/migrate-chunks48
1 files changed, 24 insertions, 24 deletions
diff --git a/scripts/migrate-chunks b/scripts/migrate-chunks
index fb33f8ad..72ae3555 100755
--- a/scripts/migrate-chunks
+++ b/scripts/migrate-chunks
@@ -11,20 +11,6 @@ import urlparse
import yaml
import re
-# Load all morphologies in the definitions repo
-sb = morphlib.sysbranchdir.open_from_within('.')
-loader = morphlib.morphloader.MorphologyLoader()
-morphs = [m for m in sb.load_all_morphologies(loader)]
-print 'Found %d morphologies in total' % len(morphs)
-
-
-# Clasify the morphologies regarding of their kind field
-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)
-
# NOTE: The following reimplements part of morphlib's remote repo cache stuff
def parse_repo_alias(repo):
domain, path = repo.split(':')
@@ -92,6 +78,15 @@ def create_directory(name, path):
subprocess.call(['mkdir','-p', directory])
return directory
+def move_file(morph, directory, path):
+ if not morph.filename.startswith(directory):
+ filename = morph.filename.split('/')[-1]
+ new_location = os.path.join(path, filename)
+ print 'Moving %s into %s' % (filename, new_location)
+ subprocess.call(['git', 'mv', morph.filename, new_location])
+ morph.filename = new_location
+ loader.save_to_file(morph.filename, morph)
+
def move_morphologies(morphs, kind, directory, path):
# Dictionary which match morphology's kind and morphology's
# directory in definitions.git
@@ -101,11 +96,7 @@ def move_morphologies(morphs, kind, directory, path):
for morph in morphs:
for submorph in morph[morph_dir[kind]]:
submorph['morph'] = sanitise_morphology_path(submorph['morph'], kind)
- print 'Moving %s into %s' % (morph.filename, directory)
- loader.save_to_file(morph.filename, morph)
- new_location = os.path.join(subdir, morph.filename)
- subprocess.call(['git', 'mv', morph.filename, new_location])
- morph.filename = new_location
+ move_file(morph, directory, subdir)
def move_clusters(morphs):
kind = 'system'
@@ -172,7 +163,6 @@ def download_chunks(morph):
loader.save_to_file(chunk['morph'], new_chunk)
print "Downloading %s from %s into %s" %(name, repo, chunk['morph'])
-
def move_strata(morphs):
for morph in morphs:
# Add chunk path on the chunk's morph field per stratum
@@ -185,10 +175,20 @@ def move_strata(morphs):
# Add path to the build-depends morphologies
for build_depends in morph['build-depends']:
build_depends['morph'] = sanitise_morphology_path(build_depends['morph'], 'stratum')
- loader.save_to_file(morph.filename,morph)
- new_location = os.path.join(subdir, morph.filename)
- subprocess.call(['git', 'mv', morph.filename, new_location])
- morph.filename = new_location
+ move_file(morph, 'strata/', subdir)
+
+# Load all morphologies in the definitions repo
+sb = morphlib.sysbranchdir.open_from_within('.')
+loader = morphlib.morphloader.MorphologyLoader()
+morphs = [m for m in sb.load_all_morphologies(loader)]
+
+
+# Clasify the morphologies regarding of their kind field
+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)
# Get the path from definitions repo
definitions_repo = sb.get_git_directory_name(sb.root_repository_url)