summaryrefslogtreecommitdiff
path: root/simplejenkinsapi
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2012-09-22 00:18:22 +0100
committerLars Wirzenius <liw@liw.fi>2012-09-22 00:18:22 +0100
commit110bb4ce40f22a587dc54bdd13d52df0938c6f3f (patch)
treee638641fe7f7184a42623824c00c787ed0d58fb9 /simplejenkinsapi
parent7839cc0e24bcacf44a0090da05a81cf01f9ba108 (diff)
downloadjenkinstool-110bb4ce40f22a587dc54bdd13d52df0938c6f3f.tar.gz
Add way to sort projects into linear order by dependency
Diffstat (limited to 'simplejenkinsapi')
-rw-r--r--simplejenkinsapi/order.py40
1 files changed, 40 insertions, 0 deletions
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 <http://www.gnu.org/licenses/>.
+
+
+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
+