Ejemplo n.º 1
0
void StagePackager::package(const char *stageName, const char *version,
                            bool obfuscate) {
  bool refresh = true;
  try {
    fileManager_->packageStage(getStagesDir().c_str(), stageName, version,
                               getCacheDir().c_str(), getTmpDir().c_str(),
                               obfuscate, false);
  } catch (FileExistsException *e) {
    std::stringstream overwriteStream;
    overwriteStream << "File already exists: " << e->what() << std::endl
                    << std::endl << "OK to overwrite it?";
    wxMessageDialog errorMessage(NULL, overwriteStream.str(), "Are you sure?",
                                 wxOK | wxCANCEL | wxICON_QUESTION);
    int r = errorMessage.ShowModal();
    if (r == wxID_OK) {
      fileManager_->packageStage(getStagesDir().c_str(), stageName, version,
                                 getCacheDir().c_str(), getTmpDir().c_str(),
                                 obfuscate, true);
      fileManager_->deleteFromCache(getCacheDir().c_str(), e->what());
    } else {
      refresh = false;
    }
    delete e;
  } catch (std::exception *e) {
    packagingConsole_->clear();
    packagingConsole_->Show();
    packagingConsole_->println("Packaging stage failed: ");
    packagingConsole_->print("  ");
    packagingConsole_->println(e->what());
    refresh = false;
    delete e;
  }

  if (refresh) {
    guiManager_->loadStages();
  }
}
Ejemplo n.º 2
0
char* GuiManager::getTmpDirCopy() {
  char *tmpDir = new char[getTmpDir().length() + 1];
  strcpy(tmpDir, getTmpDir().c_str());
  return tmpDir;
}
Ejemplo n.º 3
0
bool ThemeLoader::extract( const std::string &fileName )
{
    bool result = true;
    std::string tempPath = getTmpDir();
    if( tempPath.empty() )
        return false;

    // Extract the file in a temporary directory
    if( ! extractTarGz( fileName, tempPath ) &&
        ! extractZip( fileName, tempPath ) )
    {
        deleteTempFiles( tempPath );
        return false;
    }

    std::string path;
    std::string xmlFile;
    OSFactory *pOsFactory = OSFactory::instance( getIntf() );
    // Find the XML file in the theme
    if( findFile( tempPath, DEFAULT_XML_FILE, xmlFile ) )
    {
        path = getFilePath( xmlFile );
    }
    else
    {
        // No XML file, check if it is a winamp2 skin
        std::string mainBmp;
        if( findFile( tempPath, "main.bmp", mainBmp ) )
        {
            msg_Dbg( getIntf(), "trying to load a winamp2 skin" );
            path = getFilePath( mainBmp );

            // Look for winamp2.xml in the resource path
            std::list<std::string> resPath = pOsFactory->getResourcePath();
            std::list<std::string>::const_iterator it;
            for( it = resPath.begin(); it != resPath.end(); ++it )
            {
                if( findFile( *it, WINAMP2_XML_FILE, xmlFile ) )
                    break;
            }
        }
    }

    if( !xmlFile.empty() )
    {
        // Parse the XML file
        if (! parse( path, xmlFile ) )
        {
            msg_Err( getIntf(), "error while parsing %s", xmlFile.c_str() );
            result = false;
        }
    }
    else
    {
        msg_Err( getIntf(), "no XML found in theme %s", fileName.c_str() );
        result = false;
    }

    // Clean-up
    deleteTempFiles( tempPath );
    return result;
}
Ejemplo n.º 4
0
// create the command that will actually launch the program and
// create any files needed for the launch like the batch script
static char* chpl_launch_create_command(int argc, char* argv[],
                                        int32_t numLocales) {
    int i;
    int size;
    char baseCommand[MAX_COM_LEN];
    char* command;
    FILE* slurmFile;
    char* account = getenv("CHPL_LAUNCHER_ACCOUNT");
    char* constraint = getenv("CHPL_LAUNCHER_CONSTRAINT");
    char* outputfn = getenv("CHPL_LAUNCHER_SLURM_OUTPUT_FILENAME");
    char* basenamePtr = strrchr(argv[0], '/');
    pid_t mypid;

    // For programs with large amounts of output, a lot of time can be
    // spent syncing the stdout buffer to the output file. This can cause
    // tests to run extremely slow and can cause stdout and stderr to
    // become mixed in odd ways since stdout is buffered but stderr isn't.
    // To alleviate this problem (and to allow accurate external timings
    // of tests) this allows the output to be "buffered" to <tmpDir> and
    // copied once the job is done.
    //
    // Note that this should work even for multi-locale tests since all
    // the output is piped through a single node.
    //
    // The *NoFmt versions are the same as the regular version, except
    // that instead of using slurms output formatters, they use the
    // corresponding env var. e.g. you have to use '--output=%j.out to
    // have the output file be <jobid>.out, but when we copy the tmp file
    // to the real output file, the %j and other formatters aren't
    // available so we have to use the equivalent slurm env var
    // (SLURM_JOB_ID.) The env vars can't be used when specifying --output
    // because they haven't been initialized yet
    char* bufferStdout    = getenv("CHPL_LAUNCHER_SLURM_BUFFER_STDOUT");
    const char* tmpDir    = getTmpDir();
    char stdoutFile         [MAX_COM_LEN];
    char stdoutFileNoFmt    [MAX_COM_LEN];
    char tmpStdoutFile      [MAX_COM_LEN];
    char tmpStdoutFileNoFmt [MAX_COM_LEN];

    // command line walltime takes precedence over env var
    if (!walltime) {
        walltime = getenv("CHPL_LAUNCHER_WALLTIME");
    }

    // command line nodelist takes precedence over env var
    if (!nodelist) {
        nodelist = getenv("CHPL_LAUNCHER_NODELIST");
    }

    // command line partition takes precedence over env var
    if (!partition) {
        partition = getenv("CHPL_LAUNCHER_PARTITION");
    }

    // command line exclude takes precedence over env var
    if (!exclude) {
        exclude = getenv("CHPL_LAUNCHER_EXCLUDE");
    }

    if (basenamePtr == NULL) {
        basenamePtr = argv[0];
    } else {
        basenamePtr++;
    }

    chpl_compute_real_binary_name(argv[0]);

    if (debug) {
        mypid = 0;
    } else {
        mypid = getpid();
    }

    // Elliot, 12/02/14: TODO we have a bunch of similar commands to build up the
    // interactive and batch versions. It would be nicer to build up the commands
    // and postprocess depending on interactive vs batch. As in build up "--quiet
    // --nodes ..." and afterwards split on ' ' and then add #SBATCH and a
    // newline for batch mode and leave it as is for interactive"

    // if were running a batch job
    if (getenv("CHPL_LAUNCHER_USE_SBATCH") != NULL || generate_sbatch_script) {
        // set the sbatch filename
        sprintf(slurmFilename, "%s%d", baseSBATCHFilename, (int)mypid);

        // open the batch file and create the header
        slurmFile = fopen(slurmFilename, "w");
        fprintf(slurmFile, "#!/bin/sh\n\n");

        // set the job name
        fprintf(slurmFile, "#SBATCH --job-name=Chpl-%.10s\n", basenamePtr);

        // suppress informational messages, will still display errors
        fprintf(slurmFile, "#SBATCH --quiet\n");

        // request the number of locales, with 1 task per node, and number of cores
        // cpus-per-task. We probably don't need --nodes and --ntasks specified
        // since 1 task-per-node with n --tasks implies -n nodes
        fprintf(slurmFile, "#SBATCH --nodes=%d\n", numLocales);
        fprintf(slurmFile, "#SBATCH --ntasks=%d\n", numLocales);
        fprintf(slurmFile, "#SBATCH --ntasks-per-node=%d\n", procsPerNode);
        fprintf(slurmFile, "#SBATCH --cpus-per-task=%d\n", getCoresPerLocale());

        //request exclusive access to nodes
        fprintf(slurmFile, "#SBATCH --exclusive\n");

        // Set the walltime if it was specified
        if (walltime) {
            fprintf(slurmFile, "#SBATCH --time=%s\n", walltime);
        }

        // Set the nodelist if it was specified
        if (nodelist) {
            fprintf(slurmFile, "#SBATCH --nodelist=%s\n", nodelist);
        }

        // Set the partition if it was specified
        if (partition) {
            fprintf(slurmFile, "#SBATCH --partition=%s\n", partition);
        }

        // Set the exclude list if it was specified
        if (exclude) {
            fprintf(slurmFile, "#SBATCH --exclude=%s\n", exclude);
        }

        // If needed a constraint can be specified with the env var CHPL_LAUNCHER_CONSTRAINT
        if (constraint) {
            fprintf(slurmFile, "#SBATCH --constraint=%s\n", constraint);
        }

        // set the account name if one was provided
        if (account && strlen(account) > 0) {
            fprintf(slurmFile, "#SBATCH --account=%s\n", account);
        }

        // set the output file name to either the user specified
        // name or to the binaryName.<jobID>.out if none specified
        if (outputfn != NULL) {
            sprintf(stdoutFile,      "%s", outputfn);
            sprintf(stdoutFileNoFmt, "%s", outputfn);
        }
        else {
            sprintf(stdoutFile,      "%s.%s.out", argv[0], "%j");
            sprintf(stdoutFileNoFmt, "%s.%s.out", argv[0], "$SLURM_JOB_ID");
        }

        // We have slurm use the real output file to capture slurm errors/timeouts
        // We only redirect the program output to the tmp file
        fprintf(slurmFile, "#SBATCH --output=%s\n", stdoutFile);

        // If we're buffering the output, set the temp output file name.
        // It's always <tmpDir>/binaryName.<jobID>.out.
        if (bufferStdout != NULL) {
            sprintf(tmpStdoutFile,      "%s/%s.%s.out", tmpDir, argv[0], "%j");
            sprintf(tmpStdoutFileNoFmt, "%s/%s.%s.out", tmpDir, argv[0], "$SLURM_JOB_ID");
        }

        // add the srun command and the (possibly wrapped) binary name.
        fprintf(slurmFile, "srun --kill-on-bad-exit %s %s ",
                chpl_get_real_binary_wrapper(), chpl_get_real_binary_name());

        // add any arguments passed to the launcher to the binary
        for (i=1; i<argc; i++) {
            fprintf(slurmFile, "'%s' ", argv[i]);
        }

        // buffer program output to the tmp stdout file
        if (bufferStdout != NULL) {
            fprintf(slurmFile, "&> %s", tmpStdoutFileNoFmt);
        }
        fprintf(slurmFile, "\n");

        // After the job is run, if we buffered stdout to <tmpDir>, we need
        // to copy the output to the actual output file. The <tmpDir> output
        // will only exist on one node, ignore failures on the other nodes
        if (bufferStdout != NULL) {
            fprintf(slurmFile, "cat %s >> %s\n", tmpStdoutFileNoFmt, stdoutFileNoFmt);
            fprintf(slurmFile, "rm  %s &> /dev/null\n", tmpStdoutFileNoFmt);
        }

        // close the batch file and change permissions
        fclose(slurmFile);
        chmod(slurmFilename, 0755);

        if (generate_sbatch_script) {
            fprintf(stdout, "SBATCH script written to '%s'\n", slurmFilename);
        }

        // the baseCommand is what will call the batch file
        // that was just created
        sprintf(baseCommand, "sbatch %s\n", slurmFilename);
    }
    // else we're running an interactive job
    else {
        char iCom[1024];
        int len;

        len = 0;

        // set the job name
        len += sprintf(iCom+len, "--job-name=CHPL-%.10s ",basenamePtr);

        // suppress informational messages, will still display errors
        len += sprintf(iCom+len, "--quiet ");

        // request the number of locales, with 1 task per node, and number of cores
        // cpus-per-task. We probably don't need --nodes and --ntasks specified
        // since 1 task-per-node with n --tasks implies -n nodes
        len += sprintf(iCom+len, "--nodes=%d ",numLocales);
        len += sprintf(iCom+len, "--ntasks=%d ", numLocales);
        len += sprintf(iCom+len, "--ntasks-per-node=%d ", procsPerNode);
        len += sprintf(iCom+len, "--cpus-per-task=%d ", getCoresPerLocale());

        // request exclusive access
        len += sprintf(iCom+len, "--exclusive ");

        // kill the job if any program instance halts with non-zero exit status
        len += sprintf(iCom+len, "--kill-on-bad-exit ");

        // Set the walltime if it was specified
        if (walltime) {
            len += sprintf(iCom+len, "--time=%s ",walltime);
        }

        // Set the nodelist if it was specified
        if (nodelist) {
            len += sprintf(iCom+len, "--nodelist=%s ", nodelist);
        }

        // Set the partition if it was specified
        if (partition) {
            len += sprintf(iCom+len, "--partition=%s ", partition);
        }

        // Set the exclude list if it was specified
        if (exclude) {
            len += sprintf(iCom+len, "--exclude=%s ", exclude);
        }

        // set any constraints
        if (constraint) {
            len += sprintf(iCom+len, " --constraint=%s ", constraint);
        }

        // set the account name if one was provided
        if (account && strlen(account) > 0) {
            len += sprintf(iCom+len, "--account=%s ", account);
        }

        // add the (possibly wrapped) binary name
        len += sprintf(iCom+len, "%s %s ",
                       chpl_get_real_binary_wrapper(), chpl_get_real_binary_name());

        // add any arguments passed to the launcher to the binary
        for (i=1; i<argc; i++) {
            len += sprintf(iCom+len, "%s ", argv[i]);
        }

        // launch the job using srun
        sprintf(baseCommand, "srun %s ", iCom);
    }

    // copy baseCommand into command and return it
    size = strlen(baseCommand) + 1;
    command = chpl_mem_allocMany(size, sizeof(char), CHPL_RT_MD_COMMAND_BUFFER, -1, 0);
    sprintf(command, "%s", baseCommand);
    if (strlen(command)+1 > size) {
        chpl_internal_error("buffer overflow");
    }

    return command;
}
Ejemplo n.º 5
0
char* StagePreview::savePreviewImage(sf::RenderWindow *window,
    BerryBotsEngine *engine, unsigned int &targetWidth,
    unsigned int &targetHeight) {
  Stage *stage = engine->getStage();
  double backingScale = getBackingScaleFactor();
  unsigned int viewWidth = stage->getWidth() + (2 * STAGE_MARGIN);
  unsigned int viewHeight = stage->getHeight() + (2 * STAGE_MARGIN);
  unsigned int screenWidth = backingScale * MAX_PREVIEW_WIDTH;
  unsigned int screenHeight = backingScale * MAX_PREVIEW_HEIGHT;
  double windowScale =
      std::min(backingScale, std::min(((double) screenWidth) / viewWidth,
                                      ((double) screenHeight) / viewHeight));
  targetWidth = round(windowScale * viewWidth);
  targetHeight = round(windowScale * viewHeight);

#ifdef __WXGTK__
  // Since setSize() doesn't work reliably, we create it inline on Linux.
  window = new sf::RenderWindow(
      sf::VideoMode(targetWidth, targetHeight), "Preview",
      sf::Style::None,
      sf::ContextSettings(0, 0, (isAaDisabled() ? 0 : 4), 2, 0));
  window->setVisible(false);
#else
  window->setSize(sf::Vector2u(targetWidth, targetHeight));
#endif

  Team **teams = new Team*[1];
  teams[0] = new Team;
  strcpy(teams[0]->name, "PreviewTeam");
  teams[0]->numRectangles = 0;
  teams[0]->numLines = 0;
  teams[0]->numCircles = 0;
  teams[0]->numTexts = 0;
  Ship **ships = new Ship*[1];
  Ship *ship = new Ship;
  ShipProperties *properties = new ShipProperties;
  properties->shipR = properties->shipG = properties->shipB = 255;
  properties->laserR = properties->laserB = 0;
  properties->laserG = 255;
  properties->thrusterR = 255;
  properties->thrusterG = properties->thrusterB = 0;
  strcpy(properties->name, "PreviewShip");
  ship->properties = properties;
  ship->thrusterAngle = ship->thrusterForce = 0;
  Point2D *start = stage->getStart();
  ship->x = start->getX();
  ship->y = start->getY();
  ship->alive = true;
  ship->showName = ship->energyEnabled = false;
  ships[0] = ship;
  teams[0]->numTexts = 0;
  stage->setTeamsAndShips(teams, 1, ships, 1);

  previewGfxManager_->initBbGfx(window, backingScale, viewHeight, stage, teams,
                                1, ships, 1);
  previewGfxManager_->initViews(window, viewWidth, viewHeight);

  GfxEventHandler *gfxHandler = new GfxEventHandler();
  window->clear();
  previewGfxManager_->drawGame(window, stage, ships, 1, 0, gfxHandler, false,
                               false, 0);

  std::stringstream filenameStream;
  filenameStream << (rand() % 10000000) << ".png";
  char *filename = fileManager_->getFilePath(getTmpDir().c_str(),
                                             filenameStream.str().c_str());
  char *absFilename = fileManager_->getAbsFilePath(filename);
  delete filename;

  sf::Image previewImage = window->capture();
  fileManager_->createDirectoryIfNecessary(getTmpDir().c_str());
  previewImage.saveToFile(absFilename);
#ifdef __WXGTK__
  delete window;
#endif
  previewGfxManager_->destroyBbGfx();

  delete gfxHandler;
  delete properties;
  delete teams[0];
  delete teams;

  return absFilename;
}