-
-
Save markito/495514 to your computer and use it in GitHub Desktop.
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
projects = {'ProjectA' : {'deps' : ['ProjectB']}, | |
'ProjectB' : {'deps' : None}, | |
'ProjectC' : {'deps' : ['ProjectA']}} | |
cont = 0 | |
def deploy(name, desc): | |
""" | |
Detects the order of deploy for projects in a dict. | |
Each dic entry is the name of Projet : {desc}, where desc is a dict containing: | |
deps : Name of projects it depends on. | |
description: optional description | |
""" | |
global cont | |
if 'deployed' in desc: | |
return | |
if not desc['deps']: | |
cont += 1 | |
desc['deployed'] = cont | |
else: | |
for dep in desc['deps']: | |
if projects[dep]['deps'] and name in projects[dep]['deps']: | |
raise Exception('Cyclic reference between %s to %s' % (name, dep)) | |
deploy(dep, projects[dep]) | |
cont += 1 | |
desc['deployed'] = cont | |
if __name__ == '__main__': | |
for k,v in projects.iteritems(): | |
deploy(k,v) | |
print 'The deploy order is: ', sorted(projects.keys(), key = lambda k: projects[k]['deployed']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment