Forráskód Böngészése

Humble beginnings

Billy Barrow 1 hónapja
szülő
commit
cfabe7d47a

+ 1 - 0
examples/composition

@@ -0,0 +1 @@
+{"name": "Astrologue", "key": "q3FWBWxnjUFhbhFyLmr0ChEXg4/977H+Zo+p5G4Kw8o=", "uris": ["https://astrologue.nz"]}

+ 86 - 0
src/cli/Cli.vala

@@ -0,0 +1,86 @@
+
+public static int main(string[] args) {
+
+    if(args.length < 2) {
+        usage();
+        return 255;
+    }
+
+    var command = args[1];
+    if(command == "check") {
+        if(args.length != 3) {
+            check_usage();
+            return 255;
+        }
+        if(args[2] != "current" && args[2] != "latest") {
+            check_usage();
+            return 255;
+        }
+
+        return do_check(args[2]);
+    }
+    if(command == "repair") {
+        return do_repair();
+    }
+    if(command == "refresh") {
+        return do_refresh();
+    }
+    if(command == "apply") {
+        return do_apply();
+    }
+
+
+    usage();
+    return 255;
+}
+
+private void usage() {
+    printerr("USAGE:\n\tbinman check\n\tbinman repair\n\tbinman refresh\n\tbinman apply\n");
+}
+
+private void check_usage() {
+    printerr("USAGE:\n\tbinman check current\n\tbinman check latest\n");
+}
+
+private int do_check(string type) {
+    //  var applicator = new Binman.Applicator(Binman.ApplicationType.get_mapper().materialise(type));
+    //  var files = applicator.get_file_details();
+    return -1;
+}
+
+private int do_repair() {
+    return -1;
+}
+
+private string last_refresh_component_name;
+private int do_refresh() {
+    try {
+        print(@"0.00% - Reading composition...\r");
+        var refresher = new Binman.Updater();
+        var components = Binman.get_composition();
+        last_refresh_component_name = "";
+        refresher.progress_updated.connect((cn, cc, ct, bd, bt) => {
+            if(last_refresh_component_name != cn) {
+                print("\n");
+            }
+            var frac = ((float)cc) / ((float)ct);
+            if(bt != null) {
+                frac += (((float)bd) / ((float)bt) * (1.0f / (float)ct));
+            }
+
+            print(@"$(frac.to_string("%.2f"))% - Downloading manifest $(cn)\r");
+        });
+        refresher.update(components.to_series());
+        print("\nComplete!\n");
+    }
+    catch(Error e) {
+        printerr(@"Failed to refresh manifests: $(e.message)\n");
+        return e.code;
+    }
+
+    return 0;
+}
+
+private int do_apply() {
+    return -1;
+}

+ 7 - 0
src/cli/meson.build

@@ -0,0 +1,7 @@
+
+sources = files('Cli.vala')
+
+ deps = dependencies
+ deps += binman_dep
+
+executable('binman', sources, dependencies: deps, install: true)

+ 1 - 1
src/lib/Composition.vala

@@ -18,7 +18,7 @@ namespace Binman {
             return PropertyMapper.build_for<CompositionComponent>(cfg => cfg
                 .map<string>("name", o => o.name, (o, v) => o.name = v)
                 .map<string>("key", o => o.key.to_base64(), (o, v) => o.key = new BinaryData.from_base64(v))
-                .map_many<string>("uris", o => o.uris, (o, v) => o.uris.to_vector())
+                .map_many<string>("uris", o => o.uris, (o, v) => o.uris = v.to_vector())
                 .set_constructor(() => new CompositionComponent())
             );
         }

+ 6 - 2
src/lib/ManifestUpdater.vala

@@ -5,10 +5,14 @@ namespace Binman {
 
     public class Updater {
 
+        public signal void progress_updated(string component_name, int current_component, int total_components, int64 bytes_downloaded, int64? bytes_total);
+
         public void update(Enumerable<CompositionComponent>? components = null) throws Error{
             var comps = components ?? get_composition().to_series();
 
-            foreach (var component in comps) {
+            foreach (var component_item in comps.with_positions()) {
+                var component = component_item.item;
+                progress_updated(component.name, component_item.position, comps.count(), 0, null);
                 var folder = File.new_build_filename("/var/binman/", component.name);
                 if(!folder.query_exists()) {
                     folder.make_directory_with_parents();
@@ -20,7 +24,7 @@ namespace Binman {
                     min_serial = new ManifestFile(latest_syml).read_header().serial;
                 }
 
-                download_manifest(component, min_serial, null);
+                download_manifest(component, min_serial, (c, t) => progress_updated(component.name, component_item.position, comps.count(), c, t));
             }
 
         }

+ 1 - 1
src/meson.build

@@ -2,4 +2,4 @@ project('Binman', 'vala', 'c')
 vapi_dir = meson.current_source_dir() / 'vapi'
 
 subdir('lib')
-# subdir('cli')
+subdir('cli')