GitMonitor.vala
[gitlive] / GitMonitor.vala
index 5a85a27..988a67a 100644 (file)
@@ -1,4 +1,5 @@
 
 
 public class GitMonitorQueue : MonitorNamePathDir {
         // name = basename
@@ -11,7 +12,6 @@ public class GitMonitorQueue : MonitorNamePathDir {
         public string message ; // for commit
         public bool commit_all;
         
-        public string add; // 
 
 
 
@@ -35,12 +35,14 @@ public class GitMonitorQueue : MonitorNamePathDir {
             }
 
             this.vpath =  string.joinv("/", vpath);
+
+            this.vname =  this.vpath + (this.vpath.length > 0 ? "/" : "") + this.name;
             //f.repo = new imports.Scm.Git.Repo({ repopath: f.gitpath })
         
         
         }
 
-        public bool shouldIgnore(GitMonitor gm)
+        public bool shouldIgnore()
         {
             
             
@@ -76,7 +78,7 @@ public class GitMonitorQueue : MonitorNamePathDir {
         
         public static int indexOfAdd( Array<GitMonitorQueue> add_files, string add) {
             for(var i =0; i < add_files.length; i++) {
-                if (add_files.index(i).add == add) {
+                if (add_files.index(i).vname == add) {
                     return i;
                 }
             }
@@ -120,7 +122,7 @@ public class GitMonitor : Monitor
     public DateTime lastAdd;
      
      
-    public void pause() {
+    public new void pause() {
         this.paused = true;
         // what does this do to the old one...
         this.queue = new Array<GitMonitorQueue> ();
@@ -128,7 +130,7 @@ public class GitMonitor : Monitor
 
     }
     
-    public void resume () {
+    public new void resume () {
         this.paused = false;
         this.queue = new Array<GitMonitorQueue> ();
         StatusIconA.statusicon.set_from_stock( Gtk.Stock.MEDIA_PLAY );
@@ -140,13 +142,13 @@ public class GitMonitor : Monitor
      * and run the queue every 500 milliseconds..
      *
      */
-    public void start() {
-        StatusIconA.statusicon.set_from_stock( Gtk.Stock.MEDIA_REFRESH );
+    public new void start() {
+        StatusIconA.statusicon.set_from_stock( Gtk.Stock.REFRESH );
         
          
-        this.lastAdd = new DateTime.now(); 
+        this.lastAdd = new DateTime.now(new TimeZone.local()); 
         
-        Timeout.add_full(GLib.PRIORITY_LOW, 500, () => {
+        Timeout.add_full(Priority.LOW, 500, () => {
 
             // call this.monitor on each of 'top'
             for(int i = 0; i < this.top.length ; i++) {
@@ -156,34 +158,36 @@ public class GitMonitor : Monitor
              
            
             
-            try { 
-                var notification = new Notify.Notification({
+            try {
+
+              
+                var notification = new Notify.Notification(
                     "Git Live",
-                    GitMonitor.gitlive + "\nMonitoring " + _this.monitors.length + " Directories",
+                    "%s\nMonitoring %u Directories".printf(GitMonitor.gitlive, this.monitors.length), 
                      "dialog-information"
-                });
+                );
         
                 notification.set_timeout(5);
                 notification.show();
             } catch(Error e) {
-                print(e.toString());
+                print(e.message);
             }
 
         });
         
-        Timeout.add_full(GLib.PRIORITY_LOW, 1000, () => {
+        Timeout.add_full(Priority.LOW, 1000, () => {
             //TIMEOUT", _this.queue.length , _this.queueRunning].join(', '));
-            if (!_this.queue.length || _this.queueRunning) {
+            if (this.queue.length < 1  || this.queueRunning) {
                 return true;
             }
 
-            var last = this.lastAdd.difference(new DateTime.now());
+            var last = this.lastAdd.difference(new DateTime.now(new TimeZone.local()));
 
             
             //print("LAST RUN?" + last);
             
-            if (last < 5 * Timespan.SECOND) { // wait 1/2 a seconnd before running.
-                return 1;
+            if (last < 5 * TimeSpan.SECOND) { // wait 5 seconds before running. ????
+                return true;
             }
             //_this.lastAdd = new Date();
             //return 1;
@@ -196,20 +200,20 @@ public class GitMonitor : Monitor
     }
 
 
-    public void stop() {
+    public new void stop() {
         StatusIconA.statusicon.set_from_stock( Gtk.Stock.MEDIA_PAUSE );;
         base.stop();
     }
     
     
-    public void monitor (string path,  int depth = 0)
+    public new void monitor (string path,  int depth = 0)
     {
         
         //var depth = typeof(depth) == 'number'  ? depth *1 : 0;
         
          
         // if we are not at top level.. and there is a .git directory  (it's a submodule .. ignore) 
-        if (depth > 1 && GLib.file_test(path + "/.git" , GLib.FileTest.IS_DIR)) {
+        if (depth > 1 && FileUtils.test(path + "/.git" , FileTest.IS_DIR)) {
             return;
         }
         
@@ -249,7 +253,7 @@ public class GitMonitor : Monitor
 
         var cmds = new Array<GitMonitorQueue>();
         for(var i = 0; i < this.queue.length; i++) {
-            cmds.append_val(this.queue.item(i));
+            cmds.append_val(this.queue.index(i));
         }
 
         this.queue = new Array<GitMonitorQueue>();// empty queue!
@@ -257,7 +261,7 @@ public class GitMonitor : Monitor
         
         string[] success = {};
         string[] failure = {};
-        var repos = new Array<GitRepo>(); //??
+       //var repos = new Array<GitRepo>(); //??
         var done = new Array<GitMonitorQueue>();
         
         // first build a array of repo's to work with
@@ -270,12 +274,13 @@ public class GitMonitor : Monitor
         
         for(var i = 0; i < cmds.length; i++) {
            
+            var cmd = cmds.index(i);
         
             var gitpath = cmd.gitpath; 
-            var ix  = GitRepo.indexOf(this.repos,  cmd.gitpath);
+            var ix  = GitRepo.indexOf(repo_list,  cmd.gitpath);
             if (ix < 0) {
                 repo_list.append_val(new GitRepo( gitpath ));
-                ix = GitRepo.indexOf(this.repos,  cmd.gitpath);
+                ix = GitRepo.indexOf(repo_list,  cmd.gitpath);
             }
             
 
@@ -284,7 +289,7 @@ public class GitMonitor : Monitor
             //    repo_list[gitpath].cmds = [];
              //   repo_list[gitpath].pull();
             //}
-            repo_list.item(ix).cmds.append_val(cmd);
+            repo_list.index(ix).cmds.append_val(cmd);
 
         }
         this.paused = false;
@@ -293,7 +298,7 @@ public class GitMonitor : Monitor
         for(var i = 0;i < repo_list.length;i++) {
     
 
-            var repo = repo_list.item(i);
+            var repo = repo_list.index(i);
 
             var add_files = new Array<GitMonitorQueue>();
             var remove_files = new Array<GitMonitorQueue>();
@@ -301,13 +306,13 @@ public class GitMonitor : Monitor
             //print(JSON.stringify(repo.cmds,null,4));
             
             for(var ii = 0;ii < repo.cmds.length;ii++) {
-                var cmd = repo.cmds.item(ii);
+                var cmd = repo.cmds.index(ii);
     
                 
                 switch(cmd.action) {
                     case "add" :
                         
-                        if (GitMonitorQueue.indexOfAdd(add_files, cmd.add) > -1) {
+                        if (GitMonitorQueue.indexOfAdd(add_files, cmd.vname) > -1) {
                            break;
                         }
         
@@ -316,12 +321,12 @@ public class GitMonitor : Monitor
                         break;
                     
                     case "rm":
-                        if (GitMonitorQueue.indexOfAdd(add_files, cmd.rm) > -1 ) {
+                        if (GitMonitorQueue.indexOfAdd(add_files, cmd.vname) > -1 ) {
                            break;
                         }
                         
                         // if file exists, do not try and delete it.
-                        if (GLib.file_test(cmd.rm, GLib.FileTest.EXISTS)) {
+                        if (FileUtils.test(cmd.vname, FileTest.EXISTS)) {
                             break;
                         }
                         
@@ -344,26 +349,34 @@ public class GitMonitor : Monitor
             
             //repo.debug = 1;
             // these can fail... at present... as we wildcard stuff.
-            stdout.printf("ADD : %d files"  , add_files.length);
+            stdout.printf("ADD : %u files"  , add_files.length);
             
             // make sure added files do not get removed..
 
             var remove_files_f = new Array<GitMonitorQueue>();
             for(var ii = 0;ii < remove_files.length;ii++) {
-                if (GitMonitorQueue.indexOfAdd(add_files,  remove_files.item(ii).rm) > -1 ) {
+                if (GitMonitorQueue.indexOfAdd(add_files,  remove_files.index(ii).vname) > -1 ) {
                      continue;
                 }
-                remove_files_f.append_val(remove_files.item(ii));
+                remove_files_f.append_val(remove_files.index(ii));
             };
-            stdout.printf("REMOVE : %d files"  , remove_files.length);
+            stdout.printf("REMOVE : %u files"  , remove_files.length);
              
             // make sure monitoring is paused so it does not recursively pick up
             // deletions
             
             // -- DO STUFF..
-            
-            repo.add(add_files);
-            repo.remove(remove_files_f);
+            try {
+                repo.add(add_files);
+            } catch(Error e) {
+                failure +=  e.message;
+            }  
+            try {
+                 repo.remove(remove_files_f);
+            } catch(Error e) {
+                failure +=  e.message;
+            }  
+
             this.paused = false;
             
             
@@ -384,7 +397,7 @@ public class GitMonitor : Monitor
          
         try {
             // catch notification failures.. so we can carry on..
-            if (success.length) {
+            if (success.length > 0) {
 
                 
                 var notification = new Notify.Notification(
@@ -398,14 +411,14 @@ public class GitMonitor : Monitor
                 notification.show();   
             }
             
-            if (failure.length) {
+            if (failure.length > 0) {
 
-                var notification = new Notify.Notification({
+                var notification = new Notify.Notification(
                     summary: "Git Live ERROR!!",
                     string.joinv("\n",failure),
                     "dialog-information"
                     
-                });
+                );
     
                 notification.set_timeout(5); // show errros for longer
                 notification.show();   
@@ -430,7 +443,7 @@ public class GitMonitor : Monitor
    
 
 
-    public void onChanged(MonitorNamePathDir src) 
+    public new void onChanged(MonitorNamePathDir src) 
     { 
         return; // always ignore this..?
         //this.parsePath(src);
@@ -442,15 +455,15 @@ public class GitMonitor : Monitor
      *  results in  git add  + git commit..
      *
      */
-    public void onChangesDoneHint(MonitorNamePathDir src)  
+    public new void onChangesDoneHint(MonitorNamePathDir src)  
     { 
         
         if (this.paused) {
-            return true;
+            return;
         }
             
 
-        this.lastAdd = new DateTime.now(); 
+        this.lastAdd = new DateTime.now(new TimeZone.local()); 
         var cmd = new GitMonitorQueue(src);
         if (cmd.shouldIgnore()) {
             return;
@@ -473,7 +486,7 @@ public class GitMonitor : Monitor
             return;
         }
         */
-        cmd.add = src.vpath;
+
         this.queue.append_val(cmd);
 
         var cmd = new GitMonitorQueue(src);
@@ -483,12 +496,12 @@ public class GitMonitor : Monitor
  
          
     }
-    public void onDeleted(MonitorNamePathDir src) 
+    public new void onDeleted(MonitorNamePathDir src) 
    { 
         if (this.paused) {
-            return true;
+            return;
         }
-        this.lastAdd = new DateTime.now(); 
+        this.lastAdd = new DateTime.now(new TimeZone.local()); 
         var cmd = new GitMonitorQueue(src);
         if (cmd.shouldIgnore()) {
             return;
@@ -507,18 +520,18 @@ public class GitMonitor : Monitor
         this.queue.append_val(cmd);
  
     }
-    public void onCreated(MonitorNamePathDir src) {
+    public new void onCreated(MonitorNamePathDir src) {
 
         if (this.paused) {
-            return true;
+            return;
         }
-        this.lastAdd = new DateTime.now(); 
+        this.lastAdd = new DateTime.now(new TimeZone.local()); 
         var cmd = new GitMonitorQueue(src);
         if (cmd.shouldIgnore()) {
             return;
         }
 
-        if (!GLib.file_test(src.path, GLib.FileTest.IS_DIR)) {
+        if (!FileUtils.test(src.path, GLib.FileTest.IS_DIR)) {
            // this.just_created[src.path] = true;
             return; // we do not handle file create flags... - use done hint.
         }
@@ -537,18 +550,17 @@ public class GitMonitor : Monitor
 
     }
 
-    public void onAttributeChanged(MonitorNamePathDir src) { 
+    public new void onAttributeChanged(MonitorNamePathDir src) { 
 
         if (this.paused) {
-            return true;
+            return;
         }
-        this.lastAdd = new DateTime.now(); 
+        this.lastAdd = new DateTime.now(new TimeZone.local()); 
         var cmd = new GitMonitorQueue(src);
         if (cmd.shouldIgnore()) {
             return;
         }
         cmd.action = "add";
-        cmd.add = src.vpath;
         this.queue.append_val(cmd);
 
         var cmd = new GitMonitorQueue(src);
@@ -558,9 +570,12 @@ public class GitMonitor : Monitor
     }
 
 
-   public void onMoved(MonitorNamePathDir src,MonitorNamePathDir dest)  
+   public new void onMoved(MonitorNamePathDir src,MonitorNamePathDir dest)  
     { 
-        this.lastAdd = new DateTime.now(); 
+        if (this.paused) {
+            return;
+        }
+        this.lastAdd = new DateTime.now(new TimeZone.local()); 
         var cmd_s = new GitMonitorQueue(src);
 
         var cmd_d = new GitMonitorQueue(src);
@@ -589,14 +604,12 @@ public class GitMonitor : Monitor
         }
         
         cmd_s.action = "rm";
-        cmd_s.rm = src.vpath;
         this.queue.append_val(cmd_s);
 
 
 
 
         cmd_d.action = "add";
-        cmd_d.add = src.vpath;
         this.queue.append_val(cmd_d);