Skip to content

Commit

Permalink
Add break-infix = wrap-or-vertical
Browse files Browse the repository at this point in the history
  • Loading branch information
yfyf committed Nov 26, 2024
1 parent e77629a commit fc2b21b
Show file tree
Hide file tree
Showing 18 changed files with 94 additions and 43 deletions.
2 changes: 2 additions & 0 deletions controller/.ocamlformat
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ space-around-arrays = true
space-around-lists = true
space-around-records = true
space-around-variants = true

break-infix = wrap-or-vertical
49 changes: 33 additions & 16 deletions controller/bindings/connman/connman.ml
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,13 @@ module Service = struct
; netmask =
properties |> List.assoc "Netmask" |> cast_single basic_string
; gateway =
properties |> List.assoc_opt "Gateway"
properties
|> List.assoc_opt "Gateway"
|> Option.map (cast_single basic_string)
}
)
|> CCResult.guard |> CCResult.to_opt
|> CCResult.guard
|> CCResult.to_opt
end

module IPv6 = struct
Expand All @@ -327,16 +329,20 @@ module Service = struct
; address =
properties |> List.assoc "Address" |> cast_single basic_string
; prefix_length =
properties |> List.assoc "PrefixLength" |> cast_single basic_byte
properties
|> List.assoc "PrefixLength"
|> cast_single basic_byte
|> int_of_char
; gateway =
properties |> List.assoc_opt "Gateway"
properties
|> List.assoc_opt "Gateway"
|> Option.map (cast_single basic_string)
; privacy =
properties |> List.assoc "Privacy" |> cast_single basic_string
}
)
|> CCResult.guard |> CCResult.to_opt
|> CCResult.guard
|> CCResult.to_opt
end

module Ethernet = struct
Expand All @@ -361,7 +367,8 @@ module Service = struct
; mtu = properties |> List.assoc "MTU" |> cast_single basic_uint16
}
)
|> CCResult.guard |> CCResult.to_opt
|> CCResult.guard
|> CCResult.to_opt
end

module Proxy = struct
Expand Down Expand Up @@ -492,7 +499,8 @@ module Service = struct
let strength_of_obus v =
try
OBus_value.C.(v |> cast_single basic_byte)
|> int_of_char |> CCOption.return
|> int_of_char
|> CCOption.return
with _ -> None
in
let proxy_of_obus v =
Expand All @@ -503,9 +511,11 @@ module Service = struct
properties |> List.assoc "Method" |> cast_single basic_string
in
if proxy_method = "manual" then
properties |> List.assoc "Servers"
properties
|> List.assoc "Servers"
|> cast_single (array basic_string)
|> List.hd |> Proxy.validate
|> List.hd
|> Proxy.validate
else None
with _ -> None
in
Expand Down Expand Up @@ -547,19 +557,24 @@ module Service = struct
}
)
<*> (properties |> List.assoc_opt "Name" >>= string_of_obus)
<*> (properties |> List.assoc_opt "Type" >>= string_of_obus
>>= Technology.type_of_string
<*> (properties
|> List.assoc_opt "Type"
>>= string_of_obus
>>= Technology.type_of_string
)
<*> (properties |> List.assoc_opt "State" >>= string_of_obus
>>= state_of_string
<*> (properties
|> List.assoc_opt "State"
>>= string_of_obus
>>= state_of_string
)
<*> (properties |> List.assoc_opt "Strength" >>= strength_of_obus |> pure)
<*> (properties |> List.assoc_opt "Favorite" >>= bool_of_obus)
<*> (properties |> List.assoc_opt "AutoConnect" >>= bool_of_obus)
<*> (properties |> List.assoc_opt "IPv4" >>= IPv4.of_obus |> pure)
<*> (properties
|> List.assoc_opt "IPv4.Configuration"
>>= IPv4.of_obus |> pure
>>= IPv4.of_obus
|> pure
)
<*> (properties |> List.assoc_opt "IPv6" >>= IPv6.of_obus |> pure)
<*> (properties |> List.assoc_opt "Ethernet" >>= Ethernet.of_obus)
Expand Down Expand Up @@ -750,8 +765,10 @@ module Manager = struct
}
)
<*> (properties |> List.assoc_opt "Name" >>= string_of_obus)
<*> (properties |> List.assoc_opt "Type" >>= string_of_obus
>>= Technology.type_of_string
<*> (properties
|> List.assoc_opt "Type"
>>= string_of_obus
>>= Technology.type_of_string
)
<*> (properties |> List.assoc_opt "Powered" >>= bool_of_obus)
<*> (properties |> List.assoc_opt "Connected" >>= bool_of_obus)
Expand Down
6 changes: 4 additions & 2 deletions controller/bindings/locale/locale.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ let log_src = Logs.Src.create "locale"

let get_lang () =
(fun () -> Util.read_from_file log_src "/var/lib/gui-localization/lang")
|> Lwt_result.catch >|= Base.Result.ok
|> Lwt_result.catch
>|= Base.Result.ok

let set_lang lang_code =
Util.write_to_file log_src "/var/lib/gui-localization/lang" lang_code

let get_keymap () =
(fun () -> Util.read_from_file log_src "/var/lib/gui-localization/keymap")
|> Lwt_result.catch >|= Base.Result.ok
|> Lwt_result.catch
>|= Base.Result.ok

let set_keymap keymap_code =
Util.write_to_file log_src "/var/lib/gui-localization/keymap" keymap_code
6 changes: 4 additions & 2 deletions controller/bindings/rauc/rauc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ end

let get_booted_slot daemon =
OBus_property.make De_pengutronix_rauc_Installer.p_BootSlot (proxy daemon)
|> OBus_property.get >|= Slot.of_string
|> OBus_property.get
>|= Slot.of_string

let mark_slot daemon slot status =
let%lwt marked, msg =
Expand Down Expand Up @@ -104,7 +105,8 @@ let get_primary daemon =
try%lwt
OBus_method.call De_pengutronix_rauc_Installer.m_GetPrimary (proxy daemon)
()
>|= Slot.of_string >>= Lwt.return_some
>|= Slot.of_string
>>= Lwt.return_some
with _ -> Lwt.return_none

let install daemon source =
Expand Down
3 changes: 2 additions & 1 deletion controller/bindings/systemd/systemd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ module Manager = struct
failwith (Format.sprintf "unexpected system state (%s)" s)
in
OBus_property.make Org_freedesktop_systemd1_Manager.p_SystemState proxy
|> OBus_property.get >|= system_state_of_string
|> OBus_property.get
>|= system_state_of_string

let get_unit proxy name =
let%lwt context, x1 =
Expand Down
3 changes: 2 additions & 1 deletion controller/bindings/timedate/timedate.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ type t = OBus_peer.Private.t

let get_configured_timezone () =
(fun () -> Util.read_from_file log_src "/var/lib/gui-localization/timezone")
|> Lwt_result.catch >|= Base.Result.ok
|> Lwt_result.catch
>|= Base.Result.ok

let set_timezone timezone =
Util.write_to_file log_src "/var/lib/gui-localization/timezone" timezone
Expand Down
5 changes: 4 additions & 1 deletion controller/bindings/zerotier/zerotier.ml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ let get_status () =
with
| RequestSuccess (_, body) ->
let open Ezjsonm in
from_string body |> get_dict |> List.assoc "address" |> get_string
from_string body
|> get_dict
|> List.assoc "address"
|> get_string
|> fun address -> return { address }
| RequestFailure error ->
Lwt.fail_with (Curl.pretty_print_error error)
Expand Down
19 changes: 13 additions & 6 deletions controller/server/gui.ml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ let error_handling =
(page
(Error_page.html
{ message =
exn |> Sexplib.Std.sexp_of_exn
exn
|> Sexplib.Std.sexp_of_exn
|> Sexplib.Sexp.to_string_hum
; request =
req |> Request.sexp_of_t |> Sexplib.Sexp.to_string_hum
Expand Down Expand Up @@ -316,7 +317,8 @@ module NetworkGui = struct
match (keep_password, current_proxy_opt) with
| true, Some { host; port; credentials = Some { user; password } } ->
if
host_input = Some host && port_input = Some port
host_input = Some host
&& port_input = Some port
&& user_input = Some user
then
(* Proxy configuration wasn't touched, password may be preserved. *)
Expand Down Expand Up @@ -376,7 +378,8 @@ module NetworkGui = struct
let gateway = get_prop "static_ip_gateway" in
let nameservers =
get_prop "static_ip_nameservers"
|> String.split_on_char ',' |> List.map String.trim
|> String.split_on_char ','
|> List.map String.trim
in
let%lwt () =
Connman.Service.set_manual_ipv4 service ~address ~netmask ~gateway
Expand Down Expand Up @@ -561,13 +564,17 @@ let routes ~systemd ~health_s ~update_s ~rauc ~connman app =
|> middleware (static ())
|> middleware error_handling
|> get "/" (fun _ -> "/info" |> Uri.of_string |> redirect')
|> InfoGui.build |> NetworkGui.build ~connman |> LocalizationGui.build
|> InfoGui.build
|> NetworkGui.build ~connman
|> LocalizationGui.build
|> StatusGui.build ~systemd ~health_s ~update_s ~rauc
|> ChangelogGui.build |> LicensingGui.build
|> ChangelogGui.build
|> LicensingGui.build
|> RemoteMaintenanceGui.build ~systemd

(* NOTE: probably easier to create a record with all the inputs instead of passing in x arguments. *)
let start ~port ~systemd ~health_s ~update_s ~rauc ~connman =
empty |> Opium.App.port port
empty
|> Opium.App.port port
|> routes ~systemd ~health_s ~update_s ~rauc ~connman
|> start
5 changes: 3 additions & 2 deletions controller/server/health.ml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ let rec run ~systemd ~rauc ~set_state =
(* or bad... *)
Bad
(Format.sprintf "system state is %s"
(system_state |> Manager.sexp_of_system_state
|> Sexplib.Sexp.to_string_hum
(system_state
|> Manager.sexp_of_system_state
|> Sexplib.Sexp.to_string_hum
)
)
|> set
Expand Down
3 changes: 2 additions & 1 deletion controller/server/info.ml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ let rec grouped n s =
let get () =
let%lwt machine_id =
Util.read_from_file log_src "/etc/machine-id"
>|= grouped 4 >|= String.concat "-"
>|= grouped 4
>|= String.concat "-"
in
let%lwt zerotier_address =
match%lwt Zerotier.get_status () with
Expand Down
11 changes: 8 additions & 3 deletions controller/server/network.ml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ let enable_and_scan_wifi_devices ~connman =
|> List.filter (fun (t : Technology.t) ->
t.type' = Technology.Wifi && not t.powered
)
|> List.map Technology.enable |> Lwt.join
|> List.map Technology.enable
|> Lwt.join
in
(* and start a scan. *)
let%lwt () =
technologies
|> List.filter (fun (t : Technology.t) -> t.type' = Technology.Wifi)
|> List.map Technology.scan |> Lwt.join
|> List.map Technology.scan
|> Lwt.join
in
return_unit
)
Expand Down Expand Up @@ -76,6 +78,9 @@ module Interface = struct
let get_all () =
let command = ("/run/current-system/sw/bin/ip", [| "ip"; "-j"; "link" |]) in
let%lwt json = Lwt_process.pread command in
json |> Ezjsonm.from_string |> Ezjsonm.value |> Ezjsonm.get_list of_json
json
|> Ezjsonm.from_string
|> Ezjsonm.value
|> Ezjsonm.get_list of_json
|> return
end
3 changes: 2 additions & 1 deletion controller/server/server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,5 @@ let () =
(Cmd.info ~doc:"PlayOS Controller" ~version:Info.version
"playos-controller"
)
|> Cmd.eval |> ignore
|> Cmd.eval
|> ignore
3 changes: 2 additions & 1 deletion controller/server/view/network_list_page.ml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ let html { proxy; services; interfaces } =
List.partition Connman.Service.is_connected services
in
let interfaces_str =
interfaces |> [%sexp_of: Network.Interface.t list]
interfaces
|> [%sexp_of: Network.Interface.t list]
|> Sexplib.Sexp.to_string_hum
in
Page.html ~current_page:Page.Network
Expand Down
7 changes: 5 additions & 2 deletions controller/tests/server/update/scenario.ml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ let str_match_with_magic_pat expected actual =
let magic_pattern = regexp_string _WILDCARD_PAT in
let exp_parts = full_split magic_pattern expected in
let exp_regexp =
regexp @@ String.concat ""
regexp
@@ String.concat ""
@@ List.map
(fun p -> match p with Text a -> quote a | Delim _ -> ".*")
exp_parts
Expand Down Expand Up @@ -87,7 +88,9 @@ let check_state expected_state_sequence prev_state cur_state =
let spec = Queue.pop expected_state_sequence in
(* after a callback first spec should always be the next state we expect *)
if not (is_state_spec spec) then
failwith @@ "Expected a state spec, but got " ^ specfmt spec
failwith
@@ "Expected a state spec, but got "
^ specfmt spec
^ " - bad spec?" ;
(* check if state spec matches the prev_state (i.e. initial state) *)
let%lwt () = interpret_spec prev_state spec in
Expand Down
3 changes: 2 additions & 1 deletion controller/tests/server/update/update_client_mock_server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ let mock_server () =
let addr, port = get_random_available_port () in
let server_url = Format.sprintf "http://%s:%d/" addr port in
let server =
App.empty |> App.port port
App.empty
|> App.port port
|> App.get "/latest" self#get_latest_handler
|> App.get "/ready" (fun _ -> Lwt.return @@ Response.create ())
|> App.get "/:vsn/:bundle" self#download_bundle_handler
Expand Down
3 changes: 2 additions & 1 deletion controller/tests/server/update/update_client_tests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ let test_invalid_proxy_fail _ (module Client : S) =
true ;
Lwt.return ()
| other_exn ->
Alcotest.fail @@ "Got unexpected exception: "
Alcotest.fail
@@ "Got unexpected exception: "
^ Printexc.to_string other_exn
)

Expand Down
3 changes: 2 additions & 1 deletion controller/tests/server/update/update_prop_tests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ let test_random_failure_case =
in
let state_seq = Queue.create () in
let state_seq_to_str state_seq =
String.concat " -> " @@ List.map Helpers.statefmt
String.concat " -> "
@@ List.map Helpers.statefmt
@@ List.of_seq (Queue.to_seq state_seq)
in
let rec do_while ?(c = 0) loop_lim cur_state =
Expand Down
3 changes: 2 additions & 1 deletion controller/tests/server/update/update_tests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ let sleep_after_error_or_check_test () =
let elasped_seconds = end_time -. start_time in
if elasped_seconds > expected_timeout *. 2.0 then Lwt.return ()
else
Lwt.return @@ Alcotest.fail
Lwt.return
@@ Alcotest.fail
@@ Format.sprintf
"Slept shorter than expected (expected %f; slept %f) after state %s"
(expected_timeout *. 2.0) elasped_seconds
Expand Down

0 comments on commit fc2b21b

Please sign in to comment.