| 1 |
(**************************************************************************) |
| 2 |
(* *) |
| 3 |
(* Copyright 2019 OCamlPro *) |
| 4 |
(* *) |
| 5 |
(* All rights reserved. This file is distributed under the terms of the *) |
| 6 |
(* GNU Lesser General Public License version 2.1, with the special *) |
| 7 |
(* exception on linking described in the file LICENSE. *) |
| 8 |
(* *) |
| 9 |
(**************************************************************************) |
| 10 |
|
| 11 |
(* basic ops *) |
| 12 |
|
| 13 |
type t = string |
| 14 |
|
| 15 |
let of_string s = s |
| 16 |
let to_string s = s |
| 17 |
let compare = OpamStd.String.compare_case |
| 18 |
let equal s r = compare s r = 0 |
| 19 |
|
| 20 |
let to_json s = |
| 21 |
`O [ ("sys_package", `String s) ] |
| 22 |
let of_json = function |
| 23 |
| `O dict -> |
| 24 |
(match OpamStd.List.assoc String.equal "sys_package" dict with |
| 25 |
| `String s -> Some (of_string s) |
| 26 |
| _ -> None |
| 27 |
| exception Not_found -> None) |
| 28 |
| _ -> None |
| 29 |
|
| 30 |
module O = struct |
| 31 |
type tmp = t |
| 32 |
type t = tmp |
| 33 |
let compare = compare |
| 34 |
let to_string = to_string |
| 35 |
let to_json = to_json |
| 36 |
let of_json = of_json |
| 37 |
end |
| 38 |
|
| 39 |
module Set = OpamStd.Set.Make(O) |
| 40 |
|
| 41 |
module Map = OpamStd.Map.Make(O) |
| 42 |
|
| 43 |
let raw_set set = |
| 44 |
OpamStd.String.Set.fold (fun spkg set-> Set.add (of_string spkg) set) |
| 45 |
set Set.empty |
| 46 |
|
| 47 |
type status = |
| 48 |
{ |
| 49 |
s_available : Set.t; |
| 50 |
(** Package available but not installed *) |
| 51 |
|
| 52 |
s_not_found : Set.t; |
| 53 |
(** Package unavailable on this system *) |
| 54 |
} |
| 55 |
|
| 56 |
|
| 57 |
let status_empty = |
| 58 |
{ |
| 59 |
s_available = Set.empty; |
| 60 |
s_not_found = Set.empty; |
| 61 |
} |
| 62 |
|
| 63 |
let string_of_status sp = |
| 64 |
Printf.sprintf "available: %s; not_found: %s" |
| 65 |
(Set.to_string sp.s_available) |
| 66 |
(Set.to_string sp.s_not_found) |