Read a config file for paths

This commit is contained in:
Brandon Thomas committed 2016-06-18 01:58:37 -04:00
1 parent 29af59d8f3
commit cbb1a128fe
5 files changed
+30 -9

No files matched your search

Generated
+9
View File
@@ -11,6 +11,7 @@ dependencies = [
"rust-crypto 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)",
"toml 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)",
"urlencoded 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -398,6 +399,14 @@ dependencies = [
"winapi 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "toml"
version = "0.1.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "traitobject"
version = "0.0.1"
+3 -2
View File
@@ -8,15 +8,16 @@
name = "trumpet"
[dependencies]
clap = "1.5.*" # CLI parsing.
#cpal = "*" # Hardware audio output (for testing); works well with Hound.
clap = "1.5.*" # CLI parsing.
hound = "1.1.0" # WAV codec.
hyper = "0.7.*"
iron = "0.2.*"
log = "0.3.*"
router = "0.0.16"
rustc-serialize = "0.3.15"
rust-crypto = "0.2.*"
rustc-serialize = "0.3.15"
time = "0.1.*"
toml = "0.1.*"
urlencoded = "0.2.0"
+6
View File
@@ -0,0 +1,6 @@
# Various configs
# Sound paths in development and production environments
sound_path_development = "/home/bt/Dropbox/jungle.horse/sounds"
sound_path_production = "./sounds"
+2 -2
View File
@@ -1,11 +1,11 @@
// Copyright (c) 2016 Brandon Thomas <bt@brand.io>
use std::collections::HashMap;
use std::fs::File;
use std::fs::DirEntry;
use std::fs::File;
use std::fs;
use std::io;
use std::io::Read;
use std::io;
use std::path::{Path, PathBuf};
pub type VoiceName = String;
+10 -5
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2015 Brandon Thomas <bt@brand.io>
// Copyright (c) 2015-2016 Brandon Thomas <bt@brand.io>
extern crate clap;
extern crate crypto;
@@ -9,8 +9,10 @@ extern crate log;
extern crate router;
extern crate rustc_serialize;
extern crate time;
extern crate toml;
extern crate urlencoded;
pub mod config;
pub mod dictionary;
pub mod handlers;
pub mod logger;
@@ -21,6 +23,7 @@ use std::path::{Path, PathBuf};
use clap::{App, Arg, ArgMatches};
use iron::prelude::*;
use router::Router;
use config::Config;
use handlers::audio_synth_handler::AudioSynthHandler;
use handlers::error_filter::ErrorFilter;
@@ -44,10 +47,12 @@ fn main() {
let port = get_port(&matches, 9000);
let config = Config::read("./config.toml").unwrap();
VocabularyLibrary::read_from_directory(Path::new("./sounds"));
VocabularyLibrary::read_from_directory(
Path::new(&config.sound_path_development));
start_server(port);
start_server(&config, port);
}
fn get_port(matches: &ArgMatches, default_port: u16) -> u16 {
@@ -62,8 +67,8 @@ fn get_port(matches: &ArgMatches, default_port: u16) -> u16 {
}
}
fn start_server(port: u16) {
let audio_path = "./sounds";
fn start_server(config: &Config, port: u16) {
let audio_path = &config.sound_path_development;
let file_path = "./web";
let index = "index.html";