RooTicket.vala
[gitlive] / GitMonitor.vala
index bf890be..ef2bdca 100644 (file)
@@ -21,12 +21,13 @@ public class GitMonitorQueue : MonitorNamePathDir {
                        
                        var vpath_ar = this.dir.substring(GitMonitor.gitlive.length +1).split("/", 0);
                        
-                       if (vpath_ar[0].length < 1) {
+                       if (vpath_ar.length < 1 || vpath_ar[0].length < 1) {
 
                                this.gitpath = "";
                                this.vdir = "";
                                this.vname = "";
-                       }        
+                               return;
+                       }         
 
 
                        this.gitpath = GitMonitor.gitlive + "/" + vpath_ar[0];
@@ -39,6 +40,8 @@ public class GitMonitorQueue : MonitorNamePathDir {
                        this.vdir =  string.joinv("/", vpath);
 
                        this.vname =  this.vdir + (this.vdir.length > 0 ? "/" : "") + this.name;
+                       
+                        
 /*
                        stdout.printf(
                                        "NEW GitMonitorQueue\nname: %s\npath: %s\ndir: %s\n" + 
@@ -56,30 +59,39 @@ public class GitMonitorQueue : MonitorNamePathDir {
                public bool shouldIgnore()
                {
                        
-                        
                        // vim.. what a seriously brain dead program..
                        if (this.name == "4913") {
+                               GLib.debug("ignore name = 4913");
                                return true;
                        }
+                        
                        
                        if (this.name[0] == '.') {
                                // except!
                                if (this.name == ".htaccess") {
+                                       
                                        return false;
                                }
-                               
+                               if (this.name == ".gitignore") {
+                                       return false;
+                               }
+                               GLib.debug("ignore name starts with dot %s", this.name);
                                return true;
                        }
                        
+                       
                        if (this.name[this.name.length -1] == '~') {
+                               GLib.debug("ignore name ends with ~");
                                return true;
                        }
                        // netbeans / android studio.. silly temp files..
                        
                        if (Regex.match_simple("___jb_old___$", this.name)) {
+                               GLib.debug("ignore name includes jb_old");
                            return true;
                        }
                        if (Regex.match_simple("___jb_bak___$", this.name)) {
+                               GLib.debug("ignore name includes jb_bkc");
                            return true;
                        }
                        //if (f.name.match(/^nbproject/)) {
@@ -87,6 +99,7 @@ public class GitMonitorQueue : MonitorNamePathDir {
                        //}
                        // ignore anything in top level!!!!
                        if (this.gitpath.length < 1) {
+                               GLib.debug("ignore gitpath length is empty");
                                return true;
                        }
                        
@@ -172,11 +185,44 @@ 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, 500, () => {
+                       
+                       //GLib.debug("TIMEOUT queue length = %d, is_runing = %s\n", (int)this.queue.length , this.queueRunning ? "Y" : "N");
+
+                       //stdout.printf("QL %u: QR: %d\n", this.queue.length, this.queueRunning ? 1 : 0);
+                       if (this.queue.length < 1  || this.queueRunning) {
+                               return true;
+                       }
+                       
+                       var last = -1 * this.lastAdd.difference(new DateTime.now(new TimeZone.local()));
+                       // stdout.printf("LAST RUN: %s (expect %s) \n" ,
+                       //         last.to_string(),   (5 * TimeSpan.SECOND).to_string() );
+                       if (last < 5 * TimeSpan.SECOND) { // wait 5 seconds before running. ????
+                               return true;
+                       }
+                       //_this.lastAdd = new Date();
+                       //return 1;
+               
+                       this.runQueue();
+                       return true; //
+               });
+               
+               
        }
 
        public new void pauseError(string failure) 
@@ -191,13 +237,41 @@ 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, "phone-outgoing-busy");
+        props.sets (Canberra.PROP_EVENT_DESCRIPTION, "Gitlive stopped on error");
+
+        context.play_full (0, props, null);
+
+
+                       
        
                this.paused = true;
+               this.queueRunning = false;
                // what does this do to the old one...
                this.queue = new Array<GitMonitorQueue> ();
                this.stop();
                StatusIconA.statusicon.pauseError();
+               
+               var m = new Gtk.MessageDialog(null, Gtk.DialogFlags.MODAL,Gtk.MessageType.ERROR,Gtk.ButtonsType.CLOSE,
+                       "A Serious problem occured running git, you will probably have to resolve this manually\n" + 
+                       "Committing is paused now, so fix the problem, close this window, then press start again\n\n\n" + 
+                       failure
+               );
+               m.set_keep_above(true);
+               m.show();
+               m.set_position(Gtk.WindowPosition.CENTER);
+               m.response.connect( (id_pressed) => {
+                       m.hide();
+               });
+               
        }
  
        public new void pause() {
@@ -208,6 +282,7 @@ public class GitMonitor : Monitor
 
        }
        
+       /*
        public new void resume () {
                this.paused = false;
                this.queue = new Array<GitMonitorQueue> ();
@@ -215,12 +290,14 @@ public class GitMonitor : Monitor
                
                
        }
+       */
        /**
         * Start the monitoring
         * and run the queue every 500 milliseconds..
         *
         */
-       public new void start() {
+       public new void start() 
+       {
                StatusIconA.statusicon.refreshing();
                
                 
@@ -234,7 +311,7 @@ public class GitMonitor : Monitor
                                this.monitor(this.top.index(i) );
                        }
                        StatusIconA.statusicon.resume();
-                        
+                   this.paused = false;
                   
                        
                        try {
@@ -249,35 +326,14 @@ 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",e.message);
                        }
                        return false; // do not keep doing this..
 
                });
                
 
-               Timeout.add_full(Priority.LOW, 1000, () => {
-                       //TIMEOUT", _this.queue.length , _this.queueRunning].join(', '));
-
-                       //stdout.printf("QL %u: QR: %d\n", this.queue.length, this.queueRunning ? 1 : 0);
-                       if (this.queue.length < 1  || this.queueRunning) {
-                               return true;
-                       }
-                       
-                       var last = -1 * this.lastAdd.difference(new DateTime.now(new TimeZone.local()));
-                       // stdout.printf("LAST RUN: %s (expect %s) \n" ,
-                       //         last.to_string(),   (5 * TimeSpan.SECOND).to_string() );
-                       if (last < 5 * TimeSpan.SECOND) { // wait 5 seconds before running. ????
-                               return true;
-                       }
-                       //_this.lastAdd = new Date();
-                       //return 1;
                
-                       this.runQueue();
-                       return true; //
-               });
                 
        }
 
@@ -331,7 +387,7 @@ public class GitMonitor : Monitor
                if (this.paused) {
                        return;
                }
-               print("GitMonitor.runQueue\n");
+               GLib.debug("GitMonitor.runQueue\n");
 
                this.queueRunning = true;
 
@@ -359,21 +415,21 @@ public class GitMonitor : Monitor
 
                this.paused = true;
 
-               print("GitMonitor.runQueue - creating repos\n");
+               GLib.debug("GitMonitor.runQueue - creating repos");
                
                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", 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", ix);
 
                        //if (typeof(repo_list[gitpath]) == 'undefined') {
                        //    repo_list[gitpath] = new imports.Scm.Git.Repo.Repo( { repopath : gitpath });
@@ -386,7 +442,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");
                
                for(var i = 0;i < repo_list.length;i++) {
         
@@ -401,6 +457,10 @@ public class GitMonitor : Monitor
                        for(var ii = 0;ii < repo.cmds.length;ii++) {
                                var cmd = repo.cmds.index(ii);
        
+                               if (repo.is_ignore(cmd.vname)) {
+                                       continue;
+                               }
+       
                                
                                switch(cmd.action) {
                                        case "add" :
@@ -437,8 +497,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", GitMonitorQueue.queueArrayToString(add_files));
+                       GLib.debug( "REMOVE FILES: %s", GitMonitorQueue.queueArrayToString(remove_files));
                        
                        //repo.debug = 1;
                        // these can fail... at present... as we wildcard stuff.
@@ -483,13 +543,20 @@ 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", GitMonitorQueue.queueArrayToString(add_files_f));
+                       GLib.debug( "REMOVE FILES: %s", GitMonitorQueue.queueArrayToString(remove_files_f));
+                   
+                   if (add_files_f.length < 1 && remove_files_f.length < 1) {
+                               continue;
+                   }
+                   
                        // make sure monitoring is paused so it does not recursively pick up
                        // deletions
+                       this.paused = true; 
+                         
+                         
                        try {
+                               
                                repo.pull();
                        } catch(Error e) {
                                this.pauseError(e.message);
@@ -497,8 +564,7 @@ public class GitMonitor : Monitor
                                //print("Pull failed:\n");
                                return;
                        }
-                       
-                       
+                                                                       
                        // -- DO STUFF..            
                        try {
                                repo.add(add_files_f);
@@ -506,7 +572,7 @@ public class GitMonitor : Monitor
                                this.pauseError(e.message);
                                return;
                                failure +=  e.message;
-                               print("Add failed:\n");
+                               GLib.debug("Add failed:");
                        }  
                        try {
                                 repo.remove(remove_files_f);
@@ -514,12 +580,10 @@ public class GitMonitor : Monitor
                                this.pauseError(e.message);
                                return;
                                failure +=  e.message;
-                               print("Remove failed:\n");
+                               GLib.debug("Remove failed:");
                        }  
 
-                       this.paused = false;
-                       
-                       
+
                        try { 
                                success += repo.commit(
                                        GitMonitorQueue.messageToString(messages),
@@ -528,12 +592,27 @@ public class GitMonitor : Monitor
                                success += repo.push();
 
                        } catch(Error e) {
+                       
+                               // 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",e.message);
+                                       success += e.message;
+                                       this.paused = false; 
+                                       continue;
+                               }
+                               
+                       
+                       
+                               this.paused = false;                    
                                this.pauseError(e.message);
+                               
                                return;
-                               failure += e.message;
-                               print("Push failed:\n");
+                               //failure += e.message;
+                               //print("Push failed:\n");
                                
                        }   
+                       this.paused = false;                                            
                }
                
                
@@ -561,7 +640,7 @@ public class GitMonitor : Monitor
                        //      this.pauseError();   
                        //}
                } catch(Error e) {
-                       print(e.message);
+                       GLib.debug(e.message);
                        
                }
                this.queueRunning = false;
@@ -582,7 +661,7 @@ public class GitMonitor : Monitor
 
        public override  void onChanged(MonitorNamePathDir src) 
        { 
-               print("GitMonitor.onChanged\n");        
+               //print("GitMonitor.onChanged\n");        
                return; // always ignore this..?
                //this.parsePath(src);
        }
@@ -595,19 +674,19 @@ public class GitMonitor : Monitor
         */
        public override void onChangesDoneHint(MonitorNamePathDir src)  
        { 
-               print("GitMonitor.onChangedHint\n");        
+
                if (this.paused) {
                        return;
                }
-                       
+               GLib.debug("GitMonitor.onChangedHint");                         
 
                this.lastAdd = new DateTime.now(new TimeZone.local()); 
                var cmd = new GitMonitorQueue(src);
                if (cmd.shouldIgnore()) {
+                       GLib.debug("GitMonitor.onChangedHint - ignored");
                        return;
                }
                
-          
                //var add_it = false;
                /*
                if (this.is_just_created(cmd.path)) {
@@ -636,10 +715,11 @@ public class GitMonitor : Monitor
        }
        public override  void onDeleted(MonitorNamePathDir src) 
    { 
-               print("GitMonitor.onDeleted\n");        
+
                if (this.paused) {
                        return;
                }
+               GLib.debug("GitMonitor.onDeleted");                     
                this.lastAdd = new DateTime.now(new TimeZone.local()); 
                var cmd = new GitMonitorQueue(src);
                if (cmd.shouldIgnore()) {
@@ -659,10 +739,11 @@ public class GitMonitor : Monitor
  
        }
        public override  void onCreated(MonitorNamePathDir src) {
-               print("GitMonitor.onCreated\n");        
+
                if (this.paused) {
                        return;
                }
+               GLib.debug("GitMonitor.onCreated");                     
                this.lastAdd = new DateTime.now(new TimeZone.local()); 
                var cmd = new GitMonitorQueue(src);
                if (cmd.shouldIgnore()) {
@@ -689,10 +770,11 @@ public class GitMonitor : Monitor
        }
 
        public  override void onAttributeChanged(MonitorNamePathDir src) { 
-               print("GitMonitor.onAttributeChanged\n");        
+
                if (this.paused) {
                        return;
                }
+               GLib.debug("GitMonitor.onAttributeChanged %s", src.name);                       
                if (src.dir == GitMonitor.gitlive) {
                   return; // attribute on top level..
                }
@@ -713,10 +795,11 @@ public class GitMonitor : Monitor
  
    public  override void onMoved(MonitorNamePathDir src,MonitorNamePathDir dest)  
        { 
-               print("GitMonitor.onMoved\n");        
+
                if (this.paused) {
                        return;
                }
+               GLib.debug("GitMonitor.onMoved");                       
                this.lastAdd = new DateTime.now(new TimeZone.local()); 
                var cmd_s = new GitMonitorQueue(src);
 
@@ -746,13 +829,13 @@ public class GitMonitor : Monitor
                }
                
                
-               print("RM: %s\n", cmd_s.vname);
+               GLib.debug("RM: %s", cmd_s.vname);
                cmd_s.action = "rm";
                this.queue.append_val(cmd_s);
 
                
                
-               print("ADD: %s\n", cmd_d.vname);
+               GLib.debug("ADD: %s", cmd_d.vname);
                cmd_d.action = "add";
                this.queue.append_val(cmd_d);