2012-04-10 06:11:19 +00:00
|
|
|
#! /usr/bin/env php
|
|
|
|
<?php
|
|
|
|
|
|
|
|
// Job submission and control script for TreeThreader application
|
|
|
|
// from the Institute for Computing Technology in Beijing
|
|
|
|
//
|
|
|
|
|
2012-09-14 08:05:16 +00:00
|
|
|
define("PROJECT", "http://casathome.ihep.ac.cn/");
|
2012-04-10 06:11:19 +00:00
|
|
|
|
|
|
|
function usage() {
|
2012-09-05 14:36:39 +00:00
|
|
|
global $argv;
|
2012-04-10 06:11:19 +00:00
|
|
|
die("
|
|
|
|
Usage:
|
2012-09-05 14:36:39 +00:00
|
|
|
$argv[0] submit sequence_file (submit batch, print batch ID)
|
|
|
|
$argv[0] get_output batch_id (show URL of output file)
|
|
|
|
\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_auth() {
|
|
|
|
return trim(file_get_contents("auth"));
|
2012-04-10 06:11:19 +00:00
|
|
|
}
|
|
|
|
|
2012-04-12 12:20:16 +00:00
|
|
|
function do_http_op($xml, $file=null) {
|
2012-04-12 05:18:22 +00:00
|
|
|
$ch = curl_init(PROJECT."tree_threader.php");
|
2012-04-10 06:11:19 +00:00
|
|
|
curl_setopt($ch, CURLOPT_POST, 1);
|
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
2012-04-12 12:20:16 +00:00
|
|
|
if ($file) {
|
|
|
|
$fields = array('request' => $xml, 'seq_file' => "@$file");
|
|
|
|
} else {
|
|
|
|
$fields = "request=$xml";
|
|
|
|
}
|
|
|
|
if (!curl_setopt($ch, CURLOPT_POSTFIELDS, $fields)) {
|
|
|
|
die("curl_setopt failed\n");
|
|
|
|
}
|
2012-04-10 06:11:19 +00:00
|
|
|
$reply = curl_exec($ch);
|
|
|
|
if (!$reply) return array(null, "HTTP error");
|
|
|
|
$r = simplexml_load_string($reply);
|
|
|
|
if (!$r) return array(null, "Can't parse reply XML: <pre>".htmlentities($reply)."</pre>");
|
|
|
|
return array($r, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
function handle_submit() {
|
|
|
|
global $argc, $argv;
|
2012-09-05 14:36:39 +00:00
|
|
|
if ($argc != 3) usage();
|
2012-04-12 12:20:16 +00:00
|
|
|
if (!is_file($argv[2])) die("seq file missing");
|
2012-09-05 14:36:39 +00:00
|
|
|
$auth = get_auth();
|
2012-04-10 06:11:19 +00:00
|
|
|
$req_xml = "
|
|
|
|
<tt_request>
|
|
|
|
<action>submit</action>
|
|
|
|
<auth>$auth</auth>
|
|
|
|
</tt_request>
|
|
|
|
";
|
2012-04-12 12:20:16 +00:00
|
|
|
list($reply, $errmsg) = do_http_op($req_xml, $argv[2]);
|
2012-04-10 06:11:19 +00:00
|
|
|
if ($errmsg) die("Error: $errmsg\n");
|
2012-09-05 14:36:39 +00:00
|
|
|
print_r($reply);
|
2012-04-13 09:44:01 +00:00
|
|
|
echo "batch ID: ".(int)$reply->batch_id."\n";
|
2012-04-10 06:11:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function handle_get_output() {
|
|
|
|
global $argc, $argv;
|
2012-09-05 14:36:39 +00:00
|
|
|
if ($argc != 3) usage();
|
2012-04-13 05:45:16 +00:00
|
|
|
$batch_id = $argv[2];
|
2012-09-05 14:36:39 +00:00
|
|
|
//$auth = $argv[3];
|
|
|
|
$auth = get_auth();
|
2012-04-10 06:11:19 +00:00
|
|
|
$req_xml = "
|
|
|
|
<tt_request>
|
|
|
|
<action>get_output</action>
|
2012-04-12 07:30:45 +00:00
|
|
|
<batch_id>$batch_id</batch_id>
|
2012-04-10 06:11:19 +00:00
|
|
|
<auth>$auth</auth>
|
|
|
|
</tt_request>
|
|
|
|
";
|
|
|
|
list($reply, $errmsg) = do_http_op($req_xml);
|
|
|
|
if ($errmsg) die("Error: $errmsg\n");
|
2012-04-13 09:44:01 +00:00
|
|
|
echo (string)$reply->url, "\n";
|
2012-04-10 06:11:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($argc < 2) usage();
|
|
|
|
switch ($argv[1]) {
|
|
|
|
case "submit": handle_submit(); break;
|
|
|
|
case "get_output": handle_get_output(); break;
|
|
|
|
default: usage();
|
|
|
|
}
|
2023-05-05 18:05:20 +00:00
|
|
|
|
2012-04-10 06:11:19 +00:00
|
|
|
?>
|