tazlito annotate modules/calc_sizes @ rev 480

Add Italian; make pot; make msgmerge; make clean
author Aleksej Bobylev <al.bobylev@gmail.com>
date Tue Jan 30 11:53:57 2018 +0200 (2018-01-30)
parents 22eaf700fab5
children 37099ca8e3c1
rev   line source
al@416 1 #!/usr/bin/awk -f
al@416 2 # calc_sizes - module of TazLito - SliTaz Live Tool.
al@416 3
al@416 4 # Calculate sizes (estimated) and real packages number (including all dependencies)
al@416 5 # using given extracted flavor and current mirrors.
al@416 6 #
al@416 7 # Input: <unpacked flavor dir> <flavor name> [<output full list file>]
al@416 8 # Output in human readable form:
al@416 9 # <unpacked size> <packed size> <size of ISO> <number of packages>
al@416 10 # File $1/err output: unknown packages
al@416 11 # File $1/warn output: warnings about missing packages
al@416 12 # TODO: use 'equivalent packages' rules
al@416 13
al@417 14 #tokens dir flavor outfile lsdir rootfs_p rootfs_u rootcd_u errfile warnfile root pkgdb loop undigest repos arr pi h2b h i b2h b p mark_deps pkg localdepend localdepends pkgs sizes depends size_u size_p boot_u boot_p num_pkgs size_packed size_unpacked size_iso s
al@417 15
al@416 16 BEGIN {
al@416 17 FS = "\t";
al@416 18 K = 1024; M = K * 1024; G = M * 1024;
al@416 19 dir = ARGV[1]; flavor = ARGV[2]; outfile = ARGV[3];
al@416 20
al@416 21 # Get listing of dir
al@416 22 "ls " dir " | tr '\n' ' '" | getline lsdir;
al@416 23
al@416 24 # Calculate rootfs_p, rootfs_u, and rootcd_u
al@416 25 if (index(lsdir, flavor ".rootfs")) {
al@416 26 "wc -c < " dir "/" flavor ".rootfs" | getline rootfs_p;
al@416 27 "zcat " dir "/" flavor ".rootfs|wc -c" | getline rootfs_u;
al@416 28 }
al@416 29 if (index(lsdir, flavor ".rootcd"))
al@416 30 "zcat " dir "/" flavor ".rootcd | wc -c" | getline rootcd_u;
al@416 31
al@416 32 errfile = dir "/err";
al@416 33 warnfile = dir "/warn";
al@416 34 system("rm " errfile " " warnfile " " outfile " 2>/dev/null");
al@416 35
al@416 36 root = ENVIRON["root"];
al@416 37
al@416 38 # Get list of 'packages.info' lists using priority
al@416 39 pkgdb = root "/var/lib/tazpkg";
al@416 40 "ls " pkgdb " | tr '\n' ' '" | getline lsdir;
al@416 41 if (! index(lsdir, "packages.info"))
al@416 42 "tazpkg recharge --root=" root " >/dev/null 2>&1";
al@416 43 if (index(lsdir, "priority"))
al@416 44 "cat " pkgdb "/priority | tr '\n' ' '" | getline loop;
al@416 45 loop = loop "main";
al@416 46 if (index(lsdir, "undigest"))
al@416 47 "ls " pkgdb "/undigest | tr '\n' ' '" | getline undigest;
al@416 48 loop = loop " " undigest;
al@416 49 split(loop, repos, / +/);
al@416 50 ARGC = 1;
al@416 51 for (i in repos) {
al@416 52 if (repos[i] && ! arr[repos[i]]) {
al@416 53 arr[repos[i]] = 1;
al@416 54 if (repos[i] == "main")
al@416 55 pi = pkgdb "/packages.info";
al@416 56 else
al@416 57 pi = pkgdb "/undigest/" repos[i] "/packages.info";
al@417 58 if (!system("test -e " pi)) {
al@416 59 ARGV[ARGC] = pi;
al@416 60 ARGC ++;
al@416 61 }
al@416 62 }
al@416 63 }
al@416 64 ARGV[ARGC] = dir "/" flavor ".pkglist"; ARGC ++;
al@416 65 }
al@416 66
al@416 67 # Convert human-readable format to bytes
al@416 68 function h2b(h) {
al@416 69 if (h ~ "K") return h * K;
al@416 70 if (h ~ "M") return h * M;
al@416 71 if (h ~ "G") return h * G;
al@416 72 return h;
al@416 73 }
al@416 74
al@416 75 # Convert bytes to human-readable format
al@416 76 function b2h(b, p) {
al@416 77 if (b >= G) { b /= G; p = "G"; }
al@416 78 else if (b >= M) { b /= M; p = "M"; }
al@416 79 else { b /= K; p = "K"; }
al@416 80 if (b >= 100) return sprintf( "%d%s", b, p);
al@416 81 else return sprintf("%.1f%s", b, p);
al@416 82 }
al@416 83
al@416 84 # Mark package with its dependencies (to be processed later)
al@416 85 function mark_deps(pkg, localdepend, localdepends) {
al@416 86 if (sizes[pkg]) {
al@416 87 if (! pkgs[pkg]) {
al@416 88 pkgs[pkg] = sizes[pkg];
al@416 89
al@416 90 if (depends[pkg]) {
al@416 91 split(depends[pkg], localdepends, " ");
al@416 92 # Recursive call
al@416 93 for (localdepend in localdepends)
al@416 94 mark_deps(localdepends[localdepend]);
al@416 95 }
al@416 96 }
al@416 97 } else {
al@416 98 printf " %s\n", $1 >> errfile;
al@416 99 }
al@416 100 }
al@416 101
al@416 102 # Calculate unpacked and packed sizes of /boot
al@416 103 function calc(pkg, size_u, size_p) {
al@416