GitMonitor.vala
[gitlive] / GitMonitor.vala
1
2  
3
4 public class GitMonitorQueue : MonitorNamePathDir {
5                 // name = basename
6                 // path = full path..
7                 // dir = dir path
8         
9                 public string gitpath;
10                 public string vdir;  // relative path (within git)
11                 public string vname;  // relative filename (within git)
12                 public string message ; // for commit
13                 public bool commit_all;
14                  
15                 public GitMonitorQueue(MonitorNamePathDir f) {
16
17                         base(f.name, f.path, f.dir);
18  
19                         this.message = "";
20                         this.commit_all = false;
21                         
22                         var vpath_ar = this.dir.substring(GitMonitor.gitlive.length +1).split("/", 0);
23                         
24                         if (vpath_ar[0].length < 1) {
25
26                                 this.gitpath = "";
27                                 this.vdir = "";
28                                 this.vname = "";
29                         }        
30
31
32                         this.gitpath = GitMonitor.gitlive + "/" + vpath_ar[0];
33                         
34                         string[]  vpath = {};
35                         for (var i = 1; i< vpath_ar.length; i++) {
36                                 vpath += vpath_ar[i];
37                         }
38
39                         this.vdir =  string.joinv("/", vpath);
40
41                         this.vname =  this.vdir + (this.vdir.length > 0 ? "/" : "") + this.name;
42                         
43                          
44 /*
45                         stdout.printf(
46                                         "NEW GitMonitorQueue\nname: %s\npath: %s\ndir: %s\n" + 
47                                         "gitpath: %s\nvdir: %s\nvname: %s\n",
48                                         this.name, this.path, this.dir,
49                                         this.gitpath, this.vdir, this.vname
50                         );
51 */
52
53                         //f.repo = new imports.Scm.Git.Repo({ repopath: f.gitpath })
54                 
55                 
56                 }
57
58                 public bool shouldIgnore()
59                 {
60                         
61                  
62                         // vim.. what a seriously brain dead program..
63                         if (this.name == "4913") {
64                                 return true;
65                         }
66                         
67                         if (this.name[0] == '.') {
68                                 // except!
69                                 if (this.name == ".htaccess") {
70                                         return false;
71                                 }
72                                 if (this.name == ".gitignore") {
73                                         return false;
74                                 }
75                                 return true;
76                         }
77                         
78                         
79                         if (this.name[this.name.length -1] == '~') {
80                                 return true;
81                         }
82                         // netbeans / android studio.. silly temp files..
83                         
84                         if (Regex.match_simple("___jb_old___$", this.name)) {
85                             return true;
86                         }
87                         if (Regex.match_simple("___jb_bak___$", this.name)) {
88                             return true;
89                         }
90                         //if (f.name.match(/^nbproject/)) {
91                         //    return true;
92                         //}
93                         // ignore anything in top level!!!!
94                         if (this.gitpath.length < 1) {
95                                 return true;
96                         }
97                         
98                         return false;
99                 }
100                 
101                 /** -- statics --*/
102                 
103                 public static int indexOfAdd( Array<GitMonitorQueue> add_files, string add)
104                 {
105                         for(var i =0; i < add_files.length; i++) {
106                                 if (add_files.index(i).vname == add) {
107                                         return i;
108                                 }
109                         }
110                         return -1;
111                 }
112                 public static  int indexOfMessage(Array<GitMonitorQueue> messages, string message)  {
113                         for(var i =0; i < messages.length; i++) {
114                                 if (messages.index(i).message == message) {
115                                         return i;
116                                 }
117                         }
118                         return -1;
119                 }
120                 public static string messageToString(Array<GitMonitorQueue> messages ) {
121                         string[] ret = {};
122                         for(var i =0; i < messages.length; i++) {
123                                 ret+= messages.index(i).message;
124                         }
125                         return string.joinv("\n",ret);
126                 }
127                 public static string queueArrayToString(Array<GitMonitorQueue> list) {
128                         var ret = "";
129                         for(var i =0; i < list.length; i++) {
130                                 
131                                 ret += (ret.length > 0 ? ", " : "") + list.index(i).vname;
132                         }
133                         return ret;
134                         
135                 }
136                 
137                 public static bool  queueHas(Array<GitMonitorQueue> list , GitMonitorQueue cmd_s, string action) {
138                         for(var i =0; i < list.length; i++) {
139                                 var test = list.index(i);
140                                 if (list.index(i).gitpath != cmd_s.gitpath) {
141                                         continue;
142                                 }
143                                 if (list.index(i).vname != cmd_s.vname) {
144                                         continue;
145                                 }
146                                 if (list.index(i).action != action) {
147                                         continue;
148                                 }
149                                 return true;
150                         }
151                         return false;
152                 }
153                 public string fullpath()
154                 {
155                         return this.gitpath + "/" + this.vname;
156                 }
157                 
158                         
159                         
160 }
161
162
163
164 public class GitMonitor : Monitor
165 {
166
167         public static GitMonitor gitmonitor;
168         /**
169          * @property {String} the "gitlive" directory, normally ~/gitlive
170          *  dset by OWNER... - we should do this as a CTOR.
171          *  
172          */
173         public static string gitlive;
174         
175         
176         public Array<GitMonitorQueue> queue ;
177         public bool queueRunning = false;
178         
179         public DateTime lastAdd;
180          
181         
182         public GitMonitor () {
183                 this.queue = new Array<GitMonitorQueue>();
184                 GitMonitor.gitmonitor = this;
185                 
186                 Timeout.add_full(Priority.LOW, 1000, () => {
187                         
188                         //print("TIMEOUT queue length = %d, is_runing = %s\n", (int)this.queue.length , this.queueRunning ? "Y" : "N");
189
190                         //stdout.printf("QL %u: QR: %d\n", this.queue.length, this.queueRunning ? 1 : 0);
191                         if (this.queue.length < 1  || this.queueRunning) {
192                                 return true;
193                         }
194                         
195                         var last = -1 * this.lastAdd.difference(new DateTime.now(new TimeZone.local()));
196  
197                         // stdout.printf("LAST RUN: %s (expect %s) \n" ,
198                         //         last.to_string(),   (5 * TimeSpan.SECOND).to_string() );
199  
200                         if (last < 5 * TimeSpan.SECOND) { // wait 5 seconds before running. ????
201                                 return true;
202                         }
203                         //_this.lastAdd = new Date();
204                         //return 1;
205                 
206                         this.runQueue();
207                         return true; //
208                 });
209                 
210                 
211         }
212
213         public new void pauseError(string failure) 
214         {
215         
216                 var notification = new Notify.Notification(
217                           "Git Live ERROR!!",
218                         failure,
219                         "dialog-information"
220                         
221                 );
222                         
223                 notification.set_timeout(60); // show errros for longer
224                 notification.show();
225                 
226                 
227
228                         
229         
230                 this.paused = true;
231                 this.queueRunning = false;
232                 // what does this do to the old one...
233                 this.queue = new Array<GitMonitorQueue> ();
234                 this.stop();
235                 StatusIconA.statusicon.pauseError();
236                 
237                 var m = new Gtk.MessageDialog(null, Gtk.DialogFlags.MODAL,Gtk.MessageType.ERROR,Gtk.ButtonsType.CLOSE,
238                         "A Serious problem occured running git, you will probably have to resolve this manually\n" + 
239                         "Committing is paused now, so fix the problem, close this window, then press start again\n\n\n" + 
240                         failure
241                 );
242                 m.set_keep_above(true);
243                 m.show();
244                 m.set_position(Gtk.WindowPosition.CENTER);
245                 m.response.connect( (id_pressed) => {
246                         m.hide();
247                 });
248                 
249         }
250  
251         public new void pause() {
252                 this.paused = true;
253                 // what does this do to the old one...
254                 this.queue = new Array<GitMonitorQueue> ();
255                 StatusIconA.statusicon.pause();
256
257         }
258         
259         /*
260         public new void resume () {
261                 this.paused = false;
262                 this.queue = new Array<GitMonitorQueue> ();
263                 StatusIconA.statusicon.resume();
264                 
265                 
266         }
267         */
268         /**
269          * Start the monitoring
270          * and run the queue every 500 milliseconds..
271          *
272          */
273         public new void start() 
274         {
275                 StatusIconA.statusicon.refreshing();
276                 
277                  
278                 this.lastAdd = new DateTime.now(new TimeZone.local()); 
279                 
280                 Timeout.add_full(Priority.LOW, 500, () => {
281                         //stdout.printf("GitMonitor.start :: top.length = %u\n", this.top.length);
282                         // call this.monitor on each of 'top'
283                         for(int i = 0; i < this.top.length ; i++) {
284
285                                 this.monitor(this.top.index(i) );
286                         }
287                         StatusIconA.statusicon.resume();
288                     this.paused = false;
289                    
290                         
291                         try {
292
293                           
294                                 var notification = new Notify.Notification(
295                                         "Git Live",
296                                         "%s\nMonitoring %u Directories".printf(GitMonitor.gitlive, this.monitors.length), 
297                                          "dialog-information"
298                                 );
299                 
300                                 notification.set_timeout(5);
301                                 notification.show();
302                         } catch(Error e) {
303                                 print("Error %s\n",e.message);
304                         }
305                         return false; // do not keep doing this..
306
307                 });
308                 
309
310                 
311                  
312         }
313
314
315         public new void stop() {
316                 StatusIconA.statusicon.pause();
317                 base.stop();
318         }
319         
320         
321         public new void monitor (string path,  int depth = 0)
322         {
323                 
324                 //var depth = typeof(depth) == 'number'  ? depth *1 : 0;
325                 
326                  
327                 // if we are not at top level.. and there is a .git directory  (it's a submodule .. ignore) 
328                 if (depth > 1 && FileUtils.test(path + "/.git" , FileTest.IS_DIR)) {
329                         return;
330                 }
331                 
332                 if (depth == 1) {
333                         // FIXME - check if repo is flagged as not autocommit..
334                         //var repo = imports.Scm.Repo.Repo.get(path);
335                         //if (!repo || !repo.autocommit()) {
336                         //    return;
337                         //} 
338                 }
339                 
340                 
341                 // check if the repo is to be monitored.
342                 //print("PATH : " + path);
343                 
344                 
345                 base.monitor(path, depth);
346         }
347
348         
349
350         /**
351          * run the queue.
352          * - pulls the items off the queue 
353          *    (as commands run concurrently and new items may get added while it's running)
354          * - runs the queue items
355          * - pushes upstream.
356          * 
357          */
358         public void runQueue()
359         {
360                 
361                 if (this.paused) {
362                         return;
363                 }
364                 print("GitMonitor.runQueue\n");
365
366                 this.queueRunning = true;
367
368                 var cmds = new Array<GitMonitorQueue>();
369
370                 for(var i = 0; i < this.queue.length; i++) {
371                         cmds.append_val(this.queue.index(i));
372                 }
373
374                 this.queue = new Array<GitMonitorQueue>();// empty queue!
375
376                 
377                 string[] success = {};
378                 string[] failure = {};
379            //var repos = new Array<GitRepo>(); //??
380                 //var done = new Array<GitMonitorQueue>();
381                 
382                 // first build a array of repo's to work with
383                 var repo_list = new Array<GitRepo>();
384                 
385                 // pull and group.
386                 
387                 //print(JSON.stringify(cmds));
388                 // make sure nothing get's added to the queue where we are doing this..
389
390                 this.paused = true;
391
392                 print("GitMonitor.runQueue - creating repos\n");
393                 
394                 for(var i = 0; i < cmds.length; i++) {
395                    
396                         var cmd = cmds.index(i);
397                 
398                         var gitpath = cmd.gitpath; 
399                         stdout.printf("GitMonitor.runQueue - finding %s\n", cmd.gitpath);
400                 
401                         var ix  = GitRepo.indexOf(repo_list,  cmd.gitpath);
402                         if (ix < 0) {
403                                 repo_list.append_val(new GitRepo( gitpath ));
404                                 ix = GitRepo.indexOf(repo_list,  cmd.gitpath);
405                         }
406                         stdout.printf("GitMonitor.runQueue - adding to repolist %d\n", ix);
407
408                         //if (typeof(repo_list[gitpath]) == 'undefined') {
409                         //    repo_list[gitpath] = new imports.Scm.Git.Repo.Repo( { repopath : gitpath });
410                         //    repo_list[gitpath].cmds = [];
411                          //   repo_list[gitpath].pull();
412                         //}
413                         repo_list.index(ix).cmds.append_val(cmd);
414
415                 }
416                 this.paused = false;
417                 // build add, remove and commit message list..
418
419                 print("GitMonitor.runQueue - creating actions\n");
420                 
421                 for(var i = 0;i < repo_list.length;i++) {
422          
423                         var repo = repo_list.index(i);
424
425                         var add_files = new Array<GitMonitorQueue>();
426                         var add_files_f = new Array<GitMonitorQueue>();
427                         var remove_files = new Array<GitMonitorQueue>();
428                         var messages = new Array<GitMonitorQueue>();
429                         //print(JSON.stringify(repo.cmds,null,4));
430                         
431                         for(var ii = 0;ii < repo.cmds.length;ii++) {
432                                 var cmd = repo.cmds.index(ii);
433         
434                                 if (repo.is_ignore(cmd.vname)) {
435                                         continue;
436                                 }
437         
438                                 
439                                 switch(cmd.action) {
440                                         case "add" :
441                                                 
442                                                 if (GitMonitorQueue.indexOfAdd(add_files, cmd.vname) > -1) {
443                                                    break;
444                                                 }
445                                                 
446                                                 add_files.append_val(cmd);
447                                                 break;
448                                         
449                                         case "rm":
450                                                 if (GitMonitorQueue.indexOfAdd(remove_files, cmd.vname) > -1 ) {
451                                                    break;
452                                                 }
453                                                 
454                                                 // if file exists, do not try and delete it.
455                                                 if (FileUtils.test(cmd.fullpath(), FileTest.EXISTS)) {
456                                                         break;
457                                                 }
458                                                 
459                                                 remove_files.append_val(cmd);
460                                                 break;
461                                         
462                                         case "commit" :
463                                                 if (GitMonitorQueue.indexOfMessage(messages, cmd.message) > -1 ) {
464                                                    break;
465                                                 }
466                                                 messages.append_val(cmd);
467                                                 
468                                                 break;
469                                         default:
470                                                 stdout.printf("Opps unmatched action %s\n", cmd.action);
471                                                 break;
472                                 } 
473                         }
474                         print( "ADD : %s\n", GitMonitorQueue.queueArrayToString(add_files));
475                         print( "REMOVE FILES: %s\n", GitMonitorQueue.queueArrayToString(remove_files));
476                         
477                         //repo.debug = 1;
478                         // these can fail... at present... as we wildcard stuff.
479                    
480                         // make sure added files do not get removed.. ?? 
481                         /*
482                         var remove_files_f = new Array<GitMonitorQueue>();
483                         for(var ii = 0;ii < remove_files.length;ii++) {
484                                 if (GitMonitorQueue.indexOfAdd(add_files,  remove_files.index(ii).vname) > -1 ) {
485                                          continue;
486                                 }
487                                 remove_files_f.append_val(remove_files.index(ii));
488                         };
489                         stdout.printf("REMOVE : %u files\n"  , remove_files_f.length);
490                         */
491                         
492                         // if file was added, then removed, 
493                         var remove_files_f = new Array<GitMonitorQueue>();
494                         for(var ii = 0;ii < remove_files.length;ii++) {
495                                 
496                                 
497                                 
498                                 if (GitMonitorQueue.indexOfAdd(add_files,  remove_files.index(ii).vname) > -1 ) {
499                                         // in add and remove - do not remvove
500                                         continue;
501                                 }
502                                 remove_files_f.append_val(remove_files.index(ii));
503                         };
504                         for(var ii = 0;ii < add_files.length;ii++) {
505                                 if (GitMonitorQueue.indexOfAdd(remove_files,  add_files.index(ii).vname) > -1 ) {
506                                         // the add file is in the remove list, and it does not exist - do not add it..
507                                         print("check exists ? %s\n",add_files.index(ii).fullpath());
508                                         
509                                         if (!FileUtils.test(add_files.index(ii).fullpath(), FileTest.EXISTS)) {
510                                                         continue;
511                                         }
512                                          
513                                 }
514                                 
515                                 
516                                 
517                                 add_files_f.append_val(add_files.index(ii));
518                         };
519                         
520                         print( "ADD : %s\n", GitMonitorQueue.queueArrayToString(add_files_f));
521                         print( "REMOVE FILES: %s\n", GitMonitorQueue.queueArrayToString(remove_files_f));
522                     
523                     if (add_files_f.length < 1 && remove_files_f.length < 1) {
524                                 continue;
525                     }
526                     
527                         // make sure monitoring is paused so it does not recursively pick up
528                         // deletions
529                         this.paused = true; 
530                           
531                           
532                         try {
533                                 
534                                 repo.pull();
535                         } catch(Error e) {
536                                 this.pauseError(e.message);
537                                 //failure +=  e.message;
538                                 //print("Pull failed:\n");
539                                 return;
540                         }
541                                                                         
542                         // -- DO STUFF..            
543                         try {
544                                 repo.add(add_files_f);
545                         } catch(Error e) {
546                                 this.pauseError(e.message);
547                                 return;
548                                 failure +=  e.message;
549                                 print("Add failed:\n");
550                         }  
551                         try {
552                                  repo.remove(remove_files_f);
553                         } catch(Error e) {
554                                 this.pauseError(e.message);
555                                 return;
556                                 failure +=  e.message;
557                                 print("Remove failed:\n");
558                         }  
559
560
561                         try { 
562                                 success += repo.commit(
563                                         GitMonitorQueue.messageToString(messages),
564                                         add_files_f
565                                 );
566                                 success += repo.push();
567
568                         } catch(Error e) {
569                         
570                                 // if the error is 'nothing to commit, working tree clean'
571                                 // then it's not an error, - just continue;
572                                 if (/nothing to commit, working tree clean/.match(e.message)) {
573                                         print("%s\n",e.message);
574                                         success += e.message;
575                                         this.paused = false; 
576                                         continue;
577                                 }
578                                 
579                         
580                         
581                                 this.paused = false;                    
582                                 this.pauseError(e.message);
583                                 
584                                 return;
585                                 //failure += e.message;
586                                 //print("Push failed:\n");
587                                 
588                         }   
589                         this.paused = false;                                            
590                 }
591                 
592                 
593                 // finally merge all the commit messages.
594                  
595                 try {
596                         // catch notification failures.. so we can carry on..
597                         if (success.length > 0) {
598
599                                 
600                                 var notification = new Notify.Notification(
601                                         "Git Live Commited",
602                                         string.joinv("\n",success),
603                                          "dialog-information"
604                                         
605                                 );
606         
607                                 notification.set_timeout(5);
608                                 notification.show();   
609                         }
610                         
611                         //if (failure.length > 0) {
612
613                                 // should never get this far...
614                         //      this.pauseError();   
615                         //}
616                 } catch(Error e) {
617                         print(e.message);
618                         
619                 }
620                 this.queueRunning = false;
621         }
622         
623
624
625         
626
627         //string[] just_created;
628  
629  
630
631
632
633    
634
635
636         public override  void onChanged(MonitorNamePathDir src) 
637         { 
638                 //print("GitMonitor.onChanged\n");        
639                 return; // always ignore this..?
640                 //this.parsePath(src);
641         }
642         
643
644  
645         /**
646          *  results in  git add  + git commit..
647          *
648          */
649         public override void onChangesDoneHint(MonitorNamePathDir src)  
650         { 
651
652                 if (this.paused) {
653                         return;
654                 }
655                 print("GitMonitor.onChangedHint\n");                            
656
657                 this.lastAdd = new DateTime.now(new TimeZone.local()); 
658                 var cmd = new GitMonitorQueue(src);
659                 if (cmd.shouldIgnore()) {
660                         return;
661                 }
662                 
663            
664                 //var add_it = false;
665                 /*
666                 if (this.is_just_created(cmd.path)) {
667                         
668                 if (typeof(this.just_created[src.path]) !='undefined') {
669                         delete this.just_created[src.path];
670                         
671                         this.queue.push( 
672                                 [ src.gitpath,  'add', src.vpath ],
673                                 [ src.gitpath,  'commit',    { message: src.vpath} ] 
674                                 
675                         );
676                  
677                         return;
678                 }
679                 */
680                 cmd.action = "add";
681                 this.queue.append_val(cmd);
682
683                 cmd = new GitMonitorQueue(src);
684                 cmd.action = "commit";
685                 cmd.message = cmd.vname;
686                 this.queue.append_val(cmd);
687  
688                  
689         }
690         public override  void onDeleted(MonitorNamePathDir src) 
691    { 
692
693                 if (this.paused) {
694                         return;
695                 }
696                 print("GitMonitor.onDeleted\n");                        
697                 this.lastAdd = new DateTime.now(new TimeZone.local()); 
698                 var cmd = new GitMonitorQueue(src);
699                 if (cmd.shouldIgnore()) {
700                         return;
701                 }
702                 // should check if monitor needs removing..
703                 // it should also check if it was a directory.. - so we dont have to commit all..
704                 cmd.action = "rm";
705                 this.queue.append_val(cmd);
706
707                 cmd = new GitMonitorQueue(src);
708                 cmd.action = "commit";
709                 cmd.message = cmd.vname;
710                 cmd.commit_all = true;
711
712                 this.queue.append_val(cmd);
713  
714         }
715         public override  void onCreated(MonitorNamePathDir src) {
716
717                 if (this.paused) {
718                         return;
719                 }
720                 print("GitMonitor.onCreated\n");                        
721                 this.lastAdd = new DateTime.now(new TimeZone.local()); 
722                 var cmd = new GitMonitorQueue(src);
723                 if (cmd.shouldIgnore()) {
724                         return;
725                 }
726
727                 if (!FileUtils.test(src.path, GLib.FileTest.IS_DIR)) {
728                    // this.just_created[src.path] = true;
729                         return; // we do not handle file create flags... - use done hint.
730                 }
731                 // directory has bee created
732                 this.monitor(src.path);
733                 //this.top.append_val(src.path);
734                 //this.monitor(src.path );
735
736
737 // -- no point in adding a dir.. as git does not handle them...
738 //        this.queue.push( 
739   //          [ src.gitpath, 'add' , src.vpath,  { all: true } ],
740  //           [ src.gitpath, 'commit' , { all: true, message: src.vpath} ]
741   //          
742    //     );
743
744         }
745
746         public  override void onAttributeChanged(MonitorNamePathDir src) { 
747
748                 if (this.paused) {
749                         return;
750                 }
751                 print("GitMonitor.onAttributeChanged\n");                       
752                 if (src.dir == GitMonitor.gitlive) {
753                    return; // attribute on top level..
754                 }
755                 
756                 this.lastAdd = new DateTime.now(new TimeZone.local()); 
757                 var cmd = new GitMonitorQueue(src);
758                 if (cmd.shouldIgnore()) {
759                         return;
760                 }
761                 cmd.action = "add";
762                 this.queue.append_val(cmd);
763
764                 cmd = new GitMonitorQueue(src);
765                 cmd.action = "commit";
766                 cmd.message = "Attribute changed " + cmd.vname;
767                 this.queue.append_val(cmd);
768         }
769  
770    public  override void onMoved(MonitorNamePathDir src,MonitorNamePathDir dest)  
771         { 
772
773                 if (this.paused) {
774                         return;
775                 }
776                 print("GitMonitor.onMoved\n");                  
777                 this.lastAdd = new DateTime.now(new TimeZone.local()); 
778                 var cmd_s = new GitMonitorQueue(src);
779
780                 var cmd_d = new GitMonitorQueue(dest);
781    
782                 
783                 if (cmd_d.gitpath != cmd_s.gitpath) {
784                         this.onDeleted(src);
785                         this.onCreated(dest);
786                         this.onChangesDoneHint(dest);
787                         return;
788                 }
789                 // needs to handle move to/from unsupported types..
790                 
791                 if (cmd_s.shouldIgnore()) {
792                         this.onCreated(dest);
793                         this.onChangesDoneHint(dest);
794                         return;
795
796                 }
797                 if (cmd_d.shouldIgnore()) {
798                         
799                         this.onDeleted(src);
800  
801
802                         return;
803                 }
804                 
805                 
806                 print("RM: %s\n", cmd_s.vname);
807                 cmd_s.action = "rm";
808                 this.queue.append_val(cmd_s);
809
810                 
811                 
812                 print("ADD: %s\n", cmd_d.vname);
813                 cmd_d.action = "add";
814                 this.queue.append_val(cmd_d);
815
816
817                 var cmd = new GitMonitorQueue(dest);
818                 cmd.action = "commit";
819                 cmd.message = "MOVED " + cmd_s.vname + " to " + cmd_d.vname;
820                 if (GitMonitorQueue.queueHas(this.queue, cmd_s, "add")) {
821                         cmd.message = cmd_d.vname;
822                 }
823                 
824                 this.queue.append_val(cmd);
825
826
827                  
828         }
829            
830 }