Skip to content

Commit 59d2320

Browse files
author
majorz
committed
Transitioning to CircleCI and running latest clippy and rustfmt
Connects-To: #105 Change-Type: patch
1 parent 054da00 commit 59d2320

16 files changed

Lines changed: 307 additions & 318 deletions

.circleci/config.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
2+
build: &build
3+
docker:
4+
- image: majorz/rust-$CIRCLE_JOB:rust-1.23.0
5+
steps:
6+
- checkout
7+
- run: cargo build
8+
9+
version: 2
10+
11+
jobs:
12+
aarch64:
13+
<<: *build
14+
rpi:
15+
<<: *build
16+
armv7hf:
17+
<<: *build
18+
i386:
19+
<<: *build
20+
amd64:
21+
<<: *build
22+
test:
23+
docker:
24+
- image: majorz/rust-test-deploy:rust-nightly-2018-01-08
25+
steps:
26+
- checkout
27+
- run: cargo fmt -- --write-mode=diff
28+
- run: cargo clippy -- -D warnings
29+
30+
workflows:
31+
version: 2
32+
test:
33+
jobs:
34+
- test
35+
build:
36+
jobs:
37+
- aarch64
38+
- rpi
39+
- armv7hf
40+
- i386
41+
- amd64

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ indent_size = 4
88

99
[*.md]
1010
trim_trailing_whitespace = false
11+
12+
[*.yml]
13+
indent_size = 2

.travis.yml

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,4 @@
1-
dist: trusty
2-
sudo: required
3-
language: rust
4-
cache: cargo
5-
rust:
6-
- nightly
7-
- beta
8-
- stable
9-
before_install:
10-
- sudo apt-get -qq update
11-
- sudo apt-get install -yq --no-install-recommends libdbus-1-dev
12-
install:
13-
- type -p cargo-install-update || cargo install cargo-update
14-
- cargo install-update -i cargo-update
15-
- cargo install-update -i rustfmt
16-
- if [ $TRAVIS_RUST_VERSION == nightly ]; then
17-
cargo install-update -i clippy;
18-
fi
19-
script:
20-
- cargo fmt -- --write-mode=diff
21-
- if [ $TRAVIS_RUST_VERSION == nightly ]; then
22-
cargo clippy -- -D warnings;
23-
fi
24-
- cargo build
1+
language: generic
2+
script: printf 'empty'
3+
notifications:
4+
email: false

README.md

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,28 @@
11
network-manager
2-
==============
2+
===============
33

4-
[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/resin-io-modules/NetworkManager/blob/master/LICENSE)
5-
[![Build Status](https://travis-ci.org/resin-io-modules/network-manager.svg?branch=master)](https://travis-ci.org/resin-io-modules/network-manager)
64
> Rust NetworkManager bindings
5+
6+
[![Current Release](https://img.shields.io/github/release/resin-io-modules/network-manager.svg?style=flat-square)](https://github.com/resin-io-modules/network-manager/releases/latest)
7+
[![CircleCI status](https://img.shields.io/circleci/project/github/resin-io-modules/network-manager.svg?style=flat-square)](https://circleci.com/gh/resin-io-modules/network-manager)
8+
[![License](https://img.shields.io/github/license/resin-io-modules/network-manager.svg?style=flat-square)](https://github.com/resin-io-modules/network-manager/blob/master/LICENSE)
9+
[![Issues](https://img.shields.io/github/issues/resin-io-modules/network-manager.svg?style=flat-square)](https://github.com/resin-io-modules/network-manager/issues)
10+
11+
<div align="center">
12+
<sub>an open source :satellite: project by <a href="https://resin.io">resin.io</a></sub>
13+
</div>
14+
15+
***
16+
17+
Support
18+
-------
19+
20+
If you're having any problem, please [raise an issue](https://github.com/resin-io-modules/network-manager/issues/new) on GitHub or [contact us](https://resin.io/community/), and the resin.io team will be happy to help.
21+
22+
***
23+
24+
License
25+
-------
26+
27+
network-manager is free software, and may be redistributed under the terms specified in
28+
the [license](https://github.com/resin-io-modules/network-manager/blob/master/LICENSE).

examples/create.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ extern crate network_manager;
33
use std::env;
44
use std::process;
55

6-
use network_manager::{NetworkManager, DeviceType};
7-
6+
use network_manager::{DeviceType, NetworkManager};
87

98
fn main() {
109
let args: Vec<String> = env::args().collect();

examples/hotspot.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,19 @@ extern crate network_manager;
33
use std::env;
44
use std::process;
55

6-
use network_manager::{NetworkManager, Device, DeviceType};
7-
6+
use network_manager::{Device, DeviceType, NetworkManager};
87

98
struct Options {
109
interface: Option<String>,
1110
ssid: String,
1211
password: Option<String>,
1312
}
1413

15-
1614
fn print_usage_and_exit() {
1715
println!("USAGE: hotspot [-i INTERFACE] SSID [PASSWORD]");
1816
process::exit(1);
1917
}
2018

21-
2219
fn parse_options() -> Options {
2320
let args: Vec<String> = env::args().collect();
2421

@@ -51,7 +48,6 @@ fn parse_options() -> Options {
5148
}
5249
}
5350

54-
5551
fn find_device(manager: &NetworkManager, interface: Option<String>) -> Option<Device> {
5652
if let Some(interface) = interface {
5753
let device = manager.get_device_by_interface(&interface).unwrap();
@@ -64,9 +60,9 @@ fn find_device(manager: &NetworkManager, interface: Option<String>) -> Option<De
6460
} else {
6561
let devices = manager.get_devices().unwrap();
6662

67-
let index = devices.iter().position(
68-
|d| *d.device_type() == DeviceType::WiFi,
69-
);
63+
let index = devices
64+
.iter()
65+
.position(|d| *d.device_type() == DeviceType::WiFi);
7066

7167
if let Some(index) = index {
7268
Some(devices[index].clone())
@@ -76,7 +72,6 @@ fn find_device(manager: &NetworkManager, interface: Option<String>) -> Option<De
7672
}
7773
}
7874

79-
8075
fn main() {
8176
let Options {
8277
interface,

rustfmt.toml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,2 @@
1-
array_layout = "Block"
2-
chain_indent = "Block"
3-
control_style = "Rfc"
4-
fn_args_layout = "Block"
5-
fn_args_paren_newline = false
6-
fn_call_style = "Block"
7-
fn_call_width = 80
81
match_block_trailing_comma = true
9-
struct_lit_multiline_style = "ForceMulti"
10-
struct_lit_style = "Block"
112
use_try_shorthand = true

src/connection.rs

Lines changed: 54 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ use ascii::AsAsciiStr;
77
use dbus_nm::DBusNetworkManager;
88

99
use wifi::Security;
10-
use device::{Device, get_active_connection_devices};
11-
use ssid::{Ssid, SsidSlice, AsSsidSlice};
12-
10+
use device::{get_active_connection_devices, Device};
11+
use ssid::{AsSsidSlice, Ssid, SsidSlice};
1312

1413
#[derive(Clone)]
1514
pub struct Connection {
@@ -64,14 +63,20 @@ impl Connection {
6463

6564
match state {
6665
ConnectionState::Activated => Ok(ConnectionState::Activated),
67-
ConnectionState::Activating => {
68-
wait(self, &ConnectionState::Activated, self.dbus_manager.method_timeout())
69-
},
66+
ConnectionState::Activating => wait(
67+
self,
68+
&ConnectionState::Activated,
69+
self.dbus_manager.method_timeout(),
70+
),
7071
ConnectionState::Unknown => Err("Unable to get connection state".to_string()),
7172
_ => {
7273
self.dbus_manager.activate_connection(&self.path)?;
7374

74-
wait(self, &ConnectionState::Activated, self.dbus_manager.method_timeout())
75+
wait(
76+
self,
77+
&ConnectionState::Activated,
78+
self.dbus_manager.method_timeout(),
79+
)
7580
},
7681
}
7782
}
@@ -91,9 +96,11 @@ impl Connection {
9196

9297
match state {
9398
ConnectionState::Deactivated => Ok(ConnectionState::Deactivated),
94-
ConnectionState::Deactivating => {
95-
wait(self, &ConnectionState::Deactivated, self.dbus_manager.method_timeout())
96-
},
99+
ConnectionState::Deactivating => wait(
100+
self,
101+
&ConnectionState::Deactivated,
102+
self.dbus_manager.method_timeout(),
103+
),
97104
ConnectionState::Unknown => Err("Unable to get connection state".to_string()),
98105
_ => {
99106
let active_path_option =
@@ -102,7 +109,11 @@ impl Connection {
102109
if let Some(active_path) = active_path_option {
103110
self.dbus_manager.deactivate_connection(&active_path)?;
104111

105-
wait(self, &ConnectionState::Deactivated, self.dbus_manager.method_timeout())
112+
wait(
113+
self,
114+
&ConnectionState::Deactivated,
115+
self.dbus_manager.method_timeout(),
116+
)
106117
} else {
107118
Ok(ConnectionState::Deactivated)
108119
}
@@ -143,7 +154,11 @@ impl Eq for Connection {}
143154

144155
impl fmt::Debug for Connection {
145156
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
146-
write!(f, "Connection {{ path: {:?}, settings: {:?} }}", self.path, self.settings)
157+
write!(
158+
f,
159+
"Connection {{ path: {:?}, settings: {:?} }}",
160+
self.path, self.settings
161+
)
147162
}
148163
}
149164

@@ -159,7 +174,6 @@ impl<'a> From<&'a Connection> for i32 {
159174
}
160175
}
161176

162-
163177
#[derive(Default, Debug, Clone, Eq, PartialEq)]
164178
pub struct ConnectionSettings {
165179
pub kind: String, // `type` is a reserved word, so we are using `kind` instead
@@ -194,7 +208,6 @@ impl From<i64> for ConnectionState {
194208
}
195209
}
196210

197-
198211
pub fn get_connections(dbus_manager: &Rc<DBusNetworkManager>) -> Result<Vec<Connection>, String> {
199212
let paths = dbus_manager.list_connections()?;
200213

@@ -209,7 +222,6 @@ pub fn get_connections(dbus_manager: &Rc<DBusNetworkManager>) -> Result<Vec<Conn
209222
Ok(connections)
210223
}
211224

212-
213225
pub fn get_active_connections(
214226
dbus_manager: &Rc<DBusNetworkManager>,
215227
) -> Result<Vec<Connection>, String> {
@@ -228,7 +240,6 @@ pub fn get_active_connections(
228240
Ok(connections)
229241
}
230242

231-
232243
pub fn connect_to_access_point<P>(
233244
dbus_manager: &Rc<DBusNetworkManager>,
234245
device_path: &str,
@@ -250,7 +261,11 @@ where
250261

251262
let connection = Connection::init(dbus_manager, &path)?;
252263

253-
let state = wait(&connection, &ConnectionState::Activated, dbus_manager.method_timeout())?;
264+
let state = wait(
265+
&connection,
266+
&ConnectionState::Activated,
267+
dbus_manager.method_timeout(),
268+
)?;
254269

255270
Ok((connection, state))
256271
}
@@ -267,17 +282,15 @@ where
267282
S: AsSsidSlice + ?Sized,
268283
P: AsAsciiStr + ?Sized,
269284
{
270-
let (path, _) = dbus_manager.create_hotspot(
271-
device_path,
272-
interface,
273-
ssid,
274-
password,
275-
address,
276-
)?;
285+
let (path, _) = dbus_manager.create_hotspot(device_path, interface, ssid, password, address)?;
277286

278287
let connection = Connection::init(dbus_manager, &path)?;
279288

280-
let state = wait(&connection, &ConnectionState::Activated, dbus_manager.method_timeout())?;
289+
let state = wait(
290+
&connection,
291+
&ConnectionState::Activated,
292+
dbus_manager.method_timeout(),
293+
)?;
281294

282295
Ok((connection, state))
283296
}
@@ -320,25 +333,24 @@ fn wait(
320333
total_time += 1;
321334

322335
if state == *target_state {
323-
debug!("Connection target state reached: {:?} / {}s elapsed", state, total_time);
336+
debug!(
337+
"Connection target state reached: {:?} / {}s elapsed",
338+
state, total_time
339+
);
324340

325341
return Ok(state);
326342
} else if total_time >= timeout {
327343
debug!(
328344
"Timeout reached in waiting for connection state ({:?}): {:?} / {}s elapsed",
329-
target_state,
330-
state,
331-
total_time
345+
target_state, state, total_time
332346
);
333347

334348
return Ok(state);
335349
}
336350

337351
debug!(
338352
"Still waiting for connection state ({:?}): {:?} / {}s elapsed",
339-
target_state,
340-
state,
341-
total_time
353+
target_state, state, total_time
342354
);
343355
}
344356
}
@@ -358,15 +370,16 @@ mod tests {
358370
// e.g. export TEST_WIFI_SSID="Resin.io Wifi"
359371
let wifi_env_var = "TEST_WIFI_SSID";
360372
let connection = match ::std::env::var(wifi_env_var) {
361-
Ok(ssid) => {
362-
connections
363-
.iter()
364-
.filter(|c| c.settings().ssid.as_str().unwrap() == ssid)
365-
.nth(0)
366-
.unwrap()
367-
.clone()
368-
},
369-
Err(e) => panic!("couldn't retrieve environment variable {}: {}", wifi_env_var, e),
373+
Ok(ssid) => connections
374+
.iter()
375+
.filter(|c| c.settings().ssid.as_str().unwrap() == ssid)
376+
.nth(0)
377+
.unwrap()
378+
.clone(),
379+
Err(e) => panic!(
380+
"couldn't retrieve environment variable {}: {}",
381+
wifi_env_var, e
382+
),
370383
};
371384

372385
let state = connection.get_state().unwrap();

0 commit comments

Comments
 (0)