Skip to content

Commit

Permalink
builder: split Index_parser.index in an own module
Browse files Browse the repository at this point in the history
Move the index and entry definitions in an own Index module, together
with the (previously internal to Index_parser) print_entry debugging
function.
  • Loading branch information
ptoscano committed Jul 28, 2015
1 parent 6a86a3d commit 3b44b7d
Show file tree
Hide file tree
Showing 9 changed files with 186 additions and 139 deletions.
2 changes: 2 additions & 0 deletions builder/Makefile.am
Expand Up @@ -40,6 +40,7 @@ SOURCES_MLI = \
cache.mli \
downloader.mli \
checksums.mli \
index.mli \
index_parser.mli \
ini_reader.mli \
languages.mli \
Expand All @@ -54,6 +55,7 @@ SOURCES_ML = \
pxzcat.ml \
setlocale.ml \
checksums.ml \
index.ml \
ini_reader.ml \
paths.ml \
languages.ml \
Expand Down
36 changes: 18 additions & 18 deletions builder/builder.ml
Expand Up @@ -40,7 +40,7 @@ let remove_duplicates index =
*)
let nseen = Hashtbl.create 13 in
List.iter (
fun (name, { Index_parser.arch = arch; revision = revision }) ->
fun (name, { Index.arch = arch; revision = revision }) ->
let id = name, arch in
try
let rev = Hashtbl.find nseen id in
Expand All @@ -50,7 +50,7 @@ let remove_duplicates index =
Hashtbl.add nseen id revision
) index;
List.filter (
fun (name, { Index_parser.arch = arch; revision = revision }) ->
fun (name, { Index.arch = arch; revision = revision }) ->
let id = name, arch in
try
let rev = Hashtbl.find nseen (name, arch) in
Expand Down Expand Up @@ -165,7 +165,7 @@ let main () =
}
) sources in
let sources = List.append sources repos in
let index : Index_parser.index =
let index : Index.index =
List.concat (
List.map (
fun source ->
Expand All @@ -190,11 +190,11 @@ let main () =
(match cache with
| Some cache ->
let l = List.filter (
fun (_, { Index_parser.hidden = hidden }) ->
fun (_, { Index.hidden = hidden }) ->
hidden <> true
) index in
let l = List.map (
fun (name, { Index_parser.revision = revision; arch = arch }) ->
fun (name, { Index.revision = revision; arch = arch }) ->
(name, arch, revision)
) l in
Cache.print_item_status cache ~header:true l
Expand All @@ -209,7 +209,7 @@ let main () =
| Some _ ->
List.iter (
fun (name,
{ Index_parser.revision = revision; file_uri = file_uri;
{ Index.revision = revision; file_uri = file_uri;
proxy = proxy }) ->
let template = name, arch, revision in
message (f_"Downloading: %s") file_uri;
Expand All @@ -228,7 +228,7 @@ let main () =
try
let item =
List.find (
fun (name, { Index_parser.aliases = aliases }) ->
fun (name, { Index.aliases = aliases }) ->
match aliases with
| None -> false
| Some l -> List.mem arg l
Expand All @@ -237,19 +237,19 @@ let main () =
with Not_found -> arg in
let item =
try List.find (
fun (name, { Index_parser.arch = a }) ->
fun (name, { Index.arch = a }) ->
name = arg && arch = a
) index
with Not_found ->
error (f_"cannot find os-version '%s' with architecture '%s'.\nUse --list to list available guest types.")
arg arch in
let entry = snd item in
let sigchecker = entry.Index_parser.sigchecker in
let sigchecker = entry.Index.sigchecker in

(match mode with
| `Notes -> (* --notes *)
let notes =
Languages.find_notes (Languages.languages ()) entry.Index_parser.notes in
Languages.find_notes (Languages.languages ()) entry.Index.notes in
(match notes with
| notes :: _ ->
print_endline notes
Expand All @@ -267,7 +267,7 @@ let main () =
(* Download the template, or it may be in the cache. *)
let template =
let template, delete_on_exit =
let { Index_parser.revision = revision; file_uri = file_uri;
let { Index.revision = revision; file_uri = file_uri;
proxy = proxy } = entry in
let template = arg, arch, revision in
message (f_"Downloading: %s") file_uri;
Expand All @@ -281,15 +281,15 @@ let main () =
let () =
match entry with
(* New-style: Using a checksum. *)
| { Index_parser.checksums = Some csums } ->
| { Index.checksums = Some csums } ->
Checksums.verify_checksums csums template

| { Index_parser.checksums = None } ->
| { Index.checksums = None } ->
(* Old-style: detached signature. *)
let sigfile =
match entry with
| { Index_parser.signature_uri = None } -> None
| { Index_parser.signature_uri = Some signature_uri } ->
| { Index.signature_uri = None } -> None
| { Index.signature_uri = Some signature_uri } ->
let sigfile, delete_on_exit =
Downloader.download downloader signature_uri in
if delete_on_exit then unlink_on_exit sigfile;
Expand All @@ -303,7 +303,7 @@ let main () =

(* Planner: Input tags. *)
let itags =
let { Index_parser.size = size; format = format } = entry in
let { Index.size = size; format = format } = entry in
let format_tag =
match format with
| None -> []
Expand Down Expand Up @@ -341,7 +341,7 @@ let main () =
b, sz in

let output_size =
let { Index_parser.size = original_image_size } = entry in
let { Index.size = original_image_size } = entry in

let size =
match size with
Expand Down Expand Up @@ -557,7 +557,7 @@ let main () =
let osize = Int64.of_string (List.assoc `Size otags) in
let osize = roundup64 osize 512L in
let oformat = List.assoc `Format otags in
let { Index_parser.expand = expand; lvexpand = lvexpand } = entry in
let { Index.expand = expand; lvexpand = lvexpand } = entry in
message (f_"Resizing (using virt-resize) to expand the disk to %s")
(human_size osize);
let preallocation = if oformat = "qcow2" then Some "metadata" else None in
Expand Down
117 changes: 117 additions & 0 deletions builder/index.ml
@@ -0,0 +1,117 @@
(* virt-builder
* Copyright (C) 2013-2015 Red Hat Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*)

open Common_gettext.Gettext
open Common_utils

open Utils

open Printf
open Unix

type index = (string * entry) list (* string = "os-version" *)
and entry = {
printable_name : string option; (* the name= field *)
osinfo : string option;
file_uri : string;
arch : string;
signature_uri : string option; (* deprecated, will be removed in 1.26 *)
checksums : Checksums.csum_t list option;
revision : int;
format : string option;
size : int64;
compressed_size : int64 option;
expand : string option;
lvexpand : string option;
notes : (string * string) list;
hidden : bool;
aliases : string list option;

sigchecker : Sigchecker.t;
proxy : Downloader.proxy_mode;
}

let print_entry chan (name, { printable_name = printable_name;
file_uri = file_uri;
arch = arch;
osinfo = osinfo;
signature_uri = signature_uri;
checksums = checksums;
revision = revision;
format = format;
size = size;
compressed_size = compressed_size;
expand = expand;
lvexpand = lvexpand;
notes = notes;
aliases = aliases;
hidden = hidden }) =
let fp fs = fprintf chan fs in
fp "[%s]\n" name;
(match printable_name with
| None -> ()
| Some name -> fp "name=%s\n" name
);
(match osinfo with
| None -> ()
| Some id -> fp "osinfo=%s\n" id
);
fp "file=%s\n" file_uri;
fp "arch=%s\n" arch;
(match signature_uri with
| None -> ()
| Some uri -> fp "sig=%s\n" uri
);
(match checksums with
| None -> ()
| Some checksums ->
List.iter (
fun c ->
fp "checksum[%s]=%s\n"
(Checksums.string_of_csum_t c) (Checksums.string_of_csum c)
) checksums
);
fp "revision=%d\n" revision;
(match format with
| None -> ()
| Some format -> fp "format=%s\n" format
);
fp "size=%Ld\n" size;
(match compressed_size with
| None -> ()
| Some size -> fp "compressed_size=%Ld\n" size
);
(match expand with
| None -> ()
| Some expand -> fp "expand=%s\n" expand
);
(match lvexpand with
| None -> ()
| Some lvexpand -> fp "lvexpand=%s\n" lvexpand
);
List.iter (
fun (lang, notes) ->
match lang with
| "" -> fp "notes=%s\n" notes
| lang -> fp "notes[%s]=%s\n" lang notes
) notes;
(match aliases with
| None -> ()
| Some l -> fp "aliases=%s\n" (String.concat " " l)
);
if hidden then fp "hidden=true\n"
41 changes: 41 additions & 0 deletions builder/index.mli
@@ -0,0 +1,41 @@
(* virt-builder
* Copyright (C) 2013-2015 Red Hat Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*)

type index = (string * entry) list (* string = "os-version" *)
and entry = {
printable_name : string option; (* the name= field *)
osinfo : string option;
file_uri : string;
arch : string;
signature_uri : string option; (* deprecated, will be removed in 1.26 *)
checksums : Checksums.csum_t list option;
revision : int;
format : string option;
size : int64;
compressed_size : int64 option;
expand : string option;
lvexpand : string option;
notes : (string * string) list;
hidden : bool;
aliases : string list option;

sigchecker : Sigchecker.t;
proxy : Downloader.proxy_mode;
}

val print_entry : out_channel -> (string * entry) -> unit

0 comments on commit 3b44b7d

Please sign in to comment.