Skip to content

Commit

Permalink
[rust] Organize use (imports) in all modules (no logical changes)
Browse files Browse the repository at this point in the history
  • Loading branch information
bonigarcia committed Oct 10, 2023
1 parent f02e917 commit 2940a0d
Show file tree
Hide file tree
Showing 21 changed files with 90 additions and 132 deletions.
16 changes: 7 additions & 9 deletions rust/src/chrome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,6 @@
// under the License.

use crate::config::ManagerConfig;
use reqwest::Client;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

use anyhow::anyhow;
use anyhow::Error;
use std::option::Option;
use std::path::PathBuf;

use crate::config::ARCH::{ARM64, X32};
use crate::config::OS::{LINUX, MACOS, WINDOWS};
use crate::downloads::{parse_json_from_url, read_version_from_link};
Expand All @@ -38,6 +29,13 @@ use crate::{
OFFLINE_REQUEST_ERR_MSG, REG_VERSION_ARG, STABLE,
UNAVAILABLE_DOWNLOAD_WITH_MIN_VERSION_ERR_MSG,
};
use anyhow::anyhow;
use anyhow::Error;
use reqwest::Client;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::option::Option;
use std::path::PathBuf;

pub const CHROME_NAME: &str = "chrome";
pub const CHROMEDRIVER_NAME: &str = "chromedriver";
Expand Down
5 changes: 2 additions & 3 deletions rust/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ use crate::{
UNAME_COMMAND,
};
use crate::{ARCH_AMD64, ARCH_ARM64, ARCH_X86, TTL_SEC, WMIC_COMMAND_OS};
use anyhow::anyhow;
use anyhow::Error;
use std::cell::RefCell;
use std::env;
use std::env::consts::OS;

use anyhow::anyhow;
use anyhow::Error;
use std::fs::read_to_string;
use std::path::Path;
use toml::Table;
Expand Down
9 changes: 3 additions & 6 deletions rust/src/downloads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,18 @@
// specific language governing permissions and limitations
// under the License.

use crate::files::parse_version;
use crate::Logger;
use anyhow::anyhow;
use anyhow::Error;
use reqwest::{Client, StatusCode};
use serde::{Deserialize, Serialize};
use serde_json::Value;

use anyhow::anyhow;
use std::fs::File;
use std::io::copy;
use std::io::Cursor;

use tempfile::{Builder, TempDir};

use crate::files::parse_version;
use crate::Logger;

#[tokio::main]
pub async fn download_to_tmp_folder(
http_client: &Client,
Expand Down
13 changes: 6 additions & 7 deletions rust/src/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@
// under the License.

use crate::config::ManagerConfig;
use anyhow::Error;
use reqwest::Client;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::env;
use std::path::{Path, PathBuf};

use crate::config::ARCH::{ARM64, X32};
use crate::config::OS::{LINUX, MACOS, WINDOWS};
use crate::downloads::{parse_json_from_url, read_version_from_link};
Expand All @@ -35,6 +28,12 @@ use crate::{
DASH_DASH_VERSION, DEV, ENV_PROGRAM_FILES_X86, NIGHTLY, OFFLINE_REQUEST_ERR_MSG,
REG_VERSION_ARG, STABLE,
};
use anyhow::Error;
use reqwest::Client;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::env;
use std::path::{Path, PathBuf};

pub const EDGE_NAMES: &[&str] = &[
"edge",
Expand Down
27 changes: 12 additions & 15 deletions rust/src/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,28 @@
// specific language governing permissions and limitations
// under the License.

use crate::config::OS;
use crate::config::OS::WINDOWS;
use crate::{
format_one_arg, format_three_args, format_two_args, run_shell_command_by_os, Command, Logger,
CP_VOLUME_COMMAND, HDIUTIL_ATTACH_COMMAND, HDIUTIL_DETACH_COMMAND, MACOS,
MSIEXEC_INSTALL_COMMAND, MV_PAYLOAD_COMMAND, MV_PAYLOAD_OLD_VERSIONS_COMMAND, PKGUTIL_COMMAND,
};
use anyhow::anyhow;
use anyhow::Error;
use bzip2::read::BzDecoder;
use directories::BaseDirs;
use flate2::read::GzDecoder;
use regex::Regex;
use std::fs;
use std::fs::File;
use std::io;
use std::io::{BufReader, Cursor, Read};

use anyhow::anyhow;
use bzip2::read::BzDecoder;
use std::path::{Path, PathBuf};

use crate::config::OS;
use directories::BaseDirs;
use flate2::read::GzDecoder;
use regex::Regex;
use tar::Archive;
use tempfile::Builder;
use zip::ZipArchive;

use crate::config::OS::WINDOWS;
use crate::{
format_one_arg, format_three_args, format_two_args, run_shell_command_by_os, Command, Logger,
CP_VOLUME_COMMAND, HDIUTIL_ATTACH_COMMAND, HDIUTIL_DETACH_COMMAND, MACOS,
MSIEXEC_INSTALL_COMMAND, MV_PAYLOAD_COMMAND, MV_PAYLOAD_OLD_VERSIONS_COMMAND, PKGUTIL_COMMAND,
};

pub const PARSE_ERROR: &str = "Wrong browser/driver version";
const CACHE_FOLDER: &str = ".cache/selenium";
const ZIP: &str = "zip";
Expand Down
12 changes: 5 additions & 7 deletions rust/src/firefox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@
// under the License.

use crate::config::ManagerConfig;
use anyhow::Error;
use reqwest::Client;
use std::collections::HashMap;

use anyhow::anyhow;
use std::path::PathBuf;

use crate::config::ARCH::{ARM64, X32};
use crate::config::OS::{LINUX, MACOS, WINDOWS};
use crate::downloads::{
Expand All @@ -37,6 +30,11 @@ use crate::{
create_http_client, format_three_args, format_two_args, Logger, SeleniumManager, BETA,
DASH_VERSION, DEV, NIGHTLY, OFFLINE_REQUEST_ERR_MSG, REG_CURRENT_VERSION_ARG, STABLE,
};
use anyhow::anyhow;
use anyhow::Error;
use reqwest::Client;
use std::collections::HashMap;
use std::path::PathBuf;

pub const FIREFOX_NAME: &str = "firefox";
pub const GECKODRIVER_NAME: &str = "geckodriver";
Expand Down
22 changes: 9 additions & 13 deletions rust/src/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,20 @@
// under the License.

use crate::config::ManagerConfig;
use anyhow::Error;
use reqwest::Client;
use std::collections::HashMap;

use anyhow::anyhow;
use std::path::PathBuf;

use crate::files::BrowserPath;

use crate::downloads::parse_json_from_url;
use crate::{
create_http_client, parse_version, Logger, SeleniumManager, OFFLINE_REQUEST_ERR_MSG, SNAPSHOT,
};

use crate::files::BrowserPath;
use crate::metadata::{
create_driver_metadata, get_driver_version_from_metadata, get_metadata, write_metadata,
};
use crate::mirror::{Assets, SeleniumRelease, MIRROR_URL};
use crate::{
create_http_client, parse_version, Logger, SeleniumManager, OFFLINE_REQUEST_ERR_MSG, SNAPSHOT,
};
use anyhow::anyhow;
use anyhow::Error;
use reqwest::Client;
use std::collections::HashMap;
use std::path::PathBuf;

pub const GRID_NAME: &str = "grid";
const GRID_RELEASE: &str = "selenium-server";
Expand Down
15 changes: 6 additions & 9 deletions rust/src/iexplorer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,17 @@
// under the License.

use crate::config::ManagerConfig;
use anyhow::Error;
use reqwest::Client;
use std::collections::HashMap;

use anyhow::anyhow;
use std::path::PathBuf;

use crate::files::{compose_driver_path_in_cache, BrowserPath};

use crate::downloads::parse_json_from_url;
use crate::files::{compose_driver_path_in_cache, BrowserPath};
use crate::{
create_http_client, parse_version, Logger, SeleniumManager, OFFLINE_REQUEST_ERR_MSG,
REG_VERSION_ARG, STABLE, WINDOWS,
};
use anyhow::anyhow;
use anyhow::Error;
use reqwest::Client;
use std::collections::HashMap;
use std::path::PathBuf;

use crate::metadata::{
create_driver_metadata, get_driver_version_from_metadata, get_metadata, write_metadata,
Expand Down
33 changes: 15 additions & 18 deletions rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,36 @@
// under the License.

use crate::chrome::{ChromeManager, CHROMEDRIVER_NAME, CHROME_NAME};
use crate::config::OS::{MACOS, WINDOWS};
use crate::config::{str_to_os, ManagerConfig};
use crate::downloads::download_to_tmp_folder;
use crate::edge::{EdgeManager, EDGEDRIVER_NAME, EDGE_NAMES, WEBVIEW2_NAME};
use crate::files::{
create_parent_path_if_not_exists, create_path_if_not_exists, default_cache_folder,
get_binary_extension, path_to_string,
};
use crate::firefox::{FirefoxManager, FIREFOX_NAME, GECKODRIVER_NAME};
use crate::iexplorer::{IExplorerManager, IEDRIVER_NAME, IE_NAMES};
use crate::safari::{SafariManager, SAFARIDRIVER_NAME, SAFARI_NAME};
use std::{env, fs};

use crate::config::OS::{MACOS, WINDOWS};
use crate::config::{str_to_os, ManagerConfig};
use anyhow::Error;
use is_executable::IsExecutable;
use reqwest::{Client, Proxy};
use std::collections::HashMap;

use anyhow::anyhow;
use std::path::{Path, PathBuf};
use std::time::Duration;
use walkdir::{DirEntry, WalkDir};

use crate::downloads::download_to_tmp_folder;
use crate::files::{parse_version, uncompress, BrowserPath};
use crate::firefox::{FirefoxManager, FIREFOX_NAME, GECKODRIVER_NAME};
use crate::grid::GRID_NAME;
use crate::iexplorer::{IExplorerManager, IEDRIVER_NAME, IE_NAMES};
use crate::logger::Logger;
use crate::metadata::{
create_browser_metadata, get_browser_version_from_metadata, get_metadata, write_metadata,
};
use crate::safari::{SafariManager, SAFARIDRIVER_NAME, SAFARI_NAME};
use crate::safaritp::{SafariTPManager, SAFARITP_NAMES};
use crate::shell::{
run_shell_command, run_shell_command_by_os, run_shell_command_with_log, split_lines, Command,
};
use anyhow::anyhow;
use anyhow::Error;
use is_executable::IsExecutable;
use reqwest::{Client, Proxy};
use std::collections::HashMap;
use std::path::{Path, PathBuf};
use std::time::Duration;
use std::{env, fs};
use walkdir::{DirEntry, WalkDir};

pub mod chrome;
pub mod config;
Expand Down
11 changes: 4 additions & 7 deletions rust/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,23 @@
// specific language governing permissions and limitations
// under the License.

use std::backtrace::{Backtrace, BacktraceStatus};
use std::path::Path;
use std::process::exit;

use anyhow::Error;
use clap::Parser;

use exitcode::DATAERR;
use exitcode::OK;
use exitcode::UNAVAILABLE;
use selenium_manager::config::{BooleanKey, StringKey, CACHE_PATH_KEY};
use selenium_manager::grid::GridManager;
use selenium_manager::logger::{Logger, BROWSER_PATH, DRIVER_PATH};
use selenium_manager::metadata::clear_metadata;
use selenium_manager::REQUEST_TIMEOUT_SEC;
use selenium_manager::TTL_SEC;
use selenium_manager::{
clear_cache, get_manager_by_browser, get_manager_by_driver, SeleniumManager,
};

use selenium_manager::metadata::clear_metadata;
use std::backtrace::{Backtrace, BacktraceStatus};
use std::path::Path;
use std::process::exit;

/// Automated driver management for Selenium
#[derive(Parser, Debug)]
Expand Down
7 changes: 2 additions & 5 deletions rust/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,13 @@
// specific language governing permissions and limitations
// under the License.

use crate::Logger;
use serde::{Deserialize, Serialize};
use std::fs;
use std::fs::File;

use std::path::{Path, PathBuf};
use std::time::{SystemTime, UNIX_EPOCH};

use serde::{Deserialize, Serialize};

use crate::Logger;

const METADATA_FILE_OLD: &str = "selenium-manager.json";
const METADATA_FILE: &str = "se-metadata.json";

Expand Down
11 changes: 4 additions & 7 deletions rust/src/safari.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,16 @@
// under the License.

use crate::config::ManagerConfig;
use crate::config::OS::MACOS;
use crate::files::BrowserPath;
use crate::{create_http_client, Logger, SeleniumManager, STABLE};
use anyhow::anyhow;
use anyhow::Error;
use reqwest::Client;
use std::collections::HashMap;

use anyhow::anyhow;
use std::path::PathBuf;
use std::string::ToString;

use crate::files::BrowserPath;

use crate::config::OS::MACOS;
use crate::{create_http_client, Logger, SeleniumManager, STABLE};

pub const SAFARI_NAME: &str = "safari";
pub const SAFARIDRIVER_NAME: &str = "safaridriver";
const SAFARI_PATH: &str = r#"/Applications/Safari.app"#;
Expand Down
11 changes: 4 additions & 7 deletions rust/src/safaritp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,16 @@
// under the License.

use crate::config::ManagerConfig;
use crate::config::OS::MACOS;
use crate::files::BrowserPath;
use crate::{create_http_client, Logger, SeleniumManager, STABLE};
use anyhow::anyhow;
use anyhow::Error;
use reqwest::Client;
use std::collections::HashMap;

use anyhow::anyhow;
use std::path::PathBuf;
use std::string::ToString;

use crate::files::BrowserPath;

use crate::config::OS::MACOS;
use crate::{create_http_client, Logger, SeleniumManager, STABLE};

pub const SAFARITP_NAMES: &[&str] = &[
"safaritp",
"safari technology preview",
Expand Down
5 changes: 2 additions & 3 deletions rust/tests/browser_download_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@
// specific language governing permissions and limitations
// under the License.

use assert_cmd::Command;
use std::env::consts::OS;

use crate::common::{assert_browser, assert_driver};
use assert_cmd::Command;
use rstest::rstest;
use std::env::consts::OS;

mod common;

Expand Down
Loading

0 comments on commit 2940a0d

Please sign in to comment.