GitMonitor.vala
[gitlive] / GitMonitor.vala
index 9dcb246..e74ae7e 100644 (file)
@@ -58,7 +58,7 @@ public class GitMonitorQueue : MonitorNamePathDir {
                public bool shouldIgnore()
                {
                        
-                        
+                
                        // vim.. what a seriously brain dead program..
                        if (this.name == "4913") {
                                return true;
@@ -69,10 +69,13 @@ public class GitMonitorQueue : MonitorNamePathDir {
                                if (this.name == ".htaccess") {
                                        return false;
                                }
-                               
+                               if (this.name == ".gitignore") {
+                                       return false;
+                               }
                                return true;
                        }
                        
+                       
                        if (this.name[this.name.length -1] == '~') {
                                return true;
                        }
@@ -174,12 +177,19 @@ public class GitMonitor : Monitor
        public bool queueRunning = false;
        
        public DateTime lastAdd;
-        
-       
+
+
        public GitMonitor () {
+       
+       
+       
                this.queue = new Array<GitMonitorQueue>();
                GitMonitor.gitmonitor = this;
                
+
+               
                Timeout.add_full(Priority.LOW, 1000, () => {
                        
                        //print("TIMEOUT queue length = %d, is_runing = %s\n", (int)this.queue.length , this.queueRunning ? "Y" : "N");
@@ -220,7 +230,19 @@ public class GitMonitor : Monitor
                notification.set_timeout(60); // show errros for longer
                notification.show();
                
-               
+        Canberra.Context context;
+        Canberra.Proplist props;
+
+        Canberra.Context.create (out context);
+        Canberra.Proplist.create (out props);
+
+        props.sets (Canberra.PROP_EVENT_ID, "gitlive-error");
+        props.sets (Canberra.PROP_EVENT_DESCRIPTION, "Gitlive stopped on error");
+        props.sets (Canberra.PROP_CANBERRA_CACHE_CONTROL, "permanent");
+        props.sets (Canberra.PROP_MEDIA_ROLE, "event");
+
+        context.play_full (0, props, null);
+
 
                        
        
@@ -297,7 +319,7 @@ public class GitMonitor : Monitor
                                notification.set_timeout(5);
                                notification.show();
                        } catch(Error e) {
-                               print("Error %s\n",e.message);
+                               GLib.debug("Error sending notification to screen: %s\n",e.message);
                        }
                        return false; // do not keep doing this..
 
@@ -358,7 +380,7 @@ public class GitMonitor : Monitor
                if (this.paused) {
                        return;
                }
-               print("GitMonitor.runQueue\n");
+               GLib.debug("GitMonitor.runQueue\n");
 
                this.queueRunning = true;
 
@@ -386,21 +408,21 @@ public class GitMonitor : Monitor
 
                this.paused = true;
 
-               print("GitMonitor.runQueue - creating repos\n");
+               GLib.debug("GitMonitor.runQueue - creating repos\n");
                
                for(var i = 0; i < cmds.length; i++) {
                   
                        var cmd = cmds.index(i);
                
                        var gitpath = cmd.gitpath; 
-                       stdout.printf("GitMonitor.runQueue - finding %s\n", cmd.gitpath);
+                       GLib.debug("GitMonitor.runQueue - finding %s\n", cmd.gitpath);
                
                        var ix  = GitRepo.indexOf(repo_list,  cmd.gitpath);
                        if (ix < 0) {
                                repo_list.append_val(new GitRepo( gitpath ));
                                ix = GitRepo.indexOf(repo_list,  cmd.gitpath);
                        }
-                       stdout.printf("GitMonitor.runQueue - adding to repolist %d\n", ix);
+                       GLib.debug("GitMonitor.runQueue - adding to repolist %d\n", ix);
 
                        //if (typeof(repo_list[gitpath]) == 'undefined') {
                        //    repo_list[gitpath] = new imports.Scm.Git.Repo.Repo( { repopath : gitpath });
@@ -413,7 +435,7 @@ public class GitMonitor : Monitor
                this.paused = false;
                // build add, remove and commit message list..
 
-               print("GitMonitor.runQueue - creating actions\n");
+               GLib.debug("GitMonitor.runQueue - creating actions\n");
                
                for(var i = 0;i < repo_list.length;i++) {
         
@@ -468,8 +490,8 @@ public class GitMonitor : Monitor
                                                break;
                                } 
                        }
-                       print( "ADD : %s\n", GitMonitorQueue.queueArrayToString(add_files));
-                       print( "REMOVE FILES: %s\n", GitMonitorQueue.queueArrayToString(remove_files));
+                       GLib.debug( "ADD : %s\n", GitMonitorQueue.queueArrayToString(add_files));
+                       GLib.debug( "REMOVE FILES: %s\n", GitMonitorQueue.queueArrayToString(remove_files));
                        
                        //repo.debug = 1;
                        // these can fail... at present... as we wildcard stuff.
@@ -514,8 +536,8 @@ public class GitMonitor : Monitor
                                add_files_f.append_val(add_files.index(ii));
                        };
                        
-                       print( "ADD : %s\n", GitMonitorQueue.queueArrayToString(add_files_f));
-                       print( "REMOVE FILES: %s\n", GitMonitorQueue.queueArrayToString(remove_files_f));
+                       GLib.debug( "ADD : %s\n", GitMonitorQueue.queueArrayToString(add_files_f));
+                       GLib.debug( "REMOVE FILES: %s\n", GitMonitorQueue.queueArrayToString(remove_files_f));
                    
                    if (add_files_f.length < 1 && remove_files_f.length < 1) {
                                continue;
@@ -525,6 +547,7 @@ public class GitMonitor : Monitor
                        // deletions
                        this.paused = true; 
                          
+                         
                        try {
                                
                                repo.pull();
@@ -534,8 +557,7 @@ public class GitMonitor : Monitor
                                //print("Pull failed:\n");
                                return;
                        }
-                       
-                                               
+                                                                       
                        // -- DO STUFF..            
                        try {
                                repo.add(add_files_f);
@@ -543,7 +565,7 @@ public class GitMonitor : Monitor
                                this.pauseError(e.message);
                                return;
                                failure +=  e.message;
-                               print("Add failed:\n");
+                               GLib.debug("Add failed:\n");
                        }  
                        try {
                                 repo.remove(remove_files_f);
@@ -551,7 +573,7 @@ public class GitMonitor : Monitor
                                this.pauseError(e.message);
                                return;
                                failure +=  e.message;
-                               print("Remove failed:\n");
+                               GLib.debug("Remove failed:\n");
                        }  
 
 
@@ -566,9 +588,10 @@ public class GitMonitor : Monitor
                        
                                // if the error is 'nothing to commit, working tree clean'
                                // then it's not an error, - just continue;
-                               
                                if (/nothing to commit, working tree clean/.match(e.message)) {
+                                       GLib.debug("%s\n",e.message);
                                        success += e.message;
+                                       this.paused = false; 
                                        continue;
                                }
                                
@@ -610,7 +633,7 @@ public class GitMonitor : Monitor
                        //      this.pauseError();   
                        //}
                } catch(Error e) {
-                       print(e.message);
+                       GLib.debug(e.message);
                        
                }
                this.queueRunning = false;
@@ -648,7 +671,7 @@ public class GitMonitor : Monitor
                if (this.paused) {
                        return;
                }
-               print("GitMonitor.onChangedHint\n");                            
+               GLib.debug("GitMonitor.onChangedHint\n");                               
 
                this.lastAdd = new DateTime.now(new TimeZone.local()); 
                var cmd = new GitMonitorQueue(src);
@@ -689,7 +712,7 @@ public class GitMonitor : Monitor
                if (this.paused) {
                        return;
                }
-               print("GitMonitor.onDeleted\n");                        
+               GLib.debug("GitMonitor.onDeleted\n");                   
                this.lastAdd = new DateTime.now(new TimeZone.local()); 
                var cmd = new GitMonitorQueue(src);
                if (cmd.shouldIgnore()) {
@@ -713,7 +736,7 @@ public class GitMonitor : Monitor
                if (this.paused) {
                        return;
                }
-               print("GitMonitor.onCreated\n");                        
+               GLib.debug("GitMonitor.onCreated\n");                   
                this.lastAdd = new DateTime.now(new TimeZone.local()); 
                var cmd = new GitMonitorQueue(src);
                if (cmd.shouldIgnore()) {
@@ -744,7 +767,7 @@ public class GitMonitor : Monitor
                if (this.paused) {
                        return;
                }
-               print("GitMonitor.onAttributeChanged\n");                       
+               GLib.debug("GitMonitor.onAttributeChanged\n");                  
                if (src.dir == GitMonitor.gitlive) {
                   return; // attribute on top level..
                }
@@ -769,7 +792,7 @@ public class GitMonitor : Monitor
                if (this.paused) {
                        return;
                }
-               print("GitMonitor.onMoved\n");                  
+               GLib.debug("GitMonitor.onMoved\n");                     
                this.lastAdd = new DateTime.now(new TimeZone.local()); 
                var cmd_s = new GitMonitorQueue(src);
 
@@ -799,13 +822,13 @@ public class GitMonitor : Monitor
                }
                
                
-               print("RM: %s\n", cmd_s.vname);
+               GLib.debug("RM: %s\n", cmd_s.vname);
                cmd_s.action = "rm";
                this.queue.append_val(cmd_s);
 
                
                
-               print("ADD: %s\n", cmd_d.vname);
+               GLib.debug("ADD: %s\n", cmd_d.vname);
                cmd_d.action = "add";
                this.queue.append_val(cmd_d);