#!/usr/bin/perl -w
use English;
sub execute_cmd {
my($this_cmd) = pop(@_);
my($pid);
printf "Executing '$cmd' \n";
$pid = open (LAST,"$cmd |");
while () {
print $_;
}
close(LAST);
}
$_=`/usr/ucb/whoami`;
chop;
$person = $_;
## Change these variables
$simdir = "project";
$assignment="cad_project";
$target_dir = "/home/reese/cad_dev/sims/$person";
#@files = ("$simdir/ddrf301.L");
@files = (); # for file check
$clean_cmd = "/home/reese/bin/altera_clean $simdir";
#####
$tarname="tmp_submit";
$uuname = $tarname . "\.uu";
$maxsize = 5000000;
$fail = 0;
if (!-e $simdir) {
printf "Expecting a directory named $simdir\n. File not submitted.\n";
exit(1);
}
# clean directory
printf "Cleaning directory $simdir of unnecessary files...\n ";
chdir($simdir);
opendir(INPUT,"./");
@flist = readdir(INPUT);
closedir(INPUT);
@extlist = (".cnf", ".pof", ".vhdlview", ".synthesisview",
".hif", ".mmf", ".fit", ".hex", ".ndb", ".rpt",
".snf", ".ttf", ".log", ".idx", ".db0", ".db1",
".db2", ".dls", ".tbl");
foreach $file (@flist) {
foreach $ext (@extlist) {
if ($file=~/\Q$ext\E$/i) {
if (!(-d $file)) {
print $file;
print "\n";
unlink($file);
}
}
}
}
chdir("../");
foreach $file (@files) {
printf "Checking existence of: $file \n";
if (!(-e $file)) {
printf STDERR "Can't find file: $file\n";
$fail = 1;
}
}
if ($fail) {
printf STDERR "File Existence check failed, project not submitted \n";
exit(-1);
}
printf STDERR "Creating uuencoded tar file...\n";
$cmd = "tar cf $tarname.tar $simdir";
&execute_cmd($cmd);
if (!(-e "$tarname.tar")) {
printf STDERR "Tar file creation failed. Internal error, send email to reese\@erc.msstate.edu \n";
printf STDERR "Homework not submitted.\n";
exit(-1);
}
@fstats = stat("$tarname.tar");
$fsize = $fstats[7];
if ($fsize > $maxsize) {
print STDERR "Your TAR file ($tarname.tar) submission is too big (> $maxsize bytes) \n";
print STDERR "Make sure only ESSENTIAL files are in the $simdir directory. \n";
print STDERR "File not submitted.\n";
exit(-1);
}
$cmd = "uuencode $tarname.tar $target_dir/$tarname.tar \> $uuname";
printf STDERR "Executing $cmd \n";
`$cmd`;
if (!(-e $uuname)) {
printf STDERR "UUencoded tar file creation failed. Internal error, send email to reese\@erc.msstate.edu \n";
printf STDERR "Project not submitted.\n";
exit(-1);
}
printf STDERR "Mailing uuencoded tar file...\n";
$cmd = "mailx -s $assignment reese\@erc.msstate.edu $person < $uuname";
&execute_cmd($cmd);
`rm -f $tarname.tar $uuname`;
printf STDERR "Project submitted. Mailed to both reese\@erc.msstate.edu and $person\n";