Skip to content

Commit e619e2a

Browse files
authored
Designspark (#76)
* add DesignSpark format * ugh, specify docker image versions as latest tag no longer exists * rust fmt
1 parent 8b3af24 commit e619e2a

File tree

16 files changed

+173
-97
lines changed

16 files changed

+173
-97
lines changed

.circleci/config.yml

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,31 @@
33
version: 2
44

55
jobs:
6+
version_check:
7+
docker:
8+
- image: cimg/rust:1.58.1
9+
10+
steps:
11+
- checkout
12+
13+
- run:
14+
name: "Check version missmatch"
15+
command: "bash version_check.sh"
16+
617
fmt:
718
docker:
8-
- image: circleci/rust:latest
19+
- image: cimg/rust:1.58.1
920

1021
steps:
1122
- checkout
1223

1324
- run:
1425
name: "Check formatting"
15-
command: rustfmt --check **/**.rs
26+
command: cargo fmt --check
1627

1728
checks:
1829
docker:
19-
- image: circleci/node:latest
30+
- image: cimg/node::17.5.0
2031

2132
steps:
2233
- checkout
@@ -165,7 +176,7 @@ jobs:
165176

166177
deploy:
167178
docker:
168-
- image: circleci/node:latest
179+
- image: cimg/node::17.5.0
169180

170181
steps:
171182
- checkout
@@ -206,8 +217,12 @@ workflows:
206217
version: 2
207218
build:
208219
jobs:
209-
# - fmt
210-
- build_linux
220+
- fmt
221+
- version_check
222+
- build_linux:
223+
requires:
224+
- fmt
225+
- version_check
211226
- request_deploy:
212227
type: approval
213228
requires:

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@
44
/test-target
55
/target
66
*.tar.gz
7+
/test-files/LIB_*
8+
!/test-files/LIB_*.zip

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
# 0.3.0
1+
# 0.3.1
2+
* Added DesignSpark (#75)
3+
4+
## 0.3.0
25
* Refactored
36
* Supports multiple formats (#15, #17, #62)
47
* New Config format (incompatible, remove/rename old config)

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ll-cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "library-loader-cli"
3-
version = "0.3.0"
3+
version = "0.3.1"
44
description = "Download libraries from componentsearchengine.com"
55
authors = ["Edwin Svensson <libraryloader@olback.net>"]
66
edition = "2021"

ll-core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "library-loader-core"
3-
version = "0.3.0"
3+
version = "0.3.1"
44
authors = ["Edwin Svensson <libraryloader@olback.net>"]
55
edition = "2021"
66
publish = false

ll-core/src/cse/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl CSE {
101101
let mut vec_results = Vec::with_capacity(self.formats.len());
102102

103103
for format in &*self.formats {
104-
if format.ecad == ECAD::ZIP {
104+
if format.ecad == ECAD::Zip {
105105
let mut files: Files = Files::new();
106106
files.insert(zip_filename.clone(), data.clone());
107107
vec_results.push(Result {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
use super::*;
2+
3+
pub fn extract(
4+
format: &Format,
5+
files: &mut Files,
6+
file_path: String,
7+
item: &mut ZipFile,
8+
) -> Result<()> {
9+
generic_extractor(format, files, file_path, item)
10+
}

ll-core/src/format/extractors/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// * Keep these in alphabetical order
22
pub mod d3;
3+
pub mod designspark;
34
pub mod eagle;
45
pub mod easyeda;
56
pub mod kicad;

ll-core/src/format/mod.rs

Lines changed: 64 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -8,52 +8,55 @@ use {
88
mod extractors;
99
pub use extractors::Files;
1010

11-
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12-
pub enum ECAD {
13-
// * Keep these in alphabetical order
14-
#[serde(rename = "3d")]
15-
D3, // 3D
16-
#[serde(rename = "eagle")]
17-
EAGLE,
18-
#[serde(rename = "easyeda")]
19-
EASYEDA,
20-
#[serde(rename = "kicad")]
21-
KICAD,
22-
#[serde(rename = "zip")]
23-
ZIP,
24-
}
11+
macro_rules! ecad {
12+
([$(($variant:tt, $variant_literal:literal)),*]) => {
13+
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14+
pub enum ECAD {
15+
$(
16+
#[serde(rename = $variant_literal)]
17+
$variant,
18+
)*
19+
}
2520

26-
impl TryFrom<&str> for ECAD {
27-
type Error = Error;
21+
impl ::core::convert::TryFrom<&str> for ECAD {
22+
type Error = Error;
2823

29-
fn try_from(value: &str) -> std::result::Result<Self, Self::Error> {
30-
match value.to_lowercase().as_str() {
31-
"3d" => Ok(ECAD::D3),
32-
"eagle" => Ok(ECAD::EAGLE),
33-
"easyeda" => Ok(ECAD::EASYEDA),
34-
"kicad" => Ok(ECAD::KICAD),
35-
"zip" => Ok(ECAD::ZIP),
36-
_ => Err(Error::EcadNotFound),
24+
fn try_from(value: &str) -> ::core::result::Result<Self, Self::Error> {
25+
match value.to_lowercase().as_str() {
26+
$(
27+
$variant_literal => Ok(ECAD::$variant),
28+
)*
29+
_ => Err(Error::EcadNotFound),
30+
}
31+
}
3732
}
38-
}
39-
}
4033

41-
impl fmt::Display for ECAD {
42-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
43-
write!(
44-
f,
45-
"{}",
46-
match &self {
47-
Self::D3 => "3d",
48-
Self::EAGLE => "eagle",
49-
Self::EASYEDA => "easyeda",
50-
Self::KICAD => "kicad",
51-
Self::ZIP => "zip",
34+
impl ::core::fmt::Display for ECAD {
35+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> ::core::fmt::Result {
36+
write!(
37+
f,
38+
"{}",
39+
match &self {
40+
$(
41+
Self::$variant => $variant_literal,
42+
)*
43+
}
44+
)
5245
}
53-
)
54-
}
46+
}
47+
48+
};
5549
}
5650

51+
ecad!([
52+
(D3, "3d"),
53+
(DesignSpark, "designspark"),
54+
(Eagle, "eagle"),
55+
(EasyEDA, "easyeda"),
56+
(KiCad, "kicad"),
57+
(Zip, "zip")
58+
]);
59+
5760
#[derive(Debug, Clone, PartialEq)]
5861
pub struct Format {
5962
pub output_path: PathBuf,
@@ -66,46 +69,46 @@ pub struct Format {
6669

6770
impl Format {
6871
pub fn from_ecad<P: Into<PathBuf>>(ecad: ECAD, output_path: P) -> Self {
69-
// let f = format.into().to_lowercase();
70-
7172
// * Keep these in alphabetical order
7273
match ecad {
7374
ECAD::D3 => Self {
7475
output_path: output_path.into(),
75-
// name: f,
76-
ecad: ECAD::D3,
76+
ecad,
7777
create_folder: true,
7878
match_path: "3D",
7979
ignore: vec![],
8080
},
81-
ECAD::EAGLE => Self {
81+
ECAD::DesignSpark => Self {
82+
output_path: output_path.into(),
83+
ecad,
84+
create_folder: false,
85+
match_path: "DesignSpark PCB",
86+
ignore: vec![],
87+
},
88+
ECAD::Eagle => Self {
8289
output_path: output_path.into(),
83-
// name: f,
84-
ecad: ECAD::EAGLE,
90+
ecad,
8591
create_folder: false,
8692
match_path: "EAGLE",
8793
ignore: vec!["Readme.html"],
8894
},
89-
ECAD::EASYEDA => Self {
95+
ECAD::EasyEDA => Self {
9096
output_path: output_path.into(),
91-
// name: f,
92-
ecad: ECAD::EASYEDA,
97+
ecad,
9398
create_folder: false,
9499
match_path: "EasyEDA",
95100
ignore: vec!["Readme.html"],
96101
},
97-
ECAD::KICAD => Self {
102+
ECAD::KiCad => Self {
98103
output_path: output_path.into(),
99-
// name: f,
100-
ecad: ECAD::KICAD,
104+
ecad,
101105
create_folder: true,
102106
match_path: "KiCad",
103107
ignore: vec![],
104108
},
105-
ECAD::ZIP => Self {
109+
ECAD::Zip => Self {
106110
output_path: output_path.into(),
107-
// name: f,
108-
ecad: ECAD::ZIP,
111+
ecad,
109112
create_folder: false,
110113
match_path: "",
111114
ignore: vec![],
@@ -117,10 +120,12 @@ impl Format {
117120
match &self.ecad {
118121
// * Keep these in alphabetical order
119122
ECAD::D3 => extractors::d3::extract(&self, files, file_path, item)?,
120-
ECAD::EAGLE => extractors::eagle::extract(&self, files, file_path, item)?,
121-
ECAD::EASYEDA => extractors::easyeda::extract(&self, files, file_path, item)?,
122-
ECAD::KICAD => extractors::kicad::extract(&self, files, file_path, item)?,
123-
ECAD::ZIP => unreachable!("ZIP not handled!"), // ! NOTE: DO NOT ADD A _ => {} CATCHER HERE!
123+
ECAD::DesignSpark => extractors::designspark::extract(&self, files, file_path, item)?,
124+
ECAD::Eagle => extractors::eagle::extract(&self, files, file_path, item)?,
125+
ECAD::EasyEDA => extractors::easyeda::extract(&self, files, file_path, item)?,
126+
ECAD::KiCad => extractors::kicad::extract(&self, files, file_path, item)?,
127+
ECAD::Zip => unreachable!("ZIP not handled!"),
128+
// ! NOTE: DO NOT ADD A _ => {} CATCHER HERE!
124129
};
125130

126131
Ok(())

0 commit comments

Comments
 (0)