« lib/App/SeismicUnixGui/developer/code/sunix/sustkvel_changes.pm
↑ Summary
lib/App/SeismicUnixGui/messages/About.pm »
| 1 | use Moose; | ||
| 2 | |||
| 3 | =head2 SYNOPSIS | ||
| 4 | |||
| 5 | PERL PROGRAM NAME: update_main_version_number.pl | ||
| 6 | |||
| 7 | AUTHOR: | ||
| 8 | |||
| 9 | DATE: V 0.1 May 3 2023 | ||
| 10 | |||
| 11 | DESCRIPTION: replace version number in key files | ||
| 12 | |||
| 13 | Version: 0.1 | ||
| 14 | |||
| 15 | |||
| 16 | =head2 USE | ||
| 17 | |||
| 18 | =head3 NOTES | ||
| 19 | |||
| 20 | |||
| 21 | |||
| 22 | =head4 Examples | ||
| 23 | |||
| 24 | =head2 SYNOPSIS | ||
| 25 | |||
| 26 | =head2 CHANGES and their DATES | ||
| 27 | |||
| 28 | Sep 25 2023 | ||
| 29 | Also change name of the InstallationGuide | ||
| 30 | |||
| 31 | =cut | ||
| 32 | |||
| 33 | use aliased 'App::SeismicUnixGui::misc::manage_files_by2'; | ||
| 34 | use Cwd; | ||
| 35 | |||
| 36 | my $manage_files_by2 = manage_files_by2->new(); | ||
| 37 | |||
| 38 | my ( @file, @file_bck ); | ||
| 39 | my $path; | ||
| 40 | my @path2file; | ||
| 41 | my @inbound; | ||
| 42 | my @outbound_bck; | ||
| 43 | my @outbound; | ||
| 44 | my ( @line2find, @replacement ); | ||
| 45 | my $max_num_files = 6; # +1! | ||
| 46 | |||
| 47 | my $up3dirs = '/../../..'; | ||
| 48 | my $up4dirs = '/../../../..'; | ||
| 49 | |||
| 50 | =head2 set replacement text | ||
| 51 | and file | ||
| 52 | |||
| 53 | =cut | ||
| 54 | |||
| 55 | my $local = getcwd(); | ||
| 56 | my $old_version = '0.87.5'; | ||
| 57 | my $new_version = '0.87.6'; | ||
| 58 | |||
| 59 | my $i = 0; | ||
| 60 | $line2find[$i] = ("L_SUV$old_version.pl"); | ||
| 61 | #print("line2find = $line2find[$i]\n"); | ||
| 62 | $replacement[$i] = ("L_SUV$new_version.pl"); | ||
| 63 | #print("replacement = $replacement[$i]\n"); | ||
| 64 | $file[$i] = 'L_SU.pl'; | ||
| 65 | $path2file[$i] = $local . $up3dirs . '/script'; | ||
| 66 | |||
| 67 | $i = 1; | ||
| 68 | $line2find[$i] = "VERSION = '$old_version';"; | ||
| 69 | #print("line2find = $line2find[$i]\n"); | ||
| 70 | $replacement[$i] = "VERSION = '$new_version';"; | ||
| 71 | #print("replacement = $replacement[$i]\n"); | ||
| 72 | $file[$i] = 'About.pm'; | ||
| 73 | $path2file[$i] = $local . $up3dirs . '/messages'; | ||
| 74 | |||
| 75 | $i = 2; | ||
| 76 | $line2find[$i] = | ||
| 77 | "_program_title => 'SeismicUnixGui V$old_version',"; | ||
| 78 | #print("line2find = $line2find[$i]\n"); | ||
| 79 | $replacement[$i] = | ||
| 80 | "_program_title => 'SeismicUnixGui V$new_version',"; | ||
| 81 | #print("replacement = $replacement[$i]\n"); | ||
| 82 | $file[$i] = 'L_SU_global_constants.pm'; | ||
| 83 | $path2file[$i] = $local . $up3dirs . '/misc'; | ||
| 84 | |||
| 85 | $i = 3; | ||
| 86 | $line2find[$i] = "VERSION = '$old_version';"; | ||
| 87 | #print("line2find = $line2find[$i]\n"); | ||
| 88 | $replacement[$i] = "VERSION = '$new_version';"; | ||
| 89 | #print("replacement = $replacement[$i]\n"); | ||
| 90 | $file[$i] = 'SeismicUnixGui.pm'; | ||
| 91 | $path2file[$i] = $local . $up4dirs; | ||
| 92 | |||
| 93 | $i = 4; | ||
| 94 | $line2find[$i] = "'SeismicUnixGuiInstallationGuide$old_version.pdf';"; | ||
| 95 | print("line2find = $line2find[$i]\n"); | ||
| 96 | $replacement[$i] = "'SeismicUnixGuiInstallationGuide$new_version.pdf';"; | ||
| 97 | print("replacement = $replacement[$i]\n"); | ||
| 98 | $file[$i] = 'help_button_messages.pm'; | ||
| 99 | $path2file[$i] = $local . $up3dirs . '/messages'; | ||
| 100 | |||
| 101 | $i = 5; | ||
| 102 | $line2find[$i] = "'SeismicUnixGuiTutorial$old_version.pdf';"; | ||
| 103 | print("line2find = $line2find[$i]\n"); | ||
| 104 | $replacement[$i] = "'SeismicUnixGuiTutorial$new_version.pdf';"; | ||
| 105 | print("replacement = $replacement[$i]\n"); | ||
| 106 | $file[$i] = 'help_button_messages.pm'; | ||
| 107 | $path2file[$i] = $local . $up3dirs . '/messages'; | ||
| 108 | |||
| 109 | =head2 Set files and paths | ||
| 110 | |||
| 111 | =cut | ||
| 112 | |||
| 113 | for ( my $count = 0 ; $count < $max_num_files; $count++ ) { | ||
| 114 | |||
| 115 | #for ( my $count = 2 ; $count < 3; $count++ ) { | ||
| 116 | |||
| 117 | $file_bck[$count] = $file[$count] . '_bck'; | ||
| 118 | |||
| 119 | $inbound[$count] = $path2file[$count] . '/' . $file[$count]; | ||
| 120 | $outbound[$count] = $path2file[$count] . '/' . $file[$count]; | ||
| 121 | $outbound_bck[$count] = $path2file[$count] . '/archive/' . $file_bck[$count]; | ||
| 122 | |||
| 123 | # save a backup file | ||
| 124 | system("cp $inbound[$count] $outbound_bck[$count]"); | ||
| 125 | |||
| 126 | # slurp every file | ||
| 127 | $manage_files_by2->set_pathNfile( $inbound[$count] ); | ||
| 128 | my $slurp_ref = manage_files_by2->get_whole(); | ||
| 129 | |||
| 130 | my @slurp = @$slurp_ref; | ||
| 131 | my $length_of_slurp = scalar @slurp; | ||
| 132 | |||
| 133 | for ( my $line_idx = 0 ; $line_idx < $length_of_slurp ; $line_idx++ ) { | ||
| 134 | |||
| 135 | # CASE within each *.pm file | ||
| 136 | my $string = $slurp[$line_idx]; | ||
| 137 | |||
| 138 | # chomp $string; # remove all newlines | ||
| 139 | if ( $string =~ m/$line2find[$count]/) { | ||
| 140 | |||
| 141 | $string =~ s/$line2find[$count]/$replacement[$count]/; | ||
| 142 | print(" substitution successful: $string\n"); | ||
| 143 | print(" in file: $file[$count]\n"); | ||
| 144 | |||
| 145 | } | ||
| 146 | |||
| 147 | # print(" string: $string\n"); | ||
| 148 | $slurp[$line_idx] = $string; | ||
| 149 | |||
| 150 | } | ||
| 151 | |||
| 152 | open( OUT, ">","$outbound[$count]" ) | ||
| 153 | or die("File $outbound[$count] not found"); | ||
| 154 | |||
| 155 | # open( OUT, ">","junk" ) | ||
| 156 | # or die("File junk not found"); | ||
| 157 | |||
| 158 | foreach my $text (@slurp) { | ||
| 159 | |||
| 160 | print OUT $text . "\n"; | ||
| 161 | |||
| 162 | # print("$text \n"); | ||
| 163 | } | ||
| 164 | close(OUT); | ||
| 165 | |||
| 166 | } | ||
| 167 | |||
| 168 | print("Do not forget to update the internal name of the SeismicUnixGuiInstallationGuide \n | ||
| 169 | and SeismicUnixTutorial too.\n | ||
| 170 | As well, update other contents of the file as necessary"); |