1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
use crate::{Builder, Scheduler, Worker}; use rusty_yaml::Yaml; use std::fmt::{Display, Error, Formatter}; pub struct MasterConfig { title: String, title_url: String, git_repo: String, webserver_ip: String, poll_interval: String, builders: Vec<Builder>, schedulers: Vec<Scheduler>, workers: Vec<Worker>, } impl MasterConfig { fn new( title: String, title_url: String, git_repo: String, webserver_ip: String, poll_interval: String, builders: Vec<Builder>, schedulers: Vec<Scheduler>, workers: Vec<Worker>, ) -> Self { Self { title, title_url, git_repo, webserver_ip, poll_interval, builders, schedulers, workers, } } } impl From<Yaml> for MasterConfig { fn from(yaml: Yaml) -> Self { for section in ["master", "workers", "builders", "schedulers"].iter() { assert!( yaml.has_section(section), format!("{} section not declared", section) ) } for section in [ "title", "title-url", "repo", "webserver-ip", "poll-interval", ] .iter() { assert!( yaml.get_section("master").has_section(section), format!("{} section not specified for master", section) ) } let mut schedulers = vec![]; for scheduler in yaml.get_section("schedulers") { schedulers.push(Scheduler::from(scheduler)); } let mut builders = vec![]; for builder in yaml.get_section("builders") { builders.push(Builder::from(builder)); } let mut workers = vec![]; for worker in yaml.get_section("workers") { workers.push(Worker::from(worker)); } let title: String = yaml .get_section("master") .get_section("title") .into_iter() .collect::<Vec<Yaml>>()[0] .to_string(); let title_url: String = yaml .get_section("master") .get_section("title-url") .into_iter() .collect::<Vec<Yaml>>()[0] .to_string(); let git_repo: String = yaml .get_section("master") .get_section("repo") .into_iter() .collect::<Vec<Yaml>>()[0] .to_string(); let webserver_ip: String = yaml .get_section("master") .get_section("webserver-ip") .into_iter() .collect::<Vec<Yaml>>()[0] .to_string(); let poll_interval: String = yaml .get_section("master") .get_section("poll-interval") .into_iter() .collect::<Vec<Yaml>>()[0] .to_string(); Self::new( title, title_url, git_repo, webserver_ip, poll_interval, builders, schedulers, workers, ) } } impl Display for MasterConfig { fn fmt(&self, f: &mut Formatter) -> Result<(), Error> { write!( f, r#" # -*- python -*- # ex: set filetype=python: import re from buildbot.plugins import * # This is a sample buildmaster config file. It must be installed as # 'master.cfg' in your buildmaster's base directory. # This is the dictionary that the buildmaster pays attention to. We also use # a shorter alias to save typing. c = BuildmasterConfig = {{}} ####### WORKERS # The 'workers' list defines the set of recognized workers. Each element is # a Worker object, specifying a unique worker name and password. The same # worker name and password must be configured on the worker. c['workers'] = [{worker_info}] c['protocols'] = {{'pb': {{'port': 9989}}}} c['change_source'] = [] c['change_source'].append(changes.GitPoller( {git_repo}, workdir='gitpoller-workdir', branches=True, # poll all branches pollInterval={poll_interval})) c['schedulers'] = [] c['builders'] = [] {schedulers} {builders} c['services'] = [] c['title'] = "{title}" c['titleURL'] = {title_url} c['buildbotURL'] = "http://{webserver_ip}:8010/" c['www'] = dict(port=8010, plugins=dict(waterfall_view={{}}, console_view={{}}, grid_view={{}})) c['db'] = {{ # This specifies what database buildbot uses to store its state. You can leave # this at its default for all but the largest installations. 'db_url' : "sqlite:///state.sqlite", }} "#, title = self.title, title_url = self.title_url, webserver_ip = self.webserver_ip, git_repo = self.git_repo, worker_info = self .workers .iter() .map(|w| { format!( "worker.Worker(\"{}\", \"{}\")", w.get_name(), w.get_password() ) }) .collect::<Vec<String>>() .join(", "), poll_interval = self.poll_interval, schedulers = self .schedulers .iter() .map(|s| s.to_string()) .collect::<Vec<String>>() .join("\n\n"), builders = self .builders .iter() .map(|b| b.to_string()) .collect::<Vec<String>>() .join("\n\n"), ) } }