#!/usr/bin/perl ###################################################################################### # # This script is executed on an Xgrid agent. # Grid Agent Requirements: # - 10.3.2 (this script uses sips, and other command line tools available on Mac OS X) # - POV-Ray command line must be installed on the agents. ###################################################################################### # Get POV-Ray command line by installing DarwinPorts http://darwinports.opendarwin.org/getdp/ # See the webpage for the latest info how to install it (as of 2/2004, it was using cvs). # # Once you have DarwinPorts, intall POV-Ray using: # sudo ports install povray # # See "Check for POV-Ray" below for a list of the files that need to be copied to each # agent (as of 2/2004). ###################################################################################### # Settings $width = 1280; # Archival picture quality $height = 960; # Archival picture quality $thumbnail_width = $width/16; $thumbnail_height = $height/16; $exist_check_cgi_url = "http://yourserver.edu/cgi-bin/xgrid_check.cgi"; # This cgi checks to see if the file was rendered already (useful if you have to stop and start jobs) $upload_cgi_url = "http://yourserver.edu/cgi-bin/xgrid_upload.cgi"; # This cgi is used to upload the rendered image to the webserver $url_of_pov_files = "http://yourserver.edu/xgridfilelist"; # This folder contains the pov files @filelist = ("Dritver", "Vampire"); ###################################################################################### # Print machine info machine_info(); # Check for Mac OS X 10.3 if (substr(`sw_vers | grep ProductVersion`, 16,4) ne "10.3") { sleep 300; # Stall 5 minutes so that this computer doesn't keep getting assigned jobs) exit; # I wish there was a way to say "This computer can't accept jobs". #die "Mac OS X 10.3 required"; # This doesn't work unfortunately. } # Check for POV-Ray if ( ! -e "/opt/local/bin/povray" or ! -e "/opt/local/etc/povray.conf" or ! -e "/opt/local/etc/povray.ini" or ! -e "/opt/local/lib/libjpeg.62.0.0.dylib" or ! -e "/opt/local/lib/libjpeg.62.dylib" or ! -e "/opt/local/lib/libpng.3.1.2.5.dylib" or ! -e "/opt/local/lib/libpng.3.dylib" or ! -e "/opt/local/lib/libtiff.3.6.1.dylib" or ! -e "/usr/X11R6/lib/libX11.6.2.dylib" or ! -e "/usr/X11R6/lib/libX11.6.dylib") { sleep 300; # Stall 5 minutes so that this computer doesn't keep getting assigned jobs) exit; # I wish there was a way to say "This computer can't accept jobs". #die "POV-Ray must be installed"; # This doesn't work unfortunately. } ###################################################################################### # GO: $my_number = sprintf ("%0.5d",@ARGV[0]); foreach $i (@filelist) { $my_file = $i; print "$my_file$my_number\n"; $smfile = "$my_file${my_number}_".($thumbnail_width)."_".($thumbnail_height).".png"; $lgfile = "$my_file${my_number}_${width}_$height.png"; # Check to see if files have been rendered already $status1 = `curl -d name=$smfile $exist_check_cgi_url`; $status2 = `curl -d name=$lgfile $exist_check_cgi_url`; chomp $status1; chomp $status2; if ($status1 == 1 and $status2 == 1) { print "Files rendered already.\n"; next; } # Render POV-Ray file download_file($my_file, $my_number); render_image($my_file, ($width), ($height), $my_number); create_resized_image($my_file, ($thumbnail_width), ($thumbnail_height), $my_number); # thumbnail quality (80 x 60) system "/bin/mv $my_file$my_number.png $lgfile"; # Rename main file #Upload files print "Uploading files.\n"; system "curl -F file=\@$smfile $upload_cgi_url"; system "curl -F file=\@$lgfile $upload_cgi_url"; # Cleanup system "/bin/rm ${my_file}*"; } final_machine_info(); exit 1; ###################################################################################### sub download_file { my ($filename, $number) = @_; print "----------------------------------------------------\n"; print "Downloading file\n"; system "/usr/bin/curl -O $url_of_pov_files/$filename$number.pov"; } sub render_image { my ($filename, $width, $height, $number) = @_; print "----------------------------------------------------\n"; print "Rendering POV-Ray image\n"; system "/bin/date"; if ( -e "/Users/james/xgrid/benice" ) { print "Being nice!\n"; system "/usr/bin/nice /opt/local/bin/povray -w$width -h$height $filename$number.pov"; } else { system "/opt/local/bin/povray -w$width -h$height $filename$number.pov"; } system "/bin/date"; } sub create_resized_image { my ($filename, $width, $height, $number) = @_; print "----------------------------------------------------\n"; print "Resizing image\n"; system "/bin/cp $filename$number.png $filename${number}_${width}_$height.png"; system "/usr/bin/sips -z $height $width $filename${number}_${width}_$height.png"; system "/bin/date"; } ###################################################################################### sub machine_info { return if $testing; print "----------------------------------------------------\n"; print "The date is: "; system "/bin/date"; print "----------------------------------------------------\n"; print "My hostname is: "; system "/bin/hostname"; print "----------------------------------------------------\n"; print "This computer is:\n"; system "/usr/sbin/system_profiler SPHardwareDataType"; print "----------------------------------------------------\n"; print "My arguments are: @ARGV\n"; print "----------------------------------------------------\n"; print "My executable path is: $0\n"; print "----------------------------------------------------\n"; print "I am currently in this directory: "; system "/bin/pwd"; print "----------------------------------------------------\n"; print "This is all the perl processes running:\n"; system "/bin/ps -awwx | grep perl"; print "----------------------------------------------------\n"; print "This is the contents /var/vm:\n"; system "/bin/ls -l /var/vm"; print "----------------------------------------------------\n"; print "This is the contents of all the sub folders where I am located:\n"; system "/bin/ls -Rl"; } sub final_machine_info { return if $testing; print "----------------------------------------------------\n"; print "This is the contents /var/vm:\n"; system "/bin/ls -l /var/vm"; }