annotate rust/src/main.rs @ 623:03167105f6de rust

ignore missing local.conf
author Matt Johnston <matt@ucc.asn.au>
date Sun, 16 Apr 2017 22:50:20 +0800
parents 8fda564cc46f
children 2710649ab71e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
588
038734052b20 fiddling with futures-rs instead
Matt Johnston <matt@ucc.asn.au>
parents: 587
diff changeset
1 extern crate tokio_core;
038734052b20 fiddling with futures-rs instead
Matt Johnston <matt@ucc.asn.au>
parents: 587
diff changeset
2 extern crate futures;
594
aff50ee77252 rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents: 593
diff changeset
3 #[macro_use]
aff50ee77252 rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents: 593
diff changeset
4 extern crate log;
aff50ee77252 rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents: 593
diff changeset
5 extern crate env_logger;
597
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
6 extern crate rustc_serialize;
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
7 extern crate time;
609
7bda01659426 not building, paramwaiter work
Matt Johnston <matt@ucc.asn.au>
parents: 607
diff changeset
8 extern crate tokio_curl;
7bda01659426 not building, paramwaiter work
Matt Johnston <matt@ucc.asn.au>
parents: 607
diff changeset
9 extern crate curl;
611
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
10 extern crate serde_json;
623
03167105f6de ignore missing local.conf
Matt Johnston <matt@ucc.asn.au>
parents: 620
diff changeset
11 extern crate libc;
594
aff50ee77252 rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents: 593
diff changeset
12
604
278f1002b5c7 sensor regex, custom error type
Matt Johnston <matt@ucc.asn.au>
parents: 603
diff changeset
13 #[macro_use]
278f1002b5c7 sensor regex, custom error type
Matt Johnston <matt@ucc.asn.au>
parents: 603
diff changeset
14 extern crate lazy_static;
278f1002b5c7 sensor regex, custom error type
Matt Johnston <matt@ucc.asn.au>
parents: 603
diff changeset
15
595
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents: 594
diff changeset
16 #[macro_use]
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents: 594
diff changeset
17 extern crate serde_derive;
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents: 594
diff changeset
18 extern crate serde;
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents: 594
diff changeset
19
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents: 594
diff changeset
20 extern crate toml;
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents: 594
diff changeset
21
597
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
22 extern crate docopt;
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
23
594
aff50ee77252 rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents: 593
diff changeset
24 use std::io;
588
038734052b20 fiddling with futures-rs instead
Matt Johnston <matt@ucc.asn.au>
parents: 587
diff changeset
25
038734052b20 fiddling with futures-rs instead
Matt Johnston <matt@ucc.asn.au>
parents: 587
diff changeset
26 use tokio_core::reactor::Core;
594
aff50ee77252 rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents: 593
diff changeset
27 use futures::{Stream,Sink,Future};
aff50ee77252 rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents: 593
diff changeset
28 use futures::sync::{mpsc};
aff50ee77252 rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents: 593
diff changeset
29 use sensor::Sensor;
589
f2508125adf1 Try using traits for periodic stream
Matt Johnston <matt@ucc.asn.au>
parents: 588
diff changeset
30
595
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents: 594
diff changeset
31 mod config;
590
dccd8504aa38 it runs
Matt Johnston <matt@ucc.asn.au>
parents: 589
diff changeset
32 mod sensor;
609
7bda01659426 not building, paramwaiter work
Matt Johnston <matt@ucc.asn.au>
parents: 607
diff changeset
33 mod fridge;
592
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents: 591
diff changeset
34 mod types;
615
f153aec221be move Params, epoch code
Matt Johnston <matt@ucc.asn.au>
parents: 614
diff changeset
35 mod params;
591
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
36
592
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents: 591
diff changeset
37 use types::*;
597
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
38 use config::Config;
588
038734052b20 fiddling with futures-rs instead
Matt Johnston <matt@ucc.asn.au>
parents: 587
diff changeset
39
603
b45b8b4cf0f5 get rid of lazy_static, config is passed around
Matt Johnston <matt@ucc.asn.au>
parents: 601
diff changeset
40 fn run(config: &Config, nowait: bool, testmode: bool) {
595
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents: 594
diff changeset
41
588
038734052b20 fiddling with futures-rs instead
Matt Johnston <matt@ucc.asn.au>
parents: 587
diff changeset
42 let mut core = Core::new().unwrap();
038734052b20 fiddling with futures-rs instead
Matt Johnston <matt@ucc.asn.au>
parents: 587
diff changeset
43 let handle = core.handle();
587
646f03870762 trying rust
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
44
615
f153aec221be move Params, epoch code
Matt Johnston <matt@ucc.asn.au>
parents: 614
diff changeset
45 let params = params::Params::load(&config);
f153aec221be move Params, epoch code
Matt Johnston <matt@ucc.asn.au>
parents: 614
diff changeset
46 let mut fridge = fridge::Fridge::new(&config, nowait, params, &handle);
594
aff50ee77252 rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents: 593
diff changeset
47
597
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
48 let sensor_stream = if testmode {
603
b45b8b4cf0f5 get rid of lazy_static, config is passed around
Matt Johnston <matt@ucc.asn.au>
parents: 601
diff changeset
49 sensor::TestSensor::new(config).stream(&handle)
594
aff50ee77252 rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents: 593
diff changeset
50 } else {
603
b45b8b4cf0f5 get rid of lazy_static, config is passed around
Matt Johnston <matt@ucc.asn.au>
parents: 601
diff changeset
51 sensor::OneWireSensor::new(config).stream(&handle)
594
aff50ee77252 rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents: 593
diff changeset
52 };
aff50ee77252 rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents: 593
diff changeset
53
597
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
54 // Send the sensors of interest to the fridge (fridge_reading_s),
594
aff50ee77252 rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents: 593
diff changeset
55 // while streaming them all to the web sender.
620
8fda564cc46f fridge work
Matt Johnston <matt@ucc.asn.au>
parents: 616
diff changeset
56 let (fridge_reading_s, fridge_reading_r) = mpsc::channel(1);
8fda564cc46f fridge work
Matt Johnston <matt@ucc.asn.au>
parents: 616
diff changeset
57 let fridge_reading_r = fridge_reading_r.map_err(|e| TemplogError::new("Problem with fridge_reading_r channel"));
8fda564cc46f fridge work
Matt Johnston <matt@ucc.asn.au>
parents: 616
diff changeset
58 let sensor_stream = sensor_stream.map(|r| {
594
aff50ee77252 rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents: 593
diff changeset
59 debug!("sensors {:?}", r);
603
b45b8b4cf0f5 get rid of lazy_static, config is passed around
Matt Johnston <matt@ucc.asn.au>
parents: 601
diff changeset
60 let msg = fridge::Message::Sensor {
b45b8b4cf0f5 get rid of lazy_static, config is passed around
Matt Johnston <matt@ucc.asn.au>
parents: 601
diff changeset
61 wort: r.get_temp(&config.WORT_NAME),
b45b8b4cf0f5 get rid of lazy_static, config is passed around
Matt Johnston <matt@ucc.asn.au>
parents: 601
diff changeset
62 fridge: r.get_temp(&config.FRIDGE_NAME)
b45b8b4cf0f5 get rid of lazy_static, config is passed around
Matt Johnston <matt@ucc.asn.au>
parents: 601
diff changeset
63 };
b45b8b4cf0f5 get rid of lazy_static, config is passed around
Matt Johnston <matt@ucc.asn.au>
parents: 601
diff changeset
64 let t = fridge_reading_s.clone().send(msg)
594
aff50ee77252 rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents: 593
diff changeset
65 .map(|_| ())
595
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents: 594
diff changeset
66 .map_err(|e| {
597
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
67 warn!("Send error in fridge_reading_s: {}", e.to_string());
595
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents: 594
diff changeset
68 ()
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents: 594
diff changeset
69 });
594
aff50ee77252 rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents: 593
diff changeset
70 handle.spawn(t);
aff50ee77252 rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents: 593
diff changeset
71 r
588
038734052b20 fiddling with futures-rs instead
Matt Johnston <matt@ucc.asn.au>
parents: 587
diff changeset
72 });
587
646f03870762 trying rust
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
73
616
a85c0c9bc1fa hide epoch in ParamWaiter
Matt Johnston <matt@ucc.asn.au>
parents: 615
diff changeset
74 let param_stream = params::ParamWaiter::stream(config, &handle);
620
8fda564cc46f fridge work
Matt Johnston <matt@ucc.asn.au>
parents: 616
diff changeset
75 let param_stream = param_stream.map(|p| {
594
aff50ee77252 rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents: 593
diff changeset
76 fridge::Message::Params(p)
aff50ee77252 rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents: 593
diff changeset
77 });
aff50ee77252 rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents: 593
diff changeset
78
597
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
79 let timeouts = fridge.wakeups();
591
4a944663fa8d more skeleton
Matt Johnston <matt@ucc.asn.au>
parents: 590
diff changeset
80
620
8fda564cc46f fridge work
Matt Johnston <matt@ucc.asn.au>
parents: 616
diff changeset
81 // forward all the different types of messages to the fridge
8fda564cc46f fridge work
Matt Johnston <matt@ucc.asn.au>
parents: 616
diff changeset
82 let all_fridge = param_stream.select(timeouts).select(fridge_reading_r).forward(fridge) .map(|_| () );
592
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents: 591
diff changeset
83
620
8fda564cc46f fridge work
Matt Johnston <matt@ucc.asn.au>
parents: 616
diff changeset
84 let all_readings = sensor_stream.for_each(|_| Ok(()));
8fda564cc46f fridge work
Matt Johnston <matt@ucc.asn.au>
parents: 616
diff changeset
85
8fda564cc46f fridge work
Matt Johnston <matt@ucc.asn.au>
parents: 616
diff changeset
86 // run forever
594
aff50ee77252 rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents: 593
diff changeset
87 let all = all_fridge.select(all_readings);
aff50ee77252 rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents: 593
diff changeset
88 core.run(all).ok();
587
646f03870762 trying rust
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
89 }
646f03870762 trying rust
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
90
598
d4fbfb5c46ff broken update of versions of things
Matt Johnston <matt@ucc.asn.au>
parents: 597
diff changeset
91 const USAGE: &'static str = "\
597
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
92 Wort Temperature
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
93 Matt Johnston 2017 [email protected]
598
d4fbfb5c46ff broken update of versions of things
Matt Johnston <matt@ucc.asn.au>
parents: 597
diff changeset
94 Usage: wort-templog [--help] [--new] [--daemon] [--debug] [--test] [--defconf] [--thisconf] [--nowait]
597
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
95
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
96 Options:
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
97 -h, --help
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
98 --new Replace existing running instance
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
99 -D, --daemon Run in background
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
100 -d, --debug
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
101 -t, --test Use fake sensors etc
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
102 --nowait Skip initial fridge wait
615
f153aec221be move Params, epoch code
Matt Johnston <matt@ucc.asn.au>
parents: 614
diff changeset
103 --defconf Print default config (customise in local.conf)
597
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
104 --thisconf Print used config
598
d4fbfb5c46ff broken update of versions of things
Matt Johnston <matt@ucc.asn.au>
parents: 597
diff changeset
105 ";
d4fbfb5c46ff broken update of versions of things
Matt Johnston <matt@ucc.asn.au>
parents: 597
diff changeset
106
d4fbfb5c46ff broken update of versions of things
Matt Johnston <matt@ucc.asn.au>
parents: 597
diff changeset
107 #[derive(RustcDecodable)]
d4fbfb5c46ff broken update of versions of things
Matt Johnston <matt@ucc.asn.au>
parents: 597
diff changeset
108 struct Args {
599
f71cf1ad745f updated toml serde works OK
Matt Johnston <matt@ucc.asn.au>
parents: 598
diff changeset
109 flag_new: bool,
f71cf1ad745f updated toml serde works OK
Matt Johnston <matt@ucc.asn.au>
parents: 598
diff changeset
110 flag_daemon: bool,
f71cf1ad745f updated toml serde works OK
Matt Johnston <matt@ucc.asn.au>
parents: 598
diff changeset
111 flag_debug: bool,
f71cf1ad745f updated toml serde works OK
Matt Johnston <matt@ucc.asn.au>
parents: 598
diff changeset
112 flag_test: bool,
f71cf1ad745f updated toml serde works OK
Matt Johnston <matt@ucc.asn.au>
parents: 598
diff changeset
113 flag_defconf: bool,
f71cf1ad745f updated toml serde works OK
Matt Johnston <matt@ucc.asn.au>
parents: 598
diff changeset
114 flag_thisconf: bool,
f71cf1ad745f updated toml serde works OK
Matt Johnston <matt@ucc.asn.au>
parents: 598
diff changeset
115 flag_nowait: bool,
598
d4fbfb5c46ff broken update of versions of things
Matt Johnston <matt@ucc.asn.au>
parents: 597
diff changeset
116 }
597
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
117
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
118 fn setup_log(debug: bool) {
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
119 let loglevel = if debug {
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
120 log::LogLevelFilter::Debug
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
121 } else {
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
122 log::LogLevelFilter::Info
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
123 };
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
124
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
125 let format = |record: &log::LogRecord| {
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
126 let datefmt = "%Y-%m-%d %I:%M:%S %p";
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
127 let ts = time::strftime(datefmt, &time::now()).unwrap();
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
128 format!("{}: {} - {}", ts, record.level(), record.args())
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
129 };
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
130
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
131
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
132 let mut builder = env_logger::LogBuilder::new();
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
133 builder.format(format).filter(Some("wort_templog"), loglevel);
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
134 builder.init().unwrap();
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
135 }
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
136
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
137 fn handle_args() -> Args {
598
d4fbfb5c46ff broken update of versions of things
Matt Johnston <matt@ucc.asn.au>
parents: 597
diff changeset
138 let args: Args = docopt::Docopt::new(USAGE).and_then(|d| d.decode()).unwrap_or_else(|e| e.exit());
597
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
139
599
f71cf1ad745f updated toml serde works OK
Matt Johnston <matt@ucc.asn.au>
parents: 598
diff changeset
140 if args.flag_defconf {
597
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
141 println!("Default configuration:\n{}\n\n{}",
615
f153aec221be move Params, epoch code
Matt Johnston <matt@ucc.asn.au>
parents: 614
diff changeset
142 "(custom options go in local.conf)",
599
f71cf1ad745f updated toml serde works OK
Matt Johnston <matt@ucc.asn.au>
parents: 598
diff changeset
143 config::Config::default().to_toml_string());
597
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
144 std::process::exit(0);
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
145 }
599
f71cf1ad745f updated toml serde works OK
Matt Johnston <matt@ucc.asn.au>
parents: 598
diff changeset
146 args
597
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
147 }
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
148
601
8c21df3711e2 rigid_config
Matt Johnston <matt@ucc.asn.au>
parents: 599
diff changeset
149 fn load_config() -> Config {
603
b45b8b4cf0f5 get rid of lazy_static, config is passed around
Matt Johnston <matt@ucc.asn.au>
parents: 601
diff changeset
150 let nconfig = config::Config::default();
601
8c21df3711e2 rigid_config
Matt Johnston <matt@ucc.asn.au>
parents: 599
diff changeset
151
615
f153aec221be move Params, epoch code
Matt Johnston <matt@ucc.asn.au>
parents: 614
diff changeset
152 let conf_filename = "local.conf";
601
8c21df3711e2 rigid_config
Matt Johnston <matt@ucc.asn.au>
parents: 599
diff changeset
153 nconfig.merge_file(conf_filename)
8c21df3711e2 rigid_config
Matt Johnston <matt@ucc.asn.au>
parents: 599
diff changeset
154 .unwrap_or_else(|e| {
623
03167105f6de ignore missing local.conf
Matt Johnston <matt@ucc.asn.au>
parents: 620
diff changeset
155 if let TemplogErrorKind::Io(ref ioe) = *e.kind() {
03167105f6de ignore missing local.conf
Matt Johnston <matt@ucc.asn.au>
parents: 620
diff changeset
156 if let Some(errno) = ioe.raw_os_error() {
03167105f6de ignore missing local.conf
Matt Johnston <matt@ucc.asn.au>
parents: 620
diff changeset
157 if errno == libc::ENOENT {
03167105f6de ignore missing local.conf
Matt Johnston <matt@ucc.asn.au>
parents: 620
diff changeset
158 return nconfig;
03167105f6de ignore missing local.conf
Matt Johnston <matt@ucc.asn.au>
parents: 620
diff changeset
159 }
03167105f6de ignore missing local.conf
Matt Johnston <matt@ucc.asn.au>
parents: 620
diff changeset
160 }
03167105f6de ignore missing local.conf
Matt Johnston <matt@ucc.asn.au>
parents: 620
diff changeset
161 }
03167105f6de ignore missing local.conf
Matt Johnston <matt@ucc.asn.au>
parents: 620
diff changeset
162
601
8c21df3711e2 rigid_config
Matt Johnston <matt@ucc.asn.au>
parents: 599
diff changeset
163 println!("Couldn't parse {}: {}", conf_filename, e);
8c21df3711e2 rigid_config
Matt Johnston <matt@ucc.asn.au>
parents: 599
diff changeset
164 std::process::exit(1);
8c21df3711e2 rigid_config
Matt Johnston <matt@ucc.asn.au>
parents: 599
diff changeset
165 })
8c21df3711e2 rigid_config
Matt Johnston <matt@ucc.asn.au>
parents: 599
diff changeset
166 }
8c21df3711e2 rigid_config
Matt Johnston <matt@ucc.asn.au>
parents: 599
diff changeset
167
597
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
168 fn main() {
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
169
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
170 let args = handle_args();
599
f71cf1ad745f updated toml serde works OK
Matt Johnston <matt@ucc.asn.au>
parents: 598
diff changeset
171 setup_log(args.flag_debug);
597
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
172 //env_logger::init().unwrap();
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
173
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
174 info!("wort-templog");
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
175 debug!("debug mode");
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
176
603
b45b8b4cf0f5 get rid of lazy_static, config is passed around
Matt Johnston <matt@ucc.asn.au>
parents: 601
diff changeset
177 let config = load_config();
b45b8b4cf0f5 get rid of lazy_static, config is passed around
Matt Johnston <matt@ucc.asn.au>
parents: 601
diff changeset
178
599
f71cf1ad745f updated toml serde works OK
Matt Johnston <matt@ucc.asn.au>
parents: 598
diff changeset
179 if args.flag_thisconf {
598
d4fbfb5c46ff broken update of versions of things
Matt Johnston <matt@ucc.asn.au>
parents: 597
diff changeset
180 println!("Current configuration:\n\n{}",
603
b45b8b4cf0f5 get rid of lazy_static, config is passed around
Matt Johnston <matt@ucc.asn.au>
parents: 601
diff changeset
181 config.to_toml_string());
599
f71cf1ad745f updated toml serde works OK
Matt Johnston <matt@ucc.asn.au>
parents: 598
diff changeset
182 std::process::exit(0);
597
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
183 }
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
184
603
b45b8b4cf0f5 get rid of lazy_static, config is passed around
Matt Johnston <matt@ucc.asn.au>
parents: 601
diff changeset
185 run(&config, args.flag_nowait, args.flag_test);
597
a440eafa84a9 progress for debug
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
186 }