-
Notifications
You must be signed in to change notification settings - Fork 452
/
ict_job
executable file
·84 lines (75 loc) · 2.08 KB
/
ict_job
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#! /usr/bin/env php
<?php
// Job submission and control script for TreeThreader application
// from the Institute for Computing Technology in Beijing
//
define("PROJECT", "http://casathome.ihep.ac.cn/");
function usage() {
global $argv;
die("
Usage:
$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"));
}
function do_http_op($xml, $file=null) {
$ch = curl_init(PROJECT."tree_threader.php");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
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");
}
$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;
if ($argc != 3) usage();
if (!is_file($argv[2])) die("seq file missing");
$auth = get_auth();
$req_xml = "
<tt_request>
<action>submit</action>
<auth>$auth</auth>
</tt_request>
";
list($reply, $errmsg) = do_http_op($req_xml, $argv[2]);
if ($errmsg) die("Error: $errmsg\n");
print_r($reply);
echo "batch ID: ".(int)$reply->batch_id."\n";
}
function handle_get_output() {
global $argc, $argv;
if ($argc != 3) usage();
$batch_id = $argv[2];
//$auth = $argv[3];
$auth = get_auth();
$req_xml = "
<tt_request>
<action>get_output</action>
<batch_id>$batch_id</batch_id>
<auth>$auth</auth>
</tt_request>
";
list($reply, $errmsg) = do_http_op($req_xml);
if ($errmsg) die("Error: $errmsg\n");
echo (string)$reply->url, "\n";
}
if ($argc < 2) usage();
switch ($argv[1]) {
case "submit": handle_submit(); break;
case "get_output": handle_get_output(); break;
default: usage();
}
?>