-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
34 changed files
with
738 additions
and
357 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use crate::{ | ||
CategoryManager, Database, JammDatabase, ManufacturerManager, PackageManager, PartManager, | ||
}; | ||
use std::path::PathBuf; | ||
|
||
pub fn export(db: &dyn Database, path: &str) { | ||
let filename_part = format!("{}{}", path, "elebox_export_parts.yaml"); | ||
let _ = PartManager::new(db).export(&filename_part); | ||
|
||
let filename_cat = format!("{}{}", path, "elebox_export_categories.yaml"); | ||
let _ = CategoryManager::new(db).export(&filename_cat); | ||
|
||
let filename_pkg = format!("{}{}", path, "elebox_export_packages.yaml"); | ||
let _ = PackageManager::new(db).export(&filename_pkg); | ||
|
||
let filename_mfr = format!("{}{}", path, "elebox_export_mfrs.yaml"); | ||
let _ = ManufacturerManager::new(db).export(&filename_mfr); | ||
} | ||
|
||
pub fn import(path: &str) -> Result<(), String> { | ||
let db_path = format!("{}{}", path, "import_elebox.db"); | ||
let db = JammDatabase::new(&db_path); | ||
db.init(); | ||
|
||
let filename_mfr = format!("{}{}", path, "elebox_export_mfrs.yaml"); | ||
let res = ManufacturerManager::new(&db).import(&filename_mfr); | ||
if res.is_err() { | ||
return Err("Part".to_string()); | ||
} | ||
|
||
let filename_pkg = format!("{}{}", path, "elebox_export_packages.yaml"); | ||
let res = PackageManager::new(&db).import(&filename_pkg); | ||
if res.is_err() { | ||
return Err("Part".to_string()); | ||
} | ||
|
||
let filename_cat = format!("{}{}", path, "elebox_export_categories.yaml"); | ||
let res = CategoryManager::new(&db).import(&filename_cat); | ||
if res.is_err() { | ||
return Err("Part".to_string()); | ||
} | ||
|
||
let filename_part = format!("{}{}", path, "elebox_export_parts.yaml"); | ||
let res = PartManager::new(&db).import(&filename_part); | ||
if res.is_err() { | ||
return Err("Part".to_string()); | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use std::fs::{self, File}; | ||
|
||
use csv::{ReaderBuilder, WriterBuilder}; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use serde_yaml; | ||
|
||
pub fn write_yaml<T>(filename: &str, items: Vec<T>) -> Result<(), ()> | ||
where | ||
T: Serialize, | ||
{ | ||
let contents = serde_yaml::to_string(&items).unwrap(); | ||
fs::write(filename, contents); | ||
Ok(()) | ||
} | ||
|
||
pub fn read_yaml<T>(filename: &str) -> Result<Vec<T>, ()> | ||
where | ||
T: for<'a> Deserialize<'a>, | ||
{ | ||
let content = fs::read_to_string(filename).unwrap(); | ||
let items: Vec<T> = serde_yaml::from_str(&content).unwrap(); | ||
Ok(items) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.