Difference between revisions of "ArchiveSetsAsDefFiles"

From WeBWorK_wiki
Jump to navigation Jump to search
m
Line 5: Line 5:
 
# Author: Nandor Sieben
 
# Author: Nandor Sieben
 
 
@config= `cat $ENV{WEBWORK_ROOT}/conf/global.conf`;
+
@config= `cat $ENV{WEBWORK_ROOT}/conf/global.conf`;
+
for $line (@config) {
for $line (@config) {
+
if ($line =~ /\$database_username.*=.*"(.+)"/) {
if ($line =~ /\$database_username.*=.*"(.+)"/) {
+
$database_username = $1;
$database_username = $1;
+
}
}
+
if ($line =~ /\$database_password.*=.*"(.+)"/) {
if ($line =~ /\$database_password.*=.*"(.+)"/) {
+
$database_password = $1;
$database_password = $1;
+
}
}
+
}
}
+
+
sub mysql {
sub mysql {
+
my ($sql) = @_;
my ($sql) = @_;
+
qx[mysql -s -u $database_username -p$database_password webwork << EOF
qx[mysql -s -u $database_username -p$database_password webwork << EOF
+
$sql
$sql
+
quit
quit
+
EOF
EOF
+
];
];
+
}
}
 
 
 
 
`mkdir def_files`;
 
`mkdir def_files`;

Revision as of 01:26, 7 June 2012

#!/usr/bin/perl

# archiveSetsAsDefFiles 
# Archives all problem sets as def files  
# Author: Nandor Sieben  

@config= `cat $ENV{WEBWORK_ROOT}/conf/global.conf`;
for $line (@config) {
  if ($line =~ /\$database_username.*=.*"(.+)"/) {
    $database_username = $1;
  }
  if ($line =~ /\$database_password.*=.*"(.+)"/) {
    $database_password = $1;
  }
}

sub mysql {
my ($sql) = @_;
qx[mysql -s -u $database_username -p$database_password webwork << EOF
$sql
quit
EOF
];
}

`mkdir def_files`;
@courses= mysql(q[show tables like '%_set';]);

for $course (@courses) {
  $course =~ s/_set.*\n//;
  next if $course =~ /admin/;
  next if $course =~ /problem_library/;
  print "$course\n";
  `mkdir def_files/$course`;
  @sets=mysql(qq[select set_id from $course\_set;]);
  for $set (@sets) {
#    print "$set"; 
    chop $set;
    open F, ">def_files/$course/set$set.def";
    $problems=mysql(qq[select source_file, value, max_attempts from $course\_problem WHERE  set_id = '$set' ;]);
    $problems =~ s/\t/,\t/g;
    print F " 
openDate          = 01/01/2011 at 01:00am MST 
dueDate           = 01/01/2011 at 01:00am MST 
answerDate        = 01/01/2011 at 01:00am MST 
paperHeaderFile   = 
screenHeaderFile  = 
problemList       =  
";
    print F $problems;
    close F;
  }
}