Subversion Repositories Koakuma

Rev

Rev 5 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5 Rev 12
Line 1... Line 1...
1
#!/usr/bin/env tclsh
1
#!/usr/bin/env tclsh
2
# $Id: launch-job.in 5 2024-10-01 18:07:27Z nishi $
2
# $Id: launch-job.in 12 2024-10-02 03:25:33Z nishi $
-
 
3
package require tdom
-
 
4
foreach path [glob "@@PREFIX@@/lib/koakuma/utility/*.tcl"] {
-
 
5
	source $path
-
 
6
}
-
 
7
set name ""
-
 
8
set description ""
-
 
9
set dothis ""
-
 
10
foreach arg $argv {
-
 
11
	if { [string range "$arg" 0 0] == "-" } {
-
 
12
		if { "$arg" == "-h" || "$arg" == "--help" } {
-
 
13
			puts "Usage: $argv0 \[-u username\] \[-p password\] \[-R rpc_url\] name description"
-
 
14
			puts "You can set the environment variable `KOAKUMA_RPC' to override default RPC URL."
-
 
15
			puts "Default: http://127.0.0.1/koakuma/rpc"
-
 
16
			exit 0
-
 
17
		} elseif { "$arg" == "-u" } {
-
 
18
			set dothis "set-username"
-
 
19
		} elseif { "$arg" == "-p" } {
-
 
20
			set dothis "set-password"
-
 
21
		} elseif { "$arg" == "-R" } {
-
 
22
			set dothis "set-rpc"
-
 
23
		}
-
 
24
	} else {
-
 
25
		if { "$dothis" == "set-username" } {
-
 
26
			set ::rpc::useranme "$arg"
-
 
27
		} elseif { "$dothis" == "set-password" } {
-
 
28
			set ::rpc::password "$arg"
-
 
29
		} elseif { "$dothis" == "set-rpc" } {
-
 
30
			set RPC_URL "$arg"
-
 
31
		} elseif { "$name" == "" } {
-
 
32
			set name "$arg"
-
 
33
		} elseif { "$description" == "" } {
-
 
34
			set description "$arg"
-
 
35
		}
-
 
36
		set dothis ""
-
 
37
	}
-
 
38
}
-
 
39
 
-
 
40
if { "$name" == "" || "$description" == "" } {
-
 
41
	puts "See --help."
-
 
42
	exit 1
-
 
43
}
-
 
44
 
-
 
45
dom createNodeCmd -tagName "name" -jsonType NONE elementNode keyName
-
 
46
dom createNodeCmd -tagName "description" -jsonType NONE elementNode keyDescription
-
 
47
 
-
 
48
dom createNodeCmd -jsonType STRING textNode valueString
-
 
49
 
-
 
50
set doc [dom createDocumentNode]
-
 
51
 
-
 
52
$doc appendFromScript {
-
 
53
	keyName {valueString "$name"}
-
 
54
	keyDescription {valueString "$description"}
-
 
55
}
-
 
56
 
-
 
57
set result [::rpc::send "/launch-job" "[$doc asJSON]"]
-
 
58
if { [lindex $result 0] == 200 } {
-
 
59
} else {
-
 
60
	set doc [dom parse -json "[lindex $result 1]"]
-
 
61
	puts "Error: [$doc selectNodes "string(/error)"]"
-
 
62
}