-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathupdateantx.m
1355 lines (1229 loc) · 51.3 KB
/
updateantx.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
% noGUI-update/install function for antx-project via GITHUB (no graphical userinterface)
%% ___ INFO ___________________
% updateantx('info'); % display status information, (update status, last commit, last modified files)
% updateantx('changes'); % display last local modified files (compare last update with penultimate update)
%% ___ UPDATES ___________________
% updateantx(); % check for updates, if available, user is asked to update via cmd-window
% updateantx(1); % same as updateantx()
% updateantx(2) ; % just update (simplest version, user is not asked),
% updateantx(3) ; % hard reset, in case some local files have been modified/deleted
%% ___ FRESH INSTALLATION ___________________
% updateantx(4,'path',LOCAL-PATH-TO-INSTALL-THE-TOOLBOX);
% ..replace "LOCAL-PATH-TO-INSTALL-THE-TOOLBOX" with yout destination-path
% updateantx(4,'path',pwd); % FRESH INSTALLATION to current directory
% or
% updateantx(4,'path',fullfile(pwd,'antx2'))
%
%% ___ ".git"-folder is missing/deleted ___________________
% updateantx(13) ;% re-initiate .git
%
function varargout=updateantx(code,varargin)
% % setstatus(1,'Up-to-date. No updates found.');
% cprintf('www', ['alternative' '\n']);
% return
if 0
copyfile(fullfile(pwd,'updateantx.m'), fullfile(fileparts(pwd),'updateantx.m'),'f' )
end
if exist('code')~=1
code=1;% check updates
else
if ischar(code)
if strcmp(code,'info')
disp_info(code,varargin);
elseif strcmp(code,'changes')
if nargout==0
lastChanges(varargin);
else
varargout{1}=lastChanges(varargin);
end
end
return
end
end
%% git clone: error setting certificate verify locations #36
%% https://github.com/scalingexcellence/scrapybook/issues/36
try
git config --global http.sslverify "false"
end
%% ===============================================
p.path=[];
p.pathbefore=pwd;
if code~=4
p.path=fileparts(which('antlink'));
if exist(p.path)==7
cd(p.path);
else
disp('antx-path not found/or antx-path not set via "antlink"');
disp('...easiest way is to set current dir to the antx-directory and type antlink');
return
end
end
%% ===============================================
if nargin>1
try
p0=cell2struct(varargin(2:2:end),varargin(1:2:end),2);
fn=fieldnames(p0);
for i=1:length(fn)
p=setfield(p,fn{i},getfield(p0,fn{i}));
end
catch
error('optional args must be come as pairs');
end
end
% updatecode=13;
updatecode=code;
atime=tic;
%% ==============================================
%% check ..UPDATE
%% ==============================================
if updatecode==1 %check before
setstatus(1,'checking updates');
git fetch
%git diff master origin/master
% git diff --compact-summary master origin/master
%[msg st]=git('diff --compact-summary master origin/master');
% [msg st]=git('diff --stat master origin/master');
% [msg st]=git(' diff --name-only master origin/master');
% git diff --name-only
[msg st]=antx_gitstatus('check');
if isempty(msg);
%disp('no changes/no updates found');
setstatus(2,'Up-to-date. No updates found.');
cd(p.pathbefore);
return
else
%disp(['####### CHANGES #######']);
%disp(msg);
%% ===============================================
cprintf('*[0 0.4471 0.7412]','================================\n');
cprintf('*[0 0.4471 0.7412]','antx-UPDATES FOUND - Update now?\n');
cprintf('*[0 0.4471 0.7412]','================================\n');
disp('ENTER OPTIONS: [0] cancel');
disp(' or [1] update toolbox now');
answ=input(['Update toolbox now?: '],'s');
%% ===============================================
if strcmp(answ,'1')
updatecode=2;
else
%disp('nothing updated');
cprintf([ 1 0 1],' local package was not updated \n');
cd(p.pathbefore);
return
end
end
end
%% ==============================================
%% JUST UPDATE
%% ==============================================
% keyboard
if updatecode==2
setstatus(1,'updating..');
fprintf(['updating using version control (".git")..please wait..\n']);
if exist(fullfile(pwd,'.git'))~=7
%% ===============================================
cprintf('*[0 0.4471 0.7412]','======================================================\n');
cprintf('*[0 0.4471 0.7412]','".git-dir" not found, but mandatory for update\n');
cprintf('*[0 0.4471 0.7412]','======================================================\n');
disp('Create/Recreate ".git"-dir? ');
disp('ENTER OPTIONS: [0] cancel');
disp(' or [1] create new ".git"-dir (..download might take a while..)');
answ=input(['CREATE NEW ".git"?: '],'s');
%% ===============================================
% button = questdlg(['".git-dir" not found, but mandatory for update' char(10)...
% 'Create/Recreate ".git"-dir? ' char(10) ...
% ' ..this might take a while..'],'',...
% 'YES, do it','Cancel','canel');
% git reset --hard HEAD;
%% ===============================================
if strcmp(answ,'1')
updatecode=4;
else
cprintf([ 1 0 1],'..".git"-not found, thus .git not restored \n');
cd(p.pathbefore);
return
end
else
git pull;
end
[msg st]=antx_gitstatus('recheck');
try; antcb('versionupdate'); end
if isempty(msg)
fprintf(['updating..done t=%2.3f min\n'],toc(atime)/60);
setstatus(2,'Up-to-date. Updating finished');
cd(p.pathbefore);
else
setstatus(3,'updating failed..rebuilding necessary!');
disp('..potential reason: files in tbx where modified locally');
%% ===============================================
cprintf('*[0 0.4471 0.7412]','================================\n');
cprintf('*[0 0.4471 0.7412]','REBUILD TBX - FORCE TO UPDATE now?\n');
cprintf('*[0 0.4471 0.7412]','================================\n');
disp('ENTER OPTIONS: [0] cancel');
disp(' or [1] force to update toolbox now');
answ=input(['Update toolbox now?: '],'s');
%% ===============================================
if strcmp(answ,'1')
updatecode=3;
else
cprintf([ 1 0 1],' local package was not forced to updated \n');
cd(p.pathbefore);
return
end
end
if updatecode==2
cd(p.pathbefore);
return
end
end
%% ==================== .GIT IS MISSING..UPDATE ========================================
%% ==============================================
%% .GIT IS MISSING..UPDATE
%% ==============================================
if updatecode==13
setstatus(1,'create ".git" & updating..');
% need to initialize a new Git repository in your machine:
fprintf(['creating/restore ".git"..please wait..\n']);
git init
%Add your remote repository (published on GitHub):
%git remote add origin https://github.com/pstkoch/antx2
git(['remote add origin ' gitrepository]);
git pull origin master
%Or you can simply clone the existing remote repository as suggested in the above comments:
%git clone https://your_repot_url
try; antcb('versionupdate'); end
fprintf(['..done t=%2.3f min\n'],toc(atime)/60);
cd(p.pathbefore);
end
%% ==============================================
%% HARD RESET/REBUILD
%% ===============================================
if updatecode==3 %hard reset
%keyboard
warning off;
setstatus(1,'hard reset..');
fprintf(['hard reset,updating..please wait..\n']);
%if exist(fullfile(pwd,'.git'))~=7
%git clean -df
%PREV VERSION
% git reset --hard HEAD;
% git init
% % % %% save temp_installfromgithub
% % % orig_tempfile =which('temp_installfromgithub.m');
% % % [patt tempfi]=fileparts(orig_tempfile);
% % % moved_tempfile=fullfile(fileparts(patt),[tempfi '.m']);
% % % copyfile(orig_tempfile,moved_tempfile,'f');
% ---------------------
git fetch origin;
git add -A;
%git reset --hard;
[msg2 st2]=git('reset --hard');
if ~isempty(strfind(msg2,'Another git process seems to be running'))
if exist('.git/index.lock')==2
disp('Another git process seems to be running in this repository');
% info: https://stackoverflow.com/questions/38004148/another-git-process-seems-to-be-running-in-this-repository
disp([' ..deleting ".git/index.lock"..']);
delete('.git/index.lock','f');
disp([' ..".git/index.lock" has been deleted']);
end
[msg2 st2]=git('reset --hard');
end
%Add your remote repository (published on GitHub):
%git remote add origin https://github.com/pstkoch/antx2
try; git(['remote add origin ' gitrepository]); end
git pull origin master
% ---------------------
[msg st]=antx_gitstatus('recheck');
if isempty(msg)
fprintf(['updating..done t=%2.3f min\n'],toc(atime)/60);
setstatus(2,'Up-to-date. Updating finished');
cd(p.pathbefore);
else
setstatus(3,'updaiting failed..try again or make fresh installation');
cd(p.pathbefore);
end
if ~isempty(findobj(0,'tag','ant'))
disp('..linking paths');
thispa=pwd;
cd(p.path);
antlink(1);
cd(thispa);
antcb('update');
try; antcb('versionupdate'); end
end
% put temp_installfromgithub back to folder,
% copyfile(moved_tempfile,orig_tempfile,'f'); % allows to use pbclose and GIT-www-button
cd(p.pathbefore);
return
end
%% ==============================================
%% FRESH INSTALLATION
%% ==============================================
if updatecode==4
if isfield(p,'path')==0 | isempty(p.path)
error('path for new installation not defined..see help of updateantx ');
cd(p.pathbefore);
end
pa=p.path;
[pa2 pa1]=fileparts(pa);
if strcmp(pa1,'antx2');%antx2-path selected
patempup=pa2;
else
patempup=pa;
end
cd(patempup);
% remove paths
w=which('antlink');
if ~isempty(w)
antlink(0);
end
cd(patempup);
% try
% copyfile(fullfile(antupd.updatepath,'installfromgithub.m'), fullfile(antupd.patempup,'installfromgithub.m'),'f');
% end
msgpafinal=[' DESTINATION PATH: ' fullfile(patempup,'antx2') ] ;
if ispc==1
msgpafinal=strrep(msgpafinal,filesep,[filesep filesep]);
end
cprintf([0 .5 0], [msgpafinal '\n']);
%% ==============[install]========================
p2.antpath =fullfile(patempup,'antx2');
p2.pathbefore =p.pathbefore;
installer(p2);
%% ===============================================
end
% ==============================================
%% function local repo
% ===============================================
function gitpath=get_localGitpath
gitpath=fileparts(which('antlink.m'));
if isempty(gitpath)
error('.git not found --- link ANTx-path via antlink first');
end
% ==============================================
%% disp_info
% ===============================================
function disp_info(code,varargin)
gitpath=get_localGitpath;
%% check date of last 5 modification on LOCAL GIT-repo
w=git(['-C ' gitpath ' log -5 --format=%cd']);
w=flipud(strsplit(w,char(10))');
w{end}=[w{end} ' .. latest local version' ];
cprintf('*[0 .5 0]', ['*** date of last 5 LOCAL updates ***' '\n'] );
disp(char(w));
%% check date of last modification on LOCAL GIT-repo
w=git(['-C ' gitpath ' log -1 --format=%cd']);
w=(strsplit(w,char(10))');
tloc=w;
w{end}=[w{end} ' .. latest local version' ];
cprintf('*[0 .5 0]', ['*** date of latest LOCAL update ***' '\n'] );
disp(char(w));
%% check date of modification on REMOTE GIT-repo
w=git(['-C ' gitpath ' log -1 --format=%cd origin']);
w=(strsplit(w,char(10))');
trep=w;
w{end}=[w{end} ' .. latest REMOTE version' ];
cprintf('*[0.9294 0.6941 0.1255]', ['*** date of latest REMOTE GITHUB COMMIT ***' '\n'] );
disp(char(w));
%% check modified files on REMOTE GIT-repo
git(['-C ' gitpath ' fetch origin']);
[w st]=git(['-C ' gitpath ' diff --name-only -G. origin']);
[~,finames ext]=fileparts2(strsplit(w,char(10))');
modfiles=cellfun(@(a,b){[ a b]},finames,ext);
cprintf('*[0.9294 0.6941 0.1255]', ['*** LAST CHANGES OF REMOTE GITHUB-REPOSITORY ***' '\n'] );
if ~isempty(w)
disp(char(modfiles));
else
disp( ' .. none ..' )
end
%% update-suggestion
if strcmp(trep,tloc)~=1
cprintf('*[1 0 1]', ['UPDATE IS SUGGESTED! type "updateantx(2)" to update toolbox' '\n'] );
else
cprintf('*[0 .5 0]', ['EVERYTHING IS UP-TO-DATE' '\n'] );
end
function varargout=lastChanges(varargin)
%% show last modified LOLAL files (after update) compared to prev update
gitpath=get_localGitpath;
w=git(['-C ' gitpath ' diff --name-only HEAD HEAD~1']);
[~,finames ext]=fileparts2(strsplit(w,char(10))');
modfiles=cellfun(@(a,b){[ a b]},finames,ext);
% disp('__ LAST CHANGES OF LOCAL REPOSITORY ___');
cprintf('*[.7 .7 .7]', ['__ LAST CHANGES OF LOCAL REPOSITORY ___' '\n'] );
disp(char(modfiles));
varargout{1}=modfiles;
%
% function
% %% check modified files on REMOTE GIT-repo
% gitpath=get_localGitpath;
% git(['-C ' gitpath ' fetch origin']);
% [w st]=git(['-C ' gitpath ' diff --name-only -G. origin']);
%
% [~,finames ext]=fileparts2(strsplit(w,char(10))');
% modfiles=cellfun(@(a,b){[ a b]},finames,ext);
% cprintf('*[0.9294 0.6941 0.1255]', ['*** LAST CHANGES OF REMOTE GITHUB-REPOSITORY ***' '\n'] );
% if ~isempty(w)
% disp(char(modfiles));
% else
% disp( ' .. none ..' )
% end
% ==============================================
%% %% installer: install toolbox
% ===============================================
function installer(p2)
% keyboard
atime=tic;
setstatus(1,'fresh installation..please wait...'); drawnow;
%% ========== [1] [antx2]-folder exists ==================
isPrevANTXdir=0; % previous ANTX dir exist
if exist(p2.antpath)==7
isPrevANTXdir=1;
% keyboard
disp('..[antx2]-folder exist ..wait..folder will be renamed & removed');
cd(fileparts(p2.antpath)); drawnow;
pause(1);
%disp(fullfile(antupd.patempup,'antx2'));
%disp(fullfile(antupd.patempup,'_antx2'));
fclose('all'); % remoclose all open file-handles
if isunix && ~ismac
system(['sudo rm -r "' p2.antpath '"']);
else
try; rmdir(p2.antpath,'s'); end
end
%try; disp(pwd); end
drawnow;
end
%===============================================================
%% ========== [2] clone REPO ==================
if 1
%% NOTE the installationPath without 'ANTx2' otherwise 'ANTx2' is within 'ANTx2'-dir
% if exist(p2.antpath)
% mkdir(p2.antpath);
% end
% cd(p2.antpath);
if 1
%% ===============================================
cprintf('*[0 0.4471 0.7412]','..CLONING ANTX-2 REPO from GITHUB..please wait...\n');
%git clone https://github.com/pstkoch/antx2
%git(['clone ' gitrepository]);
%[msg]=git(['clone --depth=1 ' gitrepository]); % %CLONE-WITHOUT-PROGRESS
msg=git(['ls-remote --exit-code ' gitrepository]); %CHECK ACCESS
clonefun=['!git clone --depth=1 --progress ' gitrepository]; %CLONE-WITH-PROGRESS
eval(clonefun);
msg=git(['ls-remote --exit-code ' gitrepository]); %CHECK ACCESS
%% ===============================================
if ~isempty(strfind(msg,'unable to access')) || (exist(fullfile(p2.antpath,'.git'))~=7)
if (exist(fullfile(p2.antpath,'.git'))~=7)
disp('..failed to remove "antx2"-directory');
cprintf([1 0 1],['..PLEASE REMOVE DIRECTORY MANUALLY and try again!' '.\n']);
end
if ~isempty(strfind(msg,'unable to access'))
disp('issue -cloning REPO (check newtork/firewall/proxy settings)');
disp('for linux see: help of installLinux')
end
%installLinux(antupd,gitrepository);
error('could not clone REPOSITORY');
cd(p2.pathbefore);
% if isunix && ~ismac
% %system(['sudo git clone --depth=1 ' gitrepository])
% installLinux(antupd,gitrepository);
% elseif ismac
% error('mac issue -cloning (check newtork/firewall/proxy settings)');
% elseif ispc
% error('PC issue -cloning (check newtork/firewall/proxy settings)');
% end
end
%fprintf(['installation..done t=%2.3f min\n'],toc(atime)/60);
end
try
cd(p2.antpath);
end
warning off;
success=0;
if exist(p2.antpath)==7
[msg st]=antx_gitstatus('recheck');
if isempty(msg)
try
success=1;
end
end
end
end
if success==1 %% SUCCESS
ELA=sprintf(['(t=%2.3f min)'],toc(atime)/60);
cprintf([0 .5 0],['Package installation done' ELA '.\n']);
else
%% PROBLEM
cprintf([1 0 0],['.. installation failure.. check network connection/proxy settings/firewall.\n']);
cprintf([1 0 0],['.. TESTING a possible solution...\n']);
% ---POTENTIAL SOLUTION------------------
git fetch origin
git add -A
git reset --hard;
%Add your remote repository (published on GitHub):
%git remote add origin https://github.com/pstkoch/antx2
try; git(['remote add origin ' gitrepository]); end
git pull origin master
% ---------------------
[msg st]=antx_gitstatus('recheck');
if isempty(msg)
success=1;
else
cprintf([1 0 0],['.. persisting installation failure.. check network connection/proxy settings/firewall.\n']);
end
end
if ~isempty(findobj(0,'tag','ant'))
disp('..linking paths');
thispa=pwd;
cd(p2.antpath);
antlink(1);
cd(thispa);
if ~isempty(findobj(0,'tag','ant'));
antcb('update');
end
end
if success==1 %% SUCCESS
setstatus(2,'Instalation completed. Up-to-data.');
else
setstatus(3,'Installation failed..check network connection/proxy settings/firewall');
end
cd(p2.pathbefore);
% --------- MESSAGE what is modified
function [msg st]=antx_gitstatus(message)
% [msg st]=git('diff --name-only');
% [msg st]=git('diff --name-only origin');
[msg st]=git('diff --name-only -G. origin'); %cont' check permission rights
msg=strsplit(msg,char(10));
msg=msg(cellfun('isempty',strfind(msg,'prevprojects.mat'))); % without 'prevprojects.mat' in list
if ~isempty(msg)
msg=strjoin(msg,char(10));
end
if ~isempty(msg)
if strcmp(message,'check')
cprintf([ 1 0 1],'-----------------------------\n');
cprintf([ 1 0 1],' MODIFIED GITHUB FILES \n');
cprintf([ 1 0 1],'-----------------------------\n');
cprintf([ 0 0 0] ,'The following files have been created or modified in GITHUB:\n');
cprintf([ .5 .5 .5],' (Note that the list might contain also locally modified or deleted files.)\n');
cprintf([ 1 0 1],'_____MODIFIED GITHUB FILES: \n');
cprintf([ .5 .5 .5],msg);
cprintf([ .5 .5 .5],'\n');
elseif strcmp(message,'recheck')
cprintf([0.9294 0.6902 0.1294],'-----------------------------\n');
cprintf([0.9294 0.6902 0.1294],' ERRONEOUS UPDATE \n');
cprintf([0.9294 0.6902 0.1294],'-----------------------------\n');
cprintf([ 0 0 0],'The following files were not updated successfully.\n');
cprintf([ 0 0 0],'..REASONS: local files have been modified/deleted.\n');
cprintf([ 0 0 0],'Please hit ');
cprintf([ 1 0 1],'[rebuild] ');
cprintf([ 0 0 0],'button to update those files.\n');
cprintf([ .5 .5 .5],msg);
cprintf([ .5 .5 .5],'\n');
end
else
cprintf([ 0.4667 0.6745 0.1882],'------------------------------------------------\n');
cprintf([ 0.4667 0.6745 0.1882],' ::.STATUS: UP-TO-DATE. NO NEWER UPDATES FOUND \n');
cprintf([ 0.4667 0.6745 0.1882],'------------------------------------------------\n');
end
function setstatus(arg,msg)
if exist('msg')~=1; msg=''; end
if arg==0
%set(findobj( findobj(0,'tag','fupd') ,'tag','msg'),'foregroundcolor',[.4 .4 .4],'string','[idle] ');
cprintf([.4 .4 .4],['[idle]' msg ' \n'] );
elseif arg==1
%set(findobj( findobj(0,'tag','fupd') ,'tag','msg'),'foregroundcolor',[1 0 1],'string',['[busy] ' msg]);
cprintf([1 0 1],['[busy]' msg ' \n'] );
elseif arg==2
%set(findobj( findobj(0,'tag','fupd') ,'tag','msg'),'foregroundcolor',[ 0.4667 0.6745 0.1882],'string',['[idle] ' msg]);
cprintf([ 0.4667 0.6745 0.1882],['[idle]' msg ' \n'] );
elseif arg==3
%set(findobj( findobj(0,'tag','fupd') ,'tag','msg'),'foregroundcolor',[ 1 0 0],'string',['[idle] ' msg]);
cprintf([ 1 0 0],['[idle]' msg ' \n'] );
end
function https=gitrepository
https='https://github.com/ChariteExpMri/antx2.git';
% ==============================================
%% aux
% ===============================================
function [cmdout, statout] = git(varargin)
% A thin MATLAB wrapper for Git.
%
% Short instructions:
% Use this exactly as you would use the OS command-line verison of Git.
%
% Long instructions are:
% This is not meant to be a comprehensive guide to the near-omnipotent
% Git SCM:
% http://git-scm.com/documentation
%
% Common MATLAB workflow:
%
% % Creates initial repository tracking all files under some root
% % folder
% >> cd ~/
% >> git init
%
% % Shows changes made to all files in repo (none so far)
% >> git status
%
% % Create a new file and add some code
% >> edit foo.m
%
% % Check repo status, after new file created
% >> git status
%
% % Stage/unstage files for commit
% >> git add foo.m % Add file to repo or to stage
% >> git reset HEAD . % To unstage your files from current commit area
%
% % Commit your changes to a new branch, with comments
% >> git commit -m 'Created new file, foo.m'
%
% % Other useful commands (replace ellipses with appropriate args)
% >> git checkout ... % To restore files to last commit
% >> git branch ... % To create or move to another branch
% >> git diff ... % See line-by-line changes
%
% Useful resources:
% 1. GitX: A visual interface for Git on the OS X client
% 2. Github.com: Remote hosting for Git repos
% 3. Git on Wikipedia: Further reading
%
% v0.1, 27 October 2010 -- MR: Initial support for OS X & Linux,
% untested on PCs, but expected to work
%
% v0.2, 11 March 2011 -- TH: Support for PCs
%
% v0.3, 12 March 2011 -- MR: Fixed man pages hang bug using redirection
%
% v0.4, 20 November 2013-- TN: Searching for git in default directories,
% returning results as variable
%
% v0.5, 22 January 2015 -- TP: Suppressed printing of ans before
% git command output
%
% v0.6, 26 January 2015 -- HG: Add path to git
%
% v0.7 09 April 2015 -- VF: If user requests it, return Git results
% as a variable instead of displaying them.
%
% v0.8 24 Juli 2015 -- MvdL: Return status output
%
%
% Contributors: (MR) Manu Raghavan
% (TH) Timothy Hansell
% (TN) Tassos Natsakis
% (TP) Tyler Parsons
% (HG) Han Geerligs
% (VF) Vadim Frolov
% (MvdL) Marcel van der Linden
%
orgpath=getenv('PATH');
quit_function=0;
try
% Test to see if git is installed
[status,~] = system('git --version');
% if git is in the path this will return a status of 0
% it will return a 1 only if the command is not found
% git command output
result = '';
if status
% Checking if git exists in the default installation folders (for
% Windows)
if ispc
search = ~isempty(dir('c:\Program Files\Git\bin\git.exe'));
searchx86 = ~isempty(dir('c:\Program Files (x86)\Git\bin\git.exe'));
else
search = 0;
searchx86 = 0;
end
if ~(search||searchx86)
% If git is NOT installed, then this should end the function.
result = sprintf('git is not installed\n%s\n',...
'Download it at http://git-scm.com/download');
quit_function=1; % set quit_function flag: only result is displayed
end
end
% if quit_function then only display message
if ~quit_function
% If git exists but the status is 1, then it means that it is
% not in the path. We should add the path
if status
if search
gitpath='c:\Program Files\Git\bin';
else if searchx86
gitpath='c:\Program Files (x86)\Git\bin';
end
end
setenv('PATH',[gitpath pathsep orgpath]); % add path to git
end
% We can call the real git with the arguments
arguments = parse(varargin{:});
if ispc
prog = '';
else
prog = ' | cat';
end
if strcmp(arguments, 'commit ')
answer = inputdlg('Comments:','Commit''s comments');
arguments = [arguments '-m"' char(answer) '"'];
end
[status,result] = system(['git ',arguments,prog]);
end
if nargout >= 1
cmdout = strtrim(result);
statout = status;
else
% Display result instead of returning it
% to suppress output of ans
disp(result);
end
% restore the original path
setenv(orgpath);
catch
% restore the original path
setenv(orgpath);
end
function space_delimited_list = parse(varargin)
space_delimited_list = cell2mat(...
cellfun(@(s)([s,' ']),varargin,'UniformOutput',false));
function count = cprintf(style,format,varargin)
% CPRINTF displays styled formatted text in the Command Window
%
% Syntax:
% count = cprintf(style,format,...)
%
% Description:
% CPRINTF processes the specified text using the exact same FORMAT
% arguments accepted by the built-in SPRINTF and FPRINTF functions.
%
% CPRINTF then displays the text in the Command Window using the
% specified STYLE argument. The accepted styles are those used for
% Matlab's syntax highlighting (see: File / Preferences / Colors /
% M-file Syntax Highlighting Colors), and also user-defined colors.
%
% The possible pre-defined STYLE names are:
%
% 'Text' - default: black
% 'Keywords' - default: blue
% 'Comments' - default: green
% 'Strings' - default: purple
% 'UnterminatedStrings' - default: dark red
% 'SystemCommands' - default: orange
% 'Errors' - default: light red
% 'Hyperlinks' - default: underlined blue
%
% 'Black','Cyan','Magenta','Blue','Green','Red','Yellow','White'
%
% STYLE beginning with '-' or '_' will be underlined. For example:
% '-Blue' is underlined blue, like 'Hyperlinks';
% '_Comments' is underlined green etc.
%
% STYLE beginning with '*' will be bold (R2011b+ only). For example:
% '*Blue' is bold blue;
% '*Comments' is bold green etc.
% Note: Matlab does not currently support both bold and underline,
% only one of them can be used in a single cprintf command. But of
% course bold and underline can be mixed by using separate commands.
%
% STYLE also accepts a regular Matlab RGB vector, that can be underlined
% and bolded: -[0,1,1] means underlined cyan, '*[1,0,0]' is bold red.
%
% STYLE is case-insensitive and accepts unique partial strings just
% like handle property names.
%
% CPRINTF by itself, without any input parameters, displays a demo
%
% Example:
% cprintf; % displays the demo
% cprintf('text', 'regular black text');
% cprintf('hyper', 'followed %s','by');
% cprintf('key', '%d colored', 4);
% cprintf('-comment','& underlined');
% cprintf('err', 'elements\n');
% cprintf('cyan', 'cyan');
% cprintf('_green', 'underlined green');
% cprintf(-[1,0,1], 'underlined magenta');
% cprintf([1,0.5,0],'and multi-\nline orange\n');
% cprintf('*blue', 'and *bold* (R2011b+ only)\n');
% cprintf('string'); % same as fprintf('string') and cprintf('text','string')
%
% Bugs and suggestions:
% Please send to Yair Altman (altmany at gmail dot com)
%
% Warning:
% This code heavily relies on undocumented and unsupported Matlab
% functionality. It works on Matlab 7+, but use at your own risk!
%
% A technical description of the implementation can be found at:
% <a href="http://undocumentedmatlab.com/blog/cprintf/">http://UndocumentedMatlab.com/blog/cprintf/</a>
%
% Limitations:
% 1. In R2011a and earlier, a single space char is inserted at the
% beginning of each CPRINTF text segment (this is ok in R2011b+).
%
% 2. In R2011a and earlier, consecutive differently-colored multi-line
% CPRINTFs sometimes display incorrectly on the bottom line.
% As far as I could tell this is due to a Matlab bug. Examples:
% >> cprintf('-str','under\nline'); cprintf('err','red\n'); % hidden 'red', unhidden '_'
% >> cprintf('str','regu\nlar'); cprintf('err','red\n'); % underline red (not purple) 'lar'
%
% 3. Sometimes, non newline ('\n')-terminated segments display unstyled
% (black) when the command prompt chevron ('>>') regains focus on the
% continuation of that line (I can't pinpoint when this happens).
% To fix this, simply newline-terminate all command-prompt messages.
%
% 4. In R2011b and later, the above errors appear to be fixed. However,
% the last character of an underlined segment is not underlined for
% some unknown reason (add an extra space character to make it look better)
%
% 5. In old Matlab versions (e.g., Matlab 7.1 R14), multi-line styles
% only affect the first line. Single-line styles work as expected.
% R14 also appends a single space after underlined segments.
%
% 6. Bold style is only supported on R2011b+, and cannot also be underlined.
%
% Change log:
% 2015-06-24: Fixed a few discoloration issues (some other issues still remain)
% 2015-03-20: Fix: if command window isn't defined yet (startup) use standard fprintf as suggested by John Marozas
% 2012-08-09: Graceful degradation support for deployed (compiled) and non-desktop applications; minor bug fixes
% 2012-08-06: Fixes for R2012b; added bold style; accept RGB string (non-numeric) style
% 2011-11-27: Fixes for R2011b
% 2011-08-29: Fix by Danilo (FEX comment) for non-default text colors
% 2011-03-04: Performance improvement
% 2010-06-27: Fix for R2010a/b; fixed edge case reported by Sharron; CPRINTF with no args runs the demo
% 2009-09-28: Fixed edge-case problem reported by Swagat K
% 2009-05-28: corrected nargout behavior suggested by Andreas G?b
% 2009-05-13: First version posted on <a href="http://www.mathworks.com/matlabcentral/fileexchange/authors/27420">MathWorks File Exchange</a>
%
% See also:
% sprintf, fprintf
% License to use and modify this code is granted freely to all interested, as long as the original author is
% referenced and attributed as such. The original author maintains the right to be solely associated with this work.
% Programmed and Copyright by Yair M. Altman: altmany(at)gmail.com
% $Revision: 1.10 $ $Date: 2015/06/24 01:29:18 $
format_backup=format;
try
persistent majorVersion minorVersion
if isempty(majorVersion)
%v = version; if str2double(v(1:3)) <= 7.1
%majorVersion = str2double(regexprep(version,'^(\d+).*','$1'));
%minorVersion = str2double(regexprep(version,'^\d+\.(\d+).*','$1'));
%[a,b,c,d,versionIdStrs]=regexp(version,'^(\d+)\.(\d+).*'); %#ok unused
v = sscanf(version, '%d.', 2);
majorVersion = v(1); %str2double(versionIdStrs{1}{1});
minorVersion = v(2); %str2double(versionIdStrs{1}{2});
end
% The following is for debug use only:
%global docElement txt el
if ~exist('el','var') || isempty(el), el=handle([]); end %#ok mlint short-circuit error ("used before defined")
if nargin<1, showDemo(majorVersion,minorVersion); return; end
if isempty(style), return; end
if all(ishandle(style)) && length(style)~=3
dumpElement(style);
return;
end
% Process the text string
if nargin<2, format = style; style='text'; end
%error(nargchk(2, inf, nargin, 'struct'));
%str = sprintf(format,varargin{:});
% In compiled mode
try useDesktop = usejava('desktop'); catch, useDesktop = false; end
if isdeployed | ~useDesktop %#ok<OR2> - for Matlab 6 compatibility
% do not display any formatting - use simple fprintf()
% See: http://undocumentedmatlab.com/blog/bold-color-text-in-the-command-window/#comment-103035
% Also see: https://mail.google.com/mail/u/0/?ui=2&shva=1#all/1390a26e7ef4aa4d
% Also see: https://mail.google.com/mail/u/0/?ui=2&shva=1#all/13a6ed3223333b21
count1 = fprintf(format,varargin{:});
else
% Else (Matlab desktop mode)
% Get the normalized style name and underlining flag
[underlineFlag, boldFlag, style, debugFlag] = processStyleInfo(style);
% Set hyperlinking, if so requested
if underlineFlag
format = ['<a href="">' format '</a>'];
% Matlab 7.1 R14 (possibly a few newer versions as well?)
% have a bug in rendering consecutive hyperlinks
% This is fixed by appending a single non-linked space
if majorVersion < 7 || (majorVersion==7 && minorVersion <= 1)
format(end+1) = ' ';
end
end
% Set bold, if requested and supported (R2011b+)
if boldFlag
if (majorVersion > 7 || minorVersion >= 13)
format = ['<strong>' format '</strong>'];
else
boldFlag = 0;
end
end
% Get the current CW position
cmdWinDoc = com.mathworks.mde.cmdwin.CmdWinDocument.getInstance;
lastPos = cmdWinDoc.getLength;
% If not beginning of line
bolFlag = 0; %#ok
%if docElement.getEndOffset - docElement.getStartOffset > 1
% Display a hyperlink element in order to force element separation
% (otherwise adjacent elements on the same line will be merged)
if majorVersion<7 || (majorVersion==7 && minorVersion<13)
if ~underlineFlag
fprintf('<a href=""> </a>'); %fprintf('<a href=""> </a>\b');
elseif format(end)~=10 % if no newline at end
fprintf(' '); %fprintf(' \b');
end
end
%drawnow;
bolFlag = 1;
%end
% Get a handle to the Command Window component
mde = com.mathworks.mde.desk.MLDesktop.getInstance;
cw = mde.getClient('Command Window');
% Fix: if command window isn't defined yet (startup), use standard fprintf()
if (isempty(cw))
count1 = fprintf(format,varargin{:});
if nargout
count = count1;
end
return;
end
xCmdWndView = cw.getComponent(0).getViewport.getComponent(0);
% Store the CW background color as a special color pref
% This way, if the CW bg color changes (via File/Preferences),
% it will also affect existing rendered strs
com.mathworks.services.Prefs.setColorPref('CW_BG_Color',xCmdWndView.getBackground);
% Display the text in the Command Window
% Note: fprintf(2,...) is required in order to add formatting tokens, which
% ^^^^ can then be updated below (no such tokens when outputting to stdout)
count1 = fprintf(2,format,varargin{:});
% Repaint the command window
%awtinvoke(cmdWinDoc,'remove',lastPos,1); % TODO: find out how to remove the extra '_'