lib/App/SeismicUnixGui/misc/L_SU_local_user_constants.pm untested

filter: Statementstmt 0.0% 0 / 267 Branchbran 0.0% 0 / 24 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 42 Podpod 0.0% 0 / 34 totaltotal 0.0% 0 / 367 CC 13 SCAR 14.6
CC
13
Cov
0%
get_ACTIVE_PROJECT_exists
12.0
get_PROJECT_exists
12.0
_get_PROJECT
6.0
CRAP 4.3
1 package App::SeismicUnixGui::misc::L_SU_local_user_constants;
2  
3 use Moose;
4 our $VERSION = '0.0.1';
5  
6 use aliased 'App::SeismicUnixGui::misc::L_SU_global_constants';
7 use aliased 'App::SeismicUnixGui::misc::dirs';
8 use aliased 'App::SeismicUnixGui::misc::big_streams_param';
9 use aliased 'App::SeismicUnixGui::misc::manage_dirs_by';
10  
11 my $L_SU_global_constants = L_SU_global_constants->new();
12  
13 =head2 private hash
14  
15 =cut
16  
17 my $L_SU = {
18 _ACTIVE_PROJECT => '',
19 _default_Project_config => '',
20 _user_configuration_Project_config => '',
21 _user_configuration_Project_config2 => '',
22 _config_base_name => 'Project',
23 _PROJECT => '',
24 _default_project_name => 'Servilleta',
25 };
26  
27 =head2 definitions
28  
29 =cut
30  
31 sub get_home {
32 my ($self) = @_;
33 my $home_directory;
34  
35 use Shell qw(echo);
36  
37 $home_directory = ` echo \$HOME`;
38 chomp $home_directory;
39  
40 my $HOME = $home_directory;
41  
42 return ($HOME);
43  
44 }
45  
46 sub _get_home {
47 my ($self) = @_;
48 my $home_directory;
49  
50 use Shell qw(echo);
51  
52 $home_directory = ` echo \$HOME`;
53 chomp $home_directory;
54  
55 my $HOME = $home_directory;
56  
57 return ($HOME);
58  
59 }
60  
61 sub _get_PROJECT {
62 my ($self) = @_;
63 my $PROJECT = $L_SU->{_PROJECT};
64  
65 if ($PROJECT) {
66 return ($PROJECT);
67 }
68 else {
69 # print("L_SU_local_user_constants,_get_PROJECT, no PROJECT defined\n");
70 return ();
71 }
72 }
73  
74 sub get_PROJECT {
75 my ($self) = @_;
76 my $PROJECT = $L_SU->{_PROJECT};
77  
78 if ($PROJECT) {
79 return ($PROJECT);
80 }
81 else {
82 print("L_SU_local_user_constants,_get_PROJECT, no PROJECT defined\n");
83 return ();
84 }
85 }
86  
87 sub _get_CONFIGURATION {
88 my ($self) = @_;
89 my $CONFIGURATION;
90  
91 my $HOME = _get_home;
92  
93 $CONFIGURATION = $HOME . '/.L_SU/configuration';
94  
95 return ($CONFIGURATION);
96  
97 }
98  
99 sub get_CONFIGURATION {
100 my ($self) = @_;
101 my $CONFIGURATION;
102  
103 my $HOME = _get_home;
104  
105 $CONFIGURATION = $HOME . '/.L_SU/configuration';
106  
107 return ($CONFIGURATION);
108  
109 }
110  
111 sub set_PROJECT_name {
112 my ( $self, $PROJECT_name ) = @_;
113 my $PROJECT;
114  
115 my $HOME = _get_home;
116  
117 $PROJECT = $HOME . '/.L_SU/' . 'configuration' . '/' . $PROJECT_name;
118 $L_SU->{_PROJECT} = $PROJECT;
119 return ();
120  
121 }
122  
123 sub get_PROJECT_HOMES_aref {
124 my ($self) = @_;
125 my @PROJECT_HOMES;
126  
127 my $HOME = _get_home;
128 my $project_names_aref = _get_project_names();
129 my @project_names = @$project_names_aref;
130 my $length = scalar @project_names;
131  
132 for ( my $i = 0 ; $i < $length ; $i++ ) {
133  
134 $PROJECT_HOMES[$i] = $HOME . '/' . $project_names[$i];
135 }
136 return ( \@PROJECT_HOMES );
137 }
138  
139 sub _get_default_Project_config {
140 my ($self) = @_;
141 my $default_Project_config;
142 $default_Project_config = $L_SU->{_default_Project_config};
143  
144 return ($default_Project_config);
145 }
146  
147 sub _get_config_name_new {
148 my $self = @_;
149 my $prog_name_new = 'Project';
150  
151 return ($prog_name_new);
152 }
153  
154 sub get_config_name_new {
155 my $self = @_;
156 my $prog_name_new = 'Project';
157  
158 return ($prog_name_new);
159 }
160  
161 # TODO remove the following and substitute
162 # with the previous that makes more sense
163 # Project.config is the generic project configuration file
164 sub get_prog_name_new {
165 my $self = @_;
166 my $prog_name_new = 'Project';
167  
168 return ($prog_name_new);
169 }
170  
171 sub _get_user_configuration_Project_config {
172 my ($self) = @_;
173  
174 my $user_configuration_Project_config =
175 $L_SU->{_user_configuration_Project_config};
176  
177 # print("L_SU_local_user_constants,_get_user_configuration_Project_config, user_configuration_Project_config: $user_configuration_Project_config\n");
178  
179 return ($user_configuration_Project_config);
180 }
181  
182 sub get_user_configuration_Project_config {
183 my ($self) = @_;
184  
185 my $user_configuration_Project_config =
186 $L_SU->{_user_configuration_Project_config};
187  
188 # print("L_SU_local_user_constants,get_user_configuration_Project_config, user_configuration_Project_config: $user_configuration_Project_config\n");
189  
190 return ($user_configuration_Project_config);
191 }
192  
193 sub _get_user_configuration_Project_config2 {
194 my ($self) = @_;
195  
196 if ( $L_SU->{_user_configuration_Project_config2} ) {
197  
198 my $user_configuration_Project_config2 =
199 $L_SU->{_user_configuration_Project_config2};
200 print(
201 "L_SU_local_user_constants,_get_user_configuration_Project_config2, user_configuration_Project_config2: $user_configuration_Project_config2\n"
202 );
203  
204 return ($user_configuration_Project_config2);
205  
206 }
207 else {
208 print(
209 "L_SU_local_user_constants,_get_user_configuration_Project_config, missing user_configuration_Project_config2\n"
210 );
211 }
212 }
213  
214 sub get_user_configuration_Project_config2 {
215 my ($self) = @_;
216  
217 if ( $L_SU->{_user_configuration_Project_config2} ) {
218  
219 my $user_configuration_Project_config2 =
220 $L_SU->{_user_configuration_Project_config2};
221  
222 # print("L_SU_local_user_constants,_get_user_configuration_Project_config2, user_configuration_Project_config2: $user_configuration_Project_config\n");
223 return ($user_configuration_Project_config2);
224  
225 }
226 else {
227 print(
228 "L_SU_local_user_constants,_get_user_configuration_Project_config, missing user_configuration_Project_config2\n"
229 );
230 }
231  
232 }
233  
234 sub get_Project_config {
235 my ($self) = @_;
236  
237 my $Project_config = 'Project.config';
238 return ($Project_config);
239 }
240  
241 sub _get_Project_config {
242 my ($self) = @_;
243  
244 my $Project_config = 'Project.config';
245 return ($Project_config);
246 }
247  
248 =head2 sub _get_ACTIVE_PROJECT{
249  
250 upper case ACTIVE_PROJECT
251 PATH to the defatul Project.config
252  
253 =cut
254  
255 sub _get_ACTIVE_PROJECT {
256 my ($self) = @_;
257 my $ACTIVE_PROJECT;
258  
259 my $HOME = _get_home();
260  
261 $ACTIVE_PROJECT = $HOME . '/.L_SU/configuration/active';
262 return ($ACTIVE_PROJECT);
263 }
264  
265 =head2 sub get_ACTIVE_PROJECT{
266  
267 upper case ACTIVE_PROJECT
268 PATH to the default Project.config
269  
270 =cut
271  
272 sub get_ACTIVE_PROJECT {
273 my ($self) = @_;
274 my $ACTIVE_PROJECT;
275  
276 my $HOME = _get_home();
277  
278 $ACTIVE_PROJECT = $HOME . '/.L_SU/configuration/active';
279 return ($ACTIVE_PROJECT);
280 }
281  
282 =head2 sub get_active_project_name
283  
284 lower case active project is the project name
285 but must have a _name as suffix get_ACTIVE_PROJECT
286 because Perl does not distinguish between upper and lower-
287 case cases.
288 Get the project name from the Project.config file
289 within the active-project dirctory:
290  
291 .L_SU/configuration/active/Project.config
292  
293 =cut
294  
295 sub get_active_project_name {
296 my ($self) = @_;
297  
298 # default config file is 'Project'
299 my $project_name = $L_SU->{_config_base_name};
300  
301 # print("L295 L_SU_local_user_constants,get_active_project,project_name=$project_name\n");
302 # L_SU_local_user_constants->set_program_name( \$project_name );
303  
304 my $namesNvalues_aref = _get_local_or_defaults($project_name);
305 my @namesNvalues_aref = @$namesNvalues_aref;
306  
307 #print("L_SU_local_user_constants,get_active_project,namesNvalues_aref: @$namesNvalues_aref\n");
308  
309 my $ACTIVE_PROJECT_name = $namesNvalues_aref[3];
310  
311 # print("1. L_SU_local_user_constants,get_active_project,name:$ACTIVE_PROJECT_name\n");
312 # matches last word after last "/"
313 # last element of array is the active project name
314 my @words = split /\//, $ACTIVE_PROJECT_name;
315  
316 # print("1. L_SU_local_user_constants,get_active_project,name:$words[-1]\n");
317 my $active_project_name = $words[-1];
318  
319 #remove any quote if it exists
320 $active_project_name =~ s/'//;
321  
322 return ($active_project_name);
323 }
324  
325 =head2 sub _get_local_or_defaults
326  
327 via big_streams_param:
328
329 Read a default specification file
330 1) If default specification file# does not exist locally (PL_SEISMIC)
331 2) then check the user's configuration area: .LSU/configuration/active/Project.config
332 and if not,
333 3) then use the default one defined under global libs
334  
335  
336 Debug with
337 print ("self is $self,program is $program_name\n");
338 print("params are @$ref_CFG\n");
339 program name is a hash
340 print("params are @$ref_cfg\n");
341 print ("self is $self,program is $program_name\n");
342 print("L_SU_local_user_constants,_get_local_or_defaults,program_name:$$program_name_sref\n");
343 print("L_SU_local_user_constants,_get_local_or_defaults,program_name:$$name_sref\n");
344 print("L_SU_local_user_constants,_get_local_or_defaults,program_name:$$program_name_sref\n");
345 print("L_SU_local_user_constants,_get_local_or_defaults, length:$L_SU_local_user_constants->{_length}\n");
346  
347 =cut
348  
349 sub _get_local_or_defaults {
350 my ($config_base_name) = @_;
351  
352 # print("L_SU_local_user_constants, _get_local_or_defaults,program name=$config_base_name\n");
353  
354 if ( length $config_base_name ) {
355  
356 my $big_streams_param = big_streams_param->new();
357  
358 my $flow_type =
359 $L_SU_global_constants->flow_type_href->{_pre_built_superflow};
360 $big_streams_param->set_flow_type($flow_type);
361  
362 my ( $cfg_aref, $size );
363  
364 my $name_sref = \$config_base_name;
365  
366 # print("L359 L_SU_local_user_constants, _get_local_or_defaults,program name=$$name_sref\n");
367 # print("L359 L_SU_local_user_constants, _get_local_or_defaults,flow_type=$flow_type\n");
368 # print("L_SU_local_user_constants, _get_local_or_defaults,SCALAR program name=$name_sref\n");
369  
370 $cfg_aref = $big_streams_param->get($name_sref);
371  
372 # print("L_SU_local_user_constants, _get_local_or_defaults,cfg_aref = @{$cfg_aref}\n");
373 return ($cfg_aref);
374 }
375 else {
376 print(
377 "L_SU_local_user_constants, L_SU_local_user_constants,missing program_name_sref\n"
378 );
379 return ();
380 }
381  
382 }
383  
384 =head2 sub _get_active_project_name
385  
386 lower case active project is the project name
387 but must have a _name as suffix get_ACTIVE_PROJECT
388 because Perl does not distinguish between upper and lower
389 case cases.
390 Get the project name from the Project.config file
391 within the active-project dirctory:
392  
393 .L_SU/configuration/active/Project.config
394  
395 =cut
396  
397 sub _get_active_project_name {
398 my ($self) = @_;
399  
400 # default config file is 'Project'
401 my $project_name = $L_SU->{_config_base_name};
402  
403 # L_SU_local_user_constants->set_program_name( \$project_name );
404  
405 my $namesNvalues_aref = _get_local_or_defaults($project_name);
406 my @namesNvalues_aref = @$namesNvalues_aref;
407  
408 # print("L_SU_local_user_constants,get_active_project,namesNvalues_aref: @$namesNvalues_aref\n");
409  
410 my $ACTIVE_PROJECT_name = $namesNvalues_aref[3];
411  
412 # print("1. L_SU_local_user_constants,_get_active_project,name:$ACTIVE_PROJECT_name\n");
413 # matches last word after last "/"
414 # last element of array is the active project name
415 my @words = split /\//, $ACTIVE_PROJECT_name;
416  
417 # print("1. L_SU_local_user_constants,_get_active_project,name:$words[-1]\n");
418 my $active_project_name = $words[-1];
419  
420 #remove any quote if it exists
421 $active_project_name =~ s/'//;
422  
423 return ($active_project_name);
424 }
425  
426 sub _set_default_Project_config {
427 my ($self) = @_;
428  
429 my $ACTIVE_PROJECT;
430 my $global_lib = $L_SU_global_constants->global_libs();
431 my $GLOBAL_CONFIG_LIB = $global_lib->{_configs_big_streams};
432 my $get = $L_SU_global_constants->var();
433 my $Project_config = $get->{_Project_config};
434  
435 my $HOME = _get_home;
436  
437 my $inbound_Project_config = $GLOBAL_CONFIG_LIB .'/'. $Project_config;
438 $L_SU->{_default_Project_config} = $inbound_Project_config;
439  
440 # print(" L_SU_local_user_constants,_set_default_Project_config,default_Project_config: $L_SU->{_default_Project_config} \n");
441  
442 return ();
443 }
444  
445 =head2 sub get_ACTIVE PROJECT_exists
446  
447 does ACTIVE_PROJECT (path)
448 exist
449
450 =cut
451  
452 sub get_ACTIVE_PROJECT_exists {
453 my ($self) = @_;
454  
455 my $false = 0;
456 my $ans = $false;
457 my $true = 1;
458  
459 my $ACTIVE_PROJECT = _get_ACTIVE_PROJECT();
460  
461 print("L_SU_local_user_constants,get_ACTIVE_PROJECT_exists,ACTIVE_PROJECT =$ACTIVE_PROJECT \n");
462 # includes path
463
464 if ( length $ACTIVE_PROJECT ) {
465  
466 if ( -d $ACTIVE_PROJECT ) {
467  
468 $ans = $true;
469 print("L_SU_local_user_constants,get_ACTIVE_PROJECT_exists,TRUE :$ans\n");
470  
471 }
472 else {
473 $ans = $false;
474 print("L_SU_local_user_constants,get_ACTIVE_PROJECT_exists,FALSE :$ans\n");
475 print("$ACTIVE_PROJECT does not exist\n");
476 }
477 return ($ans);
478  
479 }
480 else {
481
482 $ans = $false;
483 # print("L_SU_local_user_constants,get_PROJECT_exists,is an empty variable \n");
484 return ($ans);
485 }
486  
487 }
488  
489 =head2 sub get_PROJECT_exists
490  
491 tests if a PROJECT (path)
492 exists
493
494 =cut
495  
496 sub get_PROJECT_exists {
497 my ($self) = @_;
498  
499 my $false = 0;
500 my $ans = $false;
501 my $true = 1;
502  
503 my $PROJECT = _get_PROJECT();
504  
505 # print("L_SU_local_user_constants,get_PROJECT_exists,PROJECT =$PROJECT \n");
506 # includes path
507 if ( length $PROJECT ) {
508  
509 if ( -d $PROJECT ) {
510  
511 $ans = $true;
512 # print("L_SU_local_user_constants,get_PROJECT_exists,TRUE :$ans\n");
513  
514 }
515 else {
516 $ans = $false;
517 # print("L_SU_local_user_constants,get_PROJECT_exists,FALSE :$ans\n");
518 # print("$PROJECT does not exist\n");
519 }
520 return ($ans);
521  
522 }
523 else {
524
525 $ans = $false;
526 # print("L_SU_local_user_constants,get_PROJECT_exists,is an empty variable \n");
527 return ($ans);
528 }
529  
530 }
531  
532 =head2 sub _get_project_names
533  
534 o/p array ref of list names
535  
536 =cut
537  
538 sub _get_project_names {
539 my ($self) = @_;
540  
541 my @filtered;
542 my $i = 0;
543 my $dirs = dirs->new();
544  
545 my $HOME = _get_home();
546 my $CONFIGURATION = $HOME . '/.L_SU/configuration';
547  
548 # print ("LSU_local_user_constants,get_Project_names CONFIGURATION: $CONFIGURATION\n");
549 $dirs->set_dir($CONFIGURATION);
550 my $ls_ref = $dirs->get_ls;
551  
552 foreach my $file (@$ls_ref) {
553  
554 # exclude any files whose full name contains the string 'active' i.e., only one.
555 next if $file =~ /active/;
556  
557 # print all other files
558 $filtered[$i] = $file;
559 $i++;
560 }
561  
562 # print ("LSU_local_user_constants,get_Project_names @$ls_ref\n");
563 return ( \@filtered );
564 }
565  
566 =head2 sub get_project_names
567  
568 o/p array ref of list names
569  
570 =cut
571  
572 sub get_project_names {
573 my ($self) = @_;
574 my @filtered;
575 my $i = 0;
576 my $dirs = dirs->new();
577  
578 my $HOME = _get_home();
579 my $CONFIGURATION = $HOME . '/.L_SU/configuration';
580  
581 # print ("LSU_local_user_constants,get_project_names CONFIGURATION: $CONFIGURATION\n");
582 $dirs->set_dir($CONFIGURATION);
583 my $ls_ref = $dirs->get_ls;
584  
585 foreach my $file (@$ls_ref) {
586  
587 # exclude any files whose full name contains the string 'active' i.e. only one
588 # print("LSU_local_user_constants,get_project_names listing: $file \n");
589 if ( !( $file =~ /active/ ) ) {
590  
591 # print("LSU_local_user_constants,get_project_names filtered: $file \n");
592 # print all other files
593 $filtered[$i] = $file;
594 $i++;
595 }
596 }
597  
598 # print ("1 L_SU_local_user_constants,get_project_names @filtered\n");
599 return ( \@filtered );
600 }
601  
602 sub set_user_configuration_Project_config {
603 my $self = @_;
604  
605 my $HOME = _get_home;
606 my $ACTIVE_PROJECT = _get_ACTIVE_PROJECT;
607  
608 my $user_configuration_Project_config =
609 $ACTIVE_PROJECT . '/Project.config';
610 $L_SU->{_user_configuration_Project_config} =
611 $user_configuration_Project_config;
612  
613 # print(" L_SU_local_user_constants,_set_user_configuration_Project_config \n");
614 # print(" 1 user_configuration_Project_config: $user_configuration_Project_config \n");
615 # print(" 2 user_configuration_Project_config: $L_SU->{_user_configuration_Project_config}\n");
616  
617 return ();
618 }
619  
620 sub set_user_configuration_Project_config2 {
621 my $self = @_;
622  
623 my $HOME = _get_home;
624 my $CONFIGURATION = _get_CONFIGURATION;
625  
626 my $project_name = _get_active_project_name();
627 my $user_configuration_Project_config2 =
628 $CONFIGURATION . '/' . $project_name . '/Project.config';
629 $L_SU->{_user_configuration_Project_config2} =
630 $user_configuration_Project_config2;
631  
632 # print(" L_SU_local_user_constants, set_user_configuration_Project_config\n");
633 # print(" 2 _user_configuration_Project_config2: $L_SU->{_user_configuration_Project_config2}\n");
634 # print(" 2 active_project_name: $project_name\n");
635  
636 return ();
637 }
638  
639 sub _set_user_configuration_Project_config {
640 my $self = @_;
641  
642 my $HOME = _get_home;
643 my $ACTIVE_PROJECT = _get_ACTIVE_PROJECT;
644  
645 my $user_configuration_Project_config =
646 $ACTIVE_PROJECT . '/Project.config';
647 $L_SU->{_user_configuration_Project_config} =
648 $user_configuration_Project_config;
649  
650 # print(" L_SU_local_user_constants,_set_user_configuration_Project_config \n");
651 # print(" 1 user_configuration_Project_config: $user_configuration_Project_config \n");
652 # print(" 2 user_configuration_Project_config: $L_SU->{_user_configuration_Project_config}\n");
653  
654 return ();
655 }
656  
657 sub _set_user_configuration_Project_config2 {
658 my $self = @_;
659  
660  
661 my $HOME = _get_home;
662 my $ACTIVE_PROJECT = _get_ACTIVE_PROJECT;
663  
664 my $user_configuration_Project_config =
665 $ACTIVE_PROJECT . '/Project.config';
666 $L_SU->{_user_configuration_Project_config} =
667 $user_configuration_Project_config;
668  
669 # print(" L_SU_local_user_constants,_set_user_configuration_Project_config \n");
670 # print(" 1 user_configuration_Project_config: $user_configuration_Project_config \n");
671 # print(" 2 user_configuration_Project_config: $L_SU->{_user_configuration_Project_config}\n");
672  
673 return ();
674 }
675  
676 =head2 sub makconfig
677  
678 make ALL configuration directories and files for
679 the first time that L_SU is used
680
681  
682 =cut
683  
684 sub makconfig {
685  
686 my ($self) = @_;
687 use File::Copy;
688  
689 my $ACTIVE_PROJECT = _get_ACTIVE_PROJECT();
690 my $PATH_N_file = $ACTIVE_PROJECT . '/Project.config';
691  
692 # print("L_SU_local_user_constants,makconfig,PATH_N_file : $PATH_N_file\n");
693 _set_default_Project_config();
694 my $default_Project_config = _get_default_Project_config();
695  
696 # print(
697 #"L_SU_local_user_constants,makconfig, default_Project_config: $default_Project_config\n"
698 # );
699 manage_dirs_by->make_dir($ACTIVE_PROJECT);
700 copy( $default_Project_config, $PATH_N_file );
701  
702 # print("L_SU_local_user_constants,makconfig, created $PATH_N_file\n");
703  
704 my $config_name_new = _get_config_name_new();
705 my $PATH_N_config_name =
706 $ACTIVE_PROJECT . '/'
707 . $config_name_new
708 . '.config'; # e.g., /home/username/.L_SU/configuration/active/Project.config
709  
710 my $CONFIGURATION = _get_CONFIGURATION();
711  
712 # REQUIRES /home/gom/.L_SU/configuration/active/Project.config
713 # reads internals of file Project.config
714 my $active_project_name = _get_active_project_name();
715 my $new_PATH = $CONFIGURATION . '/'. $active_project_name;
716 my $new_PATH_N_file = $new_PATH. '/'
717 . $config_name_new
718 . '.config';
719 # e.g., /home/username/.L_SU/configuration/Servilleta/Project.config
720  
721 # print("L_SU_local_user_constants, created ci=onfiguration $new_PATH_N_file\n");
722 manage_dirs_by->make_dir($new_PATH);
723 copy( $default_Project_config, $new_PATH_N_file );
724 # print("L_SU_local_user_constants, copied default Project.config to $new_PATH_N_file\n");
725 }
726  
727 =head2 sub Project_config_exists
728  
729 tests if a user configuration
730 Project.config file exists
731 i.e. should be found inside
732 .L_SU/configuration/active
733
734 =cut
735  
736 sub user_configuration_Project_config_exists {
737 my ($self) = @_;
738  
739 my $false = 0;
740 my $ans = $false;
741 my $true = 1;
742 _set_user_configuration_Project_config();
743 my $Project_config = _get_user_configuration_Project_config();
744  
745 # incldues path
746 if ( -e $Project_config ) {
747 $ans = $true;
748  
749 # print("L_SU_local_user_constants,user_configuration_Project_config_exists,i.e., $Project_config exists\n");
750 }
751 else {
752 $ans = $false;
753 }
754 return ($ans);
755 }
756  
757 1;