mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-24 09:24:26 +03:00
Some code style cleanups after #296
This commit is contained in:
parent
90cf38a522
commit
651b4f5ec9
@ -19,5 +19,5 @@ map_model = { path = "../map_model" }
|
||||
rand = "0.7.0"
|
||||
rand_xorshift = "0.2.0"
|
||||
serde = "1.0.110"
|
||||
serde_json = "1.0.40"
|
||||
sim = { path = "../sim" }
|
||||
serde_json = "1.0.40"
|
@ -1,5 +1,5 @@
|
||||
use crate::utils::{download, download_kml, osmconvert};
|
||||
use crate::configuration::ImporterConfiguration;
|
||||
use crate::utils::{download, download_kml, osmconvert};
|
||||
use abstutil::{prettyprint_usize, Timer};
|
||||
use geom::{Polygon, Ring};
|
||||
use kml::ExtraShapes;
|
||||
|
@ -1,4 +1,4 @@
|
||||
use serde::{Deserialize};
|
||||
use serde::Deserialize;
|
||||
use serde_json;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
@ -24,7 +24,6 @@ impl Default for ImporterConfiguration {
|
||||
}
|
||||
|
||||
pub fn load_configuration() -> ImporterConfiguration {
|
||||
|
||||
// Safe to assume that {} can be parsed given struct-level Default implementation.
|
||||
let default = serde_json::from_str("{}").unwrap();
|
||||
|
||||
|
@ -1,11 +1,18 @@
|
||||
use crate::configuration::{ImporterConfiguration, load_configuration};
|
||||
use crate::configuration::ImporterConfiguration;
|
||||
use std::ffi::OsStr;
|
||||
use std::process::Command;
|
||||
|
||||
pub fn are_dependencies_callable(config: &ImporterConfiguration) -> bool {
|
||||
let mut result = true;
|
||||
|
||||
for command in [&config.curl, &config.osmconvert, &config.unzip, &config.gunzip].iter() {
|
||||
for command in [
|
||||
&config.curl,
|
||||
&config.osmconvert,
|
||||
&config.unzip,
|
||||
&config.gunzip,
|
||||
]
|
||||
.iter()
|
||||
{
|
||||
println!("- Testing if {} is callable", command);
|
||||
if !is_program_callable(command) {
|
||||
println!("Failed to run {}", command);
|
||||
@ -17,10 +24,7 @@ pub fn are_dependencies_callable(config: &ImporterConfiguration) -> bool {
|
||||
|
||||
fn is_program_callable<S: AsRef<OsStr>>(name: S) -> bool {
|
||||
let output = Command::new(name)
|
||||
.arg("-h") // most command line programs return 0 with -h option
|
||||
.output(); // suppress output
|
||||
match output {
|
||||
Ok(_) => true,
|
||||
Err(_) => false,
|
||||
}
|
||||
}
|
||||
.arg("-h") // most command line programs return 0 with -h option
|
||||
.output(); // suppress output
|
||||
output.is_ok()
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::utils::{download, osmconvert};
|
||||
use crate::configuration::ImporterConfiguration;
|
||||
use crate::utils::{download, osmconvert};
|
||||
|
||||
fn input(config: &ImporterConfiguration) {
|
||||
download(
|
||||
|
@ -8,7 +8,8 @@ mod soundcast;
|
||||
mod tel_aviv;
|
||||
mod utils;
|
||||
mod xian;
|
||||
use configuration::{ImporterConfiguration, load_configuration};
|
||||
|
||||
use configuration::{load_configuration, ImporterConfiguration};
|
||||
use dependencies::are_dependencies_callable;
|
||||
|
||||
// TODO Might be cleaner to express as a dependency graph?
|
||||
@ -72,7 +73,9 @@ fn main() {
|
||||
|
||||
if job.osm_to_raw {
|
||||
if !are_dependencies_callable(&config) {
|
||||
println!("One or more dependencies aren't callable. Add them to the path and try again.");
|
||||
println!(
|
||||
"One or more dependencies aren't callable. Add them to the path and try again."
|
||||
);
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
@ -102,7 +105,7 @@ fn main() {
|
||||
|
||||
#[cfg(feature = "scenarios")]
|
||||
{
|
||||
let (popdat, huge_map) = seattle::ensure_popdat_exists(&mut timer);
|
||||
let (popdat, huge_map) = seattle::ensure_popdat_exists(&mut timer, &config);
|
||||
(Some(popdat), Some(huge_map))
|
||||
}
|
||||
|
||||
@ -225,4 +228,4 @@ fn oneshot(osm_path: String, clip: Option<String>, drive_on_right: bool, build_c
|
||||
map.save();
|
||||
timer.stop("save map");
|
||||
println!("{} has been created", abstutil::path_map(&name));
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::utils::{download, download_kml, osmconvert};
|
||||
use crate::configuration::ImporterConfiguration;
|
||||
use crate::utils::{download, download_kml, osmconvert};
|
||||
use abstutil::MultiMap;
|
||||
use geom::{Duration, Time};
|
||||
use map_model::{BusRouteID, Map};
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::utils::{download, osmconvert};
|
||||
use crate::configuration::ImporterConfiguration;
|
||||
use crate::utils::{download, osmconvert};
|
||||
|
||||
fn input(config: &ImporterConfiguration) {
|
||||
download(
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::configuration::ImporterConfiguration;
|
||||
use abstutil::Timer;
|
||||
use std::path::Path;
|
||||
use std::process::Command;
|
||||
use crate::configuration::ImporterConfiguration;
|
||||
|
||||
// If the output file doesn't already exist, downloads the URL into that location. Automatically
|
||||
// uncompresses .zip and .gz files.
|
||||
@ -91,7 +91,12 @@ pub fn download_kml(
|
||||
|
||||
// Uses osmconvert to clip the input .osm (or .pbf) against a polygon and produce some output.
|
||||
// Skips if the output exists.
|
||||
pub fn osmconvert(input: &str, clipping_polygon: String, output: String, config: &ImporterConfiguration) {
|
||||
pub fn osmconvert(
|
||||
input: &str,
|
||||
clipping_polygon: String,
|
||||
output: String,
|
||||
config: &ImporterConfiguration,
|
||||
) {
|
||||
let input = abstutil::path(input);
|
||||
let clipping_polygon = abstutil::path(clipping_polygon);
|
||||
let output = abstutil::path(output);
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::utils::{download, osmconvert};
|
||||
use crate::configuration::ImporterConfiguration;
|
||||
use crate::utils::{download, osmconvert};
|
||||
|
||||
fn input(config: &ImporterConfiguration) {
|
||||
download(
|
||||
|
@ -363,8 +363,8 @@ mod tests {
|
||||
"sbbdps",
|
||||
"vv^^^^",
|
||||
),
|
||||
// TODO I have a fix for this, but somehow the fallout gridlocked lakeslice, so holding
|
||||
// off...
|
||||
/* TODO I have a fix for this, but somehow the fallout gridlocked lakeslice, so
|
||||
* holding off... */
|
||||
/*(
|
||||
"https://www.openstreetmap.org/way/534549104",
|
||||
vec![
|
||||
|
Loading…
Reference in New Issue
Block a user