Subversion Repositories Koakuma

Rev

Rev 12 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 nishi 1
#!/usr/bin/env tclsh
2
# $Id: launch-job.in 17 2024-10-02 07:31:01Z nishi $
12 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" } {
17 nishi 26
			::rpc::set-username "$arg"
12 nishi 27
		} elseif { "$dothis" == "set-password" } {
17 nishi 28
			::rpc::set-password "$arg"
12 nishi 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
}