Improve console_of_string
This commit is contained in:
parent
76ab741344
commit
3c7c21afcd
2 changed files with 28 additions and 20 deletions
|
@ -759,20 +759,24 @@ module Asn = struct
|
||||||
let console_of_cs, console_to_cs = projections_of console
|
let console_of_cs, console_to_cs = projections_of console
|
||||||
end
|
end
|
||||||
|
|
||||||
|
(* NOTE: this function is duplicatedi in lib/model.ml *)
|
||||||
let console_of_string data =
|
let console_of_string data =
|
||||||
let lines = String.split_on_char '\n' data in
|
|
||||||
(* remove last empty line *)
|
(* remove last empty line *)
|
||||||
let lines =
|
let data =
|
||||||
match List.rev lines with
|
if String.ends_with ~suffix:"\n" data then
|
||||||
| "" :: lines -> List.rev lines
|
String.sub data 0 (String.length data - 2)
|
||||||
| _ -> lines
|
else data
|
||||||
in
|
in
|
||||||
|
let lines = String.split_on_char '\n' data in
|
||||||
List.map (fun line ->
|
List.map (fun line ->
|
||||||
match String.split_on_char ':' line with
|
match String.index line ':' with
|
||||||
| ts :: tail ->
|
| i ->
|
||||||
let delta = float_of_string (String.sub ts 0 (String.length ts - 1)) in
|
(* the timestamp is of the form "%fs", e.g. 0.867s; so chop off the 's' *)
|
||||||
Int64.to_int (Duration.of_f delta), String.concat ":" tail
|
let delta = float_of_string (String.sub line 0 (i - 1)) in
|
||||||
| _ -> assert false)
|
let delta = Int64.to_int (Duration.of_f delta) in
|
||||||
|
let line = String.sub line i (String.length line - i) in
|
||||||
|
delta, line
|
||||||
|
| exception Not_found -> assert false)
|
||||||
lines
|
lines
|
||||||
|
|
||||||
let extract_full () datadir dest uuid =
|
let extract_full () datadir dest uuid =
|
||||||
|
|
24
lib/model.ml
24
lib/model.ml
|
@ -524,20 +524,24 @@ let add_build
|
||||||
Unix.closedir dh;
|
Unix.closedir dh;
|
||||||
Lwt.return (Ok ())
|
Lwt.return (Ok ())
|
||||||
|
|
||||||
|
(* NOTE: this function is duplicatedi in bin/builder_db_app.ml *)
|
||||||
let console_of_string data =
|
let console_of_string data =
|
||||||
let lines = String.split_on_char '\n' data in
|
|
||||||
(* remove last empty line *)
|
(* remove last empty line *)
|
||||||
let lines =
|
let data =
|
||||||
match List.rev lines with
|
if String.ends_with ~suffix:"\n" data then
|
||||||
| "" :: lines -> List.rev lines
|
String.sub data 0 (String.length data - 2)
|
||||||
| _ -> lines
|
else data
|
||||||
in
|
in
|
||||||
|
let lines = String.split_on_char '\n' data in
|
||||||
List.map (fun line ->
|
List.map (fun line ->
|
||||||
match String.split_on_char ':' line with
|
match String.index line ':' with
|
||||||
| ts :: tail ->
|
| i ->
|
||||||
let delta = float_of_string (String.sub ts 0 (String.length ts - 1)) in
|
(* the timestamp is of the form "%fs", e.g. 0.867s; so chop off the 's' *)
|
||||||
Int64.to_int (Duration.of_f delta), String.concat ":" tail
|
let delta = float_of_string (String.sub line 0 (i - 1)) in
|
||||||
| _ -> assert false)
|
let delta = Int64.to_int (Duration.of_f delta) in
|
||||||
|
let line = String.sub line i (String.length line - i) in
|
||||||
|
delta, line
|
||||||
|
| exception Not_found -> assert false)
|
||||||
lines
|
lines
|
||||||
|
|
||||||
let exec_of_build datadir uuid (module Db : CONN) =
|
let exec_of_build datadir uuid (module Db : CONN) =
|
||||||
|
|
Loading…
Reference in a new issue