diff options
author | Lars Wirzenius <liw@liw.fi> | 2012-12-16 16:33:29 +0000 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2012-12-16 16:33:29 +0000 |
commit | bb4ee091a0211a4c96f255f7ead1beb64701d9f8 (patch) | |
tree | 1db1a860d0e4aef0bc7feae83a79ce35ca5b6df6 /jenkinstool | |
parent | b12351e281963c6d186c354502654840b323991e (diff) | |
download | jenkinstool-bb4ee091a0211a4c96f255f7ead1beb64701d9f8.tar.gz |
Add a subcommand graph-projects
Diffstat (limited to 'jenkinstool')
-rwxr-xr-x | jenkinstool | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/jenkinstool b/jenkinstool index 014c6a5..728bddc 100755 --- a/jenkinstool +++ b/jenkinstool @@ -774,6 +774,44 @@ class JenkinsTool(cliapp.Application): jenkins = simplejenkinsapi.Jenkins(self.jenkins_url) jenkins.update_job(job_id, f.read()) + def cmd_graph_projects(self, args): + '''Output a graphviz file showing project dependencies.''' + + def find(config, name): + for project in config['projects']: + if project['name'] == name: + return project + return None + + def write_graphviz(f, config, project_names): + done = set() + f.write('strict digraph foo {\n') + while project_names: + name = project_names.pop() + if name not in done: + done.add(name) + project = find(config, name) + if project: + for dep in project.get('build-depends', []): + f.write('"%s" -> "%s";\n' % (name, dep)) + project_names.append(dep) + + f.write('}\n') + + if len(args) == 0: + return + + filename = args[0] + with open(filename) as f: + config = json.load(f) + + if len(args) > 1: + project_names = args[1:] + else: + project_names = [p['name'] for p in config['projects']] + + write_graphviz(self.output, config, project_names) + def cmd_run_jobs(self, args): '''Update Jenkmins with jobs based specification, then run them.''' |