Parent Directory
|
Revision Log
This file constructs links from the courseScripts directory to the pg/lib and pg/macros directories --Mike
1 #!/usr/local/bin/perl -w 2 3 4 5 6 # I am assuming that this script is run from the folder 7 # webwork/system/courseScripts 8 # and the pg folder is at 9 # webwork/pg 10 # Then the correct addresses for the PG folder and the courseScripts (CS) folder are: 11 12 13 # Address of pg/ ... folder 14 my $PGHOME = '../../pg'; 15 16 #Address for the courseScripts folder 17 my $CSHOME = "."; 18 19 # You may need to adjust these two 20 # define the pg/lib directory and pg/macros directory 21 my $libdir = "$PGHOME/lib"; 22 my $macrosdir = "$PGHOME/macros"; 23 # "Fetch the list of files in the courseScripts directory\n"; 24 25 26 27 print "Fetch the list of files in the courseScripts directory: $CSHOME \n"; 28 my @allFiles =(); 29 30 opendir DIR, $CSHOME or die "Can't open directory $CSHOME"; 31 push(@allFiles, grep !/^\./, readdir DIR ); 32 33 closedir DIR; 34 35 print "Fetch the list of files in the pg/lib directory: $libdir \n"; 36 37 opendir DIR, $libdir or die "Can't open directory $libdir"; 38 push(@allFiles, grep !/^\./, readdir DIR ); 39 closedir DIR; 40 41 print "Fetch the list of files in the macros directory: $macrosdir \n"; 42 43 44 opendir DIR, $macrosdir or die "Can't open directory $macrosdir"; 45 push(@allFiles, grep !/^\./, readdir DIR ); 46 closedir DIR; 47 48 print "files ",join(" ", @allFiles), "\n\n"; 49 # remove duplicates from the combined list of files 50 my %allFiles; 51 foreach my $item (@allFiles) { 52 $allFiles{$item}++; 53 } 54 @allFiles = sort keys %allFiles; 55 56 57 print "These files will be linked to files under the $PGHOME directory\n". 58 join(" ",@allFiles) . "\n\n"; 59 60 my @libfiles; 61 my @macrofiles; 62 my @unmovedfiles; # file scoped variable 63 sub linkFile { 64 my $item = shift; 65 my $dir = shift; 66 my $ra_files = shift; 67 if (-e "$dir/$item") { # there is an item to link to 68 if (-e $item ) { # there is already an item in the courseScripts file 69 if (-l $item) { # remove old links 70 print "Removing old link $item\n"; 71 # print "rm $item\n"; 72 `rm $item`; 73 } else { # save old files 74 print "Saving old copy of $item to $item.bak\n"; 75 # print "mv $item $item.bak\n"; 76 `mv $item $item.bak`; 77 } 78 } 79 # create the link 80 print " linking: $item --> $dir/item \n\n"; 81 # print "ln -s $dir/$item $item\n\n"; 82 `ln -s $dir/$item $item`; 83 push( @$ra_files, $item); 84 } else { # Item can't be linked to 85 86 print "File $dir/$item not found\n Can't link to it.\n\n"; 87 push( @unmovedfiles, $item); 88 } 89 90 91 92 93 } 94 95 # Examine each file 96 print "Examining files\n\n"; 97 98 foreach my $item (@allFiles) { 99 100 $item eq 'webworkInit.pm' && next; #This file is only needed in webwork1.8 101 102 $item eq 'MAKELINKS.pl' && next; #This script file need not be linked. 103 104 $item =~ /.pl$/ && do { linkFile($item, $macrosdir, \@macrofiles) 105 106 }; 107 $item =~ /.pg$/ && do { linkFile($item, $macrosdir, \@macrofiles) 108 109 }; 110 $item =~ /.pm$/ && do { linkFile($item, $libdir, \@libfiles) 111 }; 112 113 } 114 115 print "The following files are linked to files in $libdir\n".join(" ", @libfiles)."\n\n"; 116 117 print "The following files are linked to files in $macrosdir\n".join(" ", @macrofiles)."\n\n"; 118 119 print "The following files could not be linked to in $libdir or $macrosdir\n". 120 join(" ", @unmovedfiles)."\n\n"; 121 122 print "Type\n\nls -s\n\n to double check.\n";
| aubreyja at gmail dot com | ViewVC Help |
| Powered by ViewVC 1.0.9 |