function handle_get_output($r, $batch)
{
    $wus = BoincWorkUnit::enum("batch={$batch->id}");
    $outdir = "/tmp/tree_threader_output_" . $batch->id;
    @mkdir($outdir);
    foreach ($wus as $wu) {
        if (!$wu->canonical_resultid) {
            continue;
        }
        $result = BoincResult::lookup_id($wu->canonical_resultid);
        if (!$result) {
            continue;
        }
        $paths = get_outfile_paths($result);
        if (sizeof($paths) < 1) {
            continue;
        }
        // there's only one output file
        //
        $path = $paths[0];
        // unzip it into a directory in /tmp
        //
        $dir = "/tmp/{$wu->name}";
        @mkdir($dir);
        $cmd = "cd {$dir}; unzip -q {$path}";
        $ret = system($cmd);
        if ($ret === false) {
            error("can't unzip output file");
        }
        $cmd = "cp {$dir}/ali/* {$outdir}";
        $ret = system($cmd);
        if ($ret === false) {
            error("can't copy output files");
        }
        //system("rm -rf $dir");
    }
    $cmd = "zip -r -q {$outdir} {$outdir}";
    $ret = system($cmd);
    if ($ret === false) {
        error("can't zip output files");
    }
    $fname = "tree_threader_output_" . $batch->id . ".zip";
    @symlink($outdir, "../../download/{$fname}");
    $config = simplexml_load_string(file_get_contents("../../config.xml"));
    $download_url = trim((string) $config->config->download_url);
    echo "<tt_reply>\n<url>{$download_url}/{$fname}</url>\n</tt_reply>\n";
}
Example #2
0
function query_job($r)
{
    xml_start_tag("query_job");
    list($user, $user_submit) = authenticate_user($r, null);
    $job_id = (int) $r->job_id;
    $wu = BoincWorkunit::lookup_id($job_id);
    if (!$wu) {
        xml_error(-1, "no such job");
    }
    $batch = BoincBatch::lookup_id($wu->batch);
    if ($batch->user_id != $user->id) {
        xml_error(-1, "not owner");
    }
    $results = BoincResult::enum("workunitid={$job_id}");
    foreach ($results as $result) {
        echo "    <instance>\n        <name>{$result->name}</name>\n        <id>{$result->id}</id>\n        <state>" . state_string($result) . "</state>\n";
        if ($result->server_state == 5) {
            // over?
            $paths = get_outfile_paths($result);
            foreach ($paths as $path) {
                if (is_file($path)) {
                    $size = filesize($path);
                    echo "        <outfile>\n            <size>{$size}</size>\n        </outfile>\n";
                }
            }
        }
        echo "</instance>\n";
    }
    echo "</query_job>\n";
}
Example #3
0
function handle_get_output($r, $batch)
{
    global $log;
    $timestamp = date("Y-m-d H:i", time());
    $wus = BoincWorkUnit::enum("batch={$batch->id}");
    $outdir = "/tmp/treeThreader_result_" . $batch->id;
    @mkdir($outdir);
    foreach ($wus as $wu) {
        if (!$wu->canonical_resultid) {
            continue;
        }
        $result = BoincResult::lookup_id($wu->canonical_resultid);
        if (!$result) {
            continue;
        }
        $paths = get_outfile_paths($result);
        if (sizeof($paths) < 1) {
            continue;
        }
        // there's only one output file
        //
        $path = $paths[0];
        // unzip it into a directory in /tmp
        //
        $dir = "/tmp/{$wu->name}";
        @mkdir($dir);
        $cmd = "cd {$dir}; unzip -q {$path}";
        system($cmd, $ret);
        if ($ret != 0) {
            error("can't unzip output file");
        }
        $cmd = "cp {$dir}/Aln/* {$outdir}";
        system($cmd, $ret);
        if ($ret != 0) {
            error("can't copy output files");
        }
        system("rm -rf {$dir}");
    }
    $cmd = "zip -r -q {$outdir} {$outdir}";
    system($cmd, $ret);
    if ($ret != $ret) {
        error("can't zip output files");
    }
    $fname = "treeThreader_result_" . $batch->id . ".zip";
    $treeThreader_dir = "treeThreaderResult";
    if (!is_dir("../../download/{$treeThreader_dir}")) {
        mkdir("../../download/{$treeThreader_dir}");
    }
    @symlink("/tmp/{$fname}", "../../download/{$treeThreader_dir}/{$fname}");
    system("rm -fr {$outdir}");
    $config = simplexml_load_string(file_get_contents("../../config.xml"));
    $download_url = trim((string) $config->config->download_url);
    echo "<tt_reply>\n<url>{$download_url}/{$treeThreader_dir}/{$fname}</url>\n</tt_reply>\n";
    $log_msg = "{$timestamp}\tuser {$batch->user_id} downloads results for batch {$batch->id} : {$download_url}/{$treeThreader_dir}/{$fname}\n";
    fwrite($log, $log_msg);
}