From 110bb4ce40f22a587dc54bdd13d52df0938c6f3f Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 22 Sep 2012 00:18:22 +0100 Subject: Add way to sort projects into linear order by dependency --- simplejenkinsapi/order.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 simplejenkinsapi/order.py (limited to 'simplejenkinsapi') diff --git a/simplejenkinsapi/order.py b/simplejenkinsapi/order.py new file mode 100644 index 0000000..9973977 --- /dev/null +++ b/simplejenkinsapi/order.py @@ -0,0 +1,40 @@ +# order.py -- order projects in dependency order +# +# Copyright 2012 Lars Wirzenius +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + + +def order(projects): + by_name = {} + for project in projects: + by_name[project['name']] = project + + for project in projects: + project['_'] = [by_name[dep['name']] + for dep in project.get('build-depends, [])] + + linear = [] + for project in projects: + linear.extend(project['_']) + linear.append(project) + + result = [] + while linear: + project = linear.pop(0) + if project not in linear: + result.append(project) + + return result + -- cgit v1.2.1