File: ict_job

package info (click to toggle)
boinc 7.14.2%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 111,132 kB
  • sloc: cpp: 163,589; php: 113,173; ansic: 49,284; pascal: 35,620; xml: 17,864; java: 13,521; python: 6,551; sh: 4,082; perl: 1,843; makefile: 1,796; objc: 1,543; sql: 959; csh: 126; lisp: 47
file content (84 lines) | stat: -rwxr-xr-x 2,131 bytes parent folder | download | duplicates (10)
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();
}
   
?>