Changeset - 4e072ce1165f
[Not reviewed]
default
0 2 0
Ethan Zonca (ethanzonca) - 16 years ago 2010-03-14 00:26:35
e@ethanzonca.com
Curlget updates and checks
2 files changed with 17 insertions and 7 deletions:
0 comments (0 inline, 0 general)
src/server/simpleslave.c
Show inline comments
 
@@ -145,29 +145,31 @@ int main(int argc, char *argv[])
 
    if(haveWork)
 
      {
 
        fprintf(stderr,"Got work from server...\n");
 
        /* @TODO: Add remotio hooks */
 
        // jobnum = remoteio_read(jobnum); /* Set jobnum from remoteio (we could use info from struct, but we need this info to download the xmlfile */
 
        // framenum = remoteio_read(jobnum); /* Set framenum from remoteio */
 
        // outputExt = remotio)read(outputExt); /* Set output extension from remotio */
 

	
 
        fprintf(stderr, "Preparing to render frame %d in job %d\n", framenum, jobnum);
 

	
 
        prepareJobPaths(jobnum, framenum, outputExt, datadir, &urltoTar, &pathtoTar, &pathtoJobfile, &urltoOutput, &pathtoOutput);
 
        // free(outputExt);
 

	
 
        if(downloadTar(urltoTar, pathtoTar))
 
          return 1;
 
        int dlret = downloadTar(urltoTar, pathtoTar);
 
        if(dlret == 0)
 
          fprintf(stderr,"Got data tarball\n");
 
        else if(dlret == 3)
 
          return 0; // ouput dir doesn't exist
 
        else
 
          fprintf(stderr,"Got data tarball\n");
 
          fprintf(stderr,"Using existing tarball...\n");
 

	
 
        unpackJob(datadir, pathtoTar);
 

	
 
        /* Execute blender */
 
        if(exec_blender(pathtoJobfile, pathtoOutput, framenum))
 
          {
 
            fprintf(stderr,"Error running Blender. Check your installation and/or your PATH.\n");
 
            return 1;
 
          }
 
        free(pathtoJobfile);
 

	
 
        /* Post-execution */
src/server/slavefuncs.c
Show inline comments
 
@@ -146,25 +146,26 @@ return 0;
 

	
 
/** Retrieves a URL with cURL and saves it to disk */
 
int curlget(char *url, char *out){
 
  fprintf(stderr,"Preparing to download %s",url);
 
  double *Bar; // Stores cURL progress display info
 
  CURL *curl;
 
  CURLcode res;
 
  FILE *outfile;
 

	
 
  curl = curl_easy_init();
 
  if(curl) {
 
	outfile = fopen(out, "w"); // Open where we're writing to
 

	
 
    if(outfile == NULL)
 
      return 2; // Output dir doesn't exist
 
  curl_easy_setopt(curl, CURLOPT_URL, url);
 
  curl_easy_setopt(curl, CURLOPT_WRITEDATA, outfile);
 
  curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curl_writetodisk); // this MUST be set for win32 compat.
 
  curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0);
 
  curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, curl_progress);
 
  curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, &Bar);
 
  res = curl_easy_perform(curl);
 
  curl_easy_cleanup(curl);
 
  }
 
  fprintf(stderr,"\n"); // Clears out he progressbar's carriage return
 
  return res; // 0 is OK, 1 is 404 or other error
 
}
 
@@ -356,39 +357,46 @@ int job_build_path(char *filename, unsig
 
{
 
  return 0;
 
}
 

	
 

	
 
int downloadTar(char *url, char *destinationPath){
 
  // Prepare to download the job tar if it isn't  present
 
  struct stat buffer;
 
  int fstatus = stat(destinationPath, &buffer);
 
  if(fstatus == -1)
 
    {
 
      // Download the Tar
 
      if( curlget(url, destinationPath) == 0){
 
      int ret = curlget(url, destinationPath);
 
      if(ret == 0){
 
        fprintf(stderr, "Job data retrieved successfully\n");
 
        // free(url); @FIXME: causes doublefree! Curl must free the url?
 
        return 0;
 
      }
 
      else {
 
      else if(ret == 1){
 
        fprintf(stderr, "Downloading job data from %s failed. Check your network connection.\n",url);
 
        free(url);
 
        return 1; // Eventually make a retry loop
 
      }
 
      else if(ret == 2){
 
        fprintf(stderr, "Output directory \"%s\" does not exist!\n",destinationPath);
 
        free(url);
 
        return 3;
 
      }
 
    }
 
  else{
 
    fprintf(stderr, "Tar already exists! Download cancelled.\n");
 
    return 2;
 
  }
 

	
 
}
 

	
 

	
 
int uploadOutput(char *pathtoOutput, char *urltoOutput, int jobnum, int framenum, int slavekey){
 
  if( !curlpost(pathtoOutput, urltoOutput, jobnum, framenum, slavekey)) // Uploads output
 
    {
 
      fprintf(stderr,"Upload successful, removing old output...\n");
 
      remove(pathtoOutput); // Delete the file after its uploaded
 
      return 0;
 
    }
 
  else
 
    {
0 comments (0 inline, 0 general)