forked from openwebwork/admintools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
npl-problem-pointer
executable file
·124 lines (93 loc) · 3.53 KB
/
npl-problem-pointer
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
#!/usr/bin/perl
# Make a Problem Library type pointer to the given problem
# This new pg file will tell webwork to process the contents of
# the existing pg file when used as a problem. It includes the
# tags which tell NPL-update to ignore it.
# See the usage statements below. The first argument is the
# existing path. The second argument is the place to put the
# special file. There should not be a file in that position
# already. This is a safety feature in case the script is
# called with the arguments reversed. So, if file1 is a duplicate
# of file2 and you want to keep file1 and make file2 the linking
# file, then delete file2 before calling this script.
# This needs to be called from the top directory of the Problem
# Library (so the directory containing 270, Indiana, Michigan, etc.
# This script does not execute any cvs commands. If a file really is
# new, then you would need "cvs add". If you just deleted a file and
# are now putting in the linking file, then you would just need "cvs up"
# If you have several files, you may want to deal with them all and
# then call "cvs up" just once.
# This could be made nicer in several ways:
# - pod style documentation
# - command line flag to delete the second argument if it already
# exists
# - command line flag to call cvs update
# - declare more variables with "my"
use File::Basename;
if(scalar(@ARGV) != 2) {
print "Usage: npl-problem-pointer existing/path new/path\n";
print "Paths should not start with Library\n";
print "Run me from the top of the problem library.\n";
exit();
}
$existpath = $ARGV[0];
$newpath = $ARGV[1];
if( -f $newpath ) {
print "I don't want to overwrite $newpath ... quitting\n";
exit();
}
sub surePathToFile($) {
# constructs intermediate directories enroute to the file
# the input path must be the path relative to this starting directory
my $start_directory = "";
my $path = shift;
my $delim = "/";
unless ($path ) {
warn "missing directory<br> surePathToFile start_directory pa
th ";
return '';
}
my ($perms, $groupID) = (stat ".")[2,5];
#$path =~ s|^$start_directory|| if $path =~ m|^$start_directory|;
# find the nodes on the given path
my @nodes = split("$delim",$path);
# create new path
$path = $start_directory;
while (@nodes>1) { # the last node is the file name
$path = $path . shift (@nodes) . "/";
unless (-e $path) {
mkdir($path, $perms)
or warn "Failed to create directory $path with start directory $start_directory ";
system("cvs add $path");
}
}
$path = $path . shift(@nodes);
return $path;
}
$dir = dirname($newpath);
$fname = basename($newpath);
surePathToFile($newpath);
if(not open(OUF, ">$newpath")) {
print "Cannot write to $newpath ... quitting\n";
exit();
}
# Make the directory if we have to
print OUF <<"HERE";
# This file is just a pointer to the file
#
# "Library/$existpath"
#
# You may want to change your problem set to use that problem
# directly, especially if you want to make a copy of the problem
# for modification.
DOCUMENT();
includePGproblem("Library/$existpath");
ENDDOCUMENT();
## These tags keep this problem from being added to the NPL database
##
## DBsubject('ZZZ-Inserted Text')
## DBchapter('ZZZ-Inserted Text')
## DBsection('ZZZ-Inserted Text')
HERE
close(OUF);
#system("cvs add $newpath");