diff --git a/Cargo.toml b/Cargo.toml index d20c860..f0bd4f7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,4 +8,5 @@ edition = "2021" [dependencies] clap = { version = "4.0", features = ["derive"] } cvrf-xmlparser = { git = "https://git.zhgsun.com:8089/jiachao2130/cvrf-xmlparser.git", version = "0.1.0" } +serde = { version = "1", features = ["serde_derive"] } serde_json = { version = "1.0" } diff --git a/src/cli.rs b/src/cli.rs index ff4bbd3..d31640c 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -17,6 +17,10 @@ pub enum CliSub { /// 创建并生成新的 CUSA 数据文件 Db(SaDbCli), + + /// CUVAS 定制化自动操作,通过读取配置文件中指定的源、目标目录,执行 CUVARS + /// 数据库更新操作,配置文件为 `/etc/cuvars/cvrf2cusa.json` + Auto(AutoCli), } /// ConvertCli 用于将指定的 cvrf 格式 xml 文件转换为 cusa 格式 @@ -67,3 +71,7 @@ pub struct SaDbCli { pub fn parse() -> Cli { Cli::parse() } + +#[derive(Clone, Debug, Parser)] +#[command(author, version, about, long_about = None)] +pub struct AutoCli; diff --git a/src/config.rs b/src/config.rs new file mode 100644 index 0000000..83c8da9 --- /dev/null +++ b/src/config.rs @@ -0,0 +1,56 @@ +use serde::{Deserialize, Serialize}; + +/// cvrf2cusa 自动化执行所需的配置 +#[derive(Clone, Debug, Deserialize, Serialize)] +pub(crate) struct AutoConfig { + // 对应cuavrs-db-cvrf + source: String, + + // cuavrs-db-sa + target: String, +} + +impl AutoConfig { + pub fn from(path: &str) -> crate::Result { + let data = std::fs::read_to_string(path)?; + + Ok(serde_json::from_str::(&data)?) + } +} + +/// cuvars 中,关于源码追踪,自动修复相关的配置项,一般位于组件最底层的目录,`config.json` +#[derive(Clone, Debug, Deserialize, Serialize)] +pub(crate) struct RepairConfig { + // 对应了 openEuelr 的上游版本 + upstream: String, + + // 此组件是否支持自动修复 + autobuild: bool, + + // 当前已修复的最新版本号 + fixed_version: String, +} + +impl RepairConfig { + /// 从指定的路径读取文件并将之转换为 `RepairConfig` + pub fn read(path: &str) -> crate::Result { + let data = std::fs::read_to_string(path)?; + + Ok(serde_json::from_str::(&data)?) + } + + /// 获取对应的上游代码分支 + pub fn upstream(&self) -> &str { + &self.upstream + } + + /// 此组件是否支持自动构建发布 + pub fn autobuild(&self) -> bool { + self.autobuild + } + + /// 已修复的最新代码版本 + pub fn fixed_version(&self) -> &str { + &self.fixed_version + } +} \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 58cfc97..3e3bb00 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,6 +11,8 @@ use cvrf_xmlparser::{ pub mod cli; +mod config; + /// 定义 crate::Error /// 大部分函数返回的错误 pub type Error = Box; @@ -24,6 +26,7 @@ pub fn cumain() -> Result<()> { match cli.subcommand { cli::CliSub::Convert(cli) => covert(&cli), cli::CliSub::Db(cli) => sadb(&cli), + cli::CliSub::Auto(_) => auto(), } } @@ -163,3 +166,21 @@ fn walk_dir>(path: P, nodir: bool) -> Vec res } + +/// 从配置文件中读取 cvrf 和 cusa 数据库的路径,并执行自动转换操作 +pub fn auto() -> Result<()> { + // 默认配置为,但也可读取执行命令路径下的配置 + let config = { + let default = Path::new("/etc/cuvars/cvrf2cusa.json"); + if default.is_file() { + default.to_str().unwrap() + } else { + "cvrf2cusa.json" + } + }; + + let auto = config::AutoConfig::from(config)?; + + todo!(); + Ok(()) +}