Check-in [5445a8ff26]
Overview
Comment:Better formatting of results
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:5445a8ff26cf801d5db44c0b83ebd8894753d8d3
User & Date: rkeene on 2019-02-28 08:55:59
Other Links: manifest | tags
Context
2019-02-28
09:20
More metadata in API check-in: e9fdb85e3f user: rkeene tags: trunk
08:55
Better formatting of results check-in: 5445a8ff26 user: rkeene tags: trunk
08:55
Added a simple API client check-in: c0f939a115 user: rkeene tags: trunk
Changes

Modified build/web/building.cgi from [fa17a7dcc9] to [ce6b7093ed].

12
13
14
15
16
17
18






19
20
21
22
23
24
25
...
110
111
112
113
114
115
116

117
118
119
120
121
122
123
124
125
126
127
128
129
130
131











132
133
134
135
136
137
138
139
140
141
142
143
144
145








146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
}
set key [lindex $info end]
set resultFormat "html"
if {[llength $info] > 1} {
	set resultFormat [lindex $info 0]
}







set status "Unknown"
set terminal 0
if {![regexp {^[0-9a-f]+$} $key]} {
	set status "Invalid Key"
	set terminal 1

	unset key
................................................................................
		append description ", Packages: [join $buildinfo(packages) {, }]"
	} else {
		append description ", No packages"
	}
}

if {[info exists outfile]} {

	if {[file exists $outfile]} {
		set status "Complete"
		set terminal 1

		set url "http://kitcreator.rkeene.org/kits/$key/$filename"
	} elseif {[file exists "${outfile}.buildfail"]} {
		set status "Failed"
		set terminal 1
	} else {
		set status "Building"
	}
}

if {$resultFormat in {json dict}} {
	set terminalBoolean [lindex {false true} $terminal]











}

switch -exact -- $resultFormat {
	"html" {
		# Handled below
	}
	"json" {
		puts "Content-Type: application/json"
		puts ""
		if {$status eq "Complete"} {
			puts "{\"status\":\"[string tolower $status]\", \"terminal\": $terminalBoolean, \"kit_url\":\"$url\"}"
		} else {
			puts "{\"status\":\"[string tolower $status]\", \"terminal\": $terminalBoolean}"
		}








		exit 0
	}
	"dict" {
		puts "Content-Type: text/plain"
		puts ""
		if {$status eq "Complete"} {
			puts [dict create \
				status [string tolower $status] \
				terminal $terminalBoolean \
				kit_url $url \
			]
		} else {
			puts [dict create \
				status [string tolower $status] \
				terminal $terminalBoolean \
			]
		}
		exit 0
	}
	default {
		exit 1
	}
}








>
>
>
>
>
>







 







>




|










>
>
>
>
>
>
>
>
>
>
>









|
|
|
|
|
>
>
>
>
>
>
>
>





|
<
<
<
<
<
<
<
<
<
<
<







12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
...
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177











178
179
180
181
182
183
184
}
set key [lindex $info end]
set resultFormat "html"
if {[llength $info] > 1} {
	set resultFormat [lindex $info 0]
}

set scheme http
if {[info exists ::env(HTTPS)]} {
	set scheme https
}
set base_url "${scheme}://kitcreator.rkeene.org/kits/$key"

set status "Unknown"
set terminal 0
if {![regexp {^[0-9a-f]+$} $key]} {
	set status "Invalid Key"
	set terminal 1

	unset key
................................................................................
		append description ", Packages: [join $buildinfo(packages) {, }]"
	} else {
		append description ", No packages"
	}
}

if {[info exists outfile]} {
	set build_log_url "${base_url}/${filename}.log"
	if {[file exists $outfile]} {
		set status "Complete"
		set terminal 1

		set url "${base_url}/$filename"
	} elseif {[file exists "${outfile}.buildfail"]} {
		set status "Failed"
		set terminal 1
	} else {
		set status "Building"
	}
}

if {$resultFormat in {json dict}} {
	set terminalBoolean [lindex {false true} $terminal]

	set resultsDict [dict create \
		status [string tolower $status] \
		terminal $terminalBoolean \
	]
	if {[string tolower $status] eq "complete"} {
		dict set resultsDict kit_url $url
	}
	if {[string tolower $status] in {complete building}} {
		dict set resultsDict build_log_url $build_log_url
	}
}

switch -exact -- $resultFormat {
	"html" {
		# Handled below
	}
	"json" {
		puts "Content-Type: application/json"
		puts ""
		set resultsJSONItems [list]
		foreach {key value} $resultsDict {
			switch -exact -- $key {
				"terminal" {
				}
				default {
					set value "\"$value\""
				}
			}
			lappend resultsJSONItems "\"$key\": $value"
		}
		set resultsJSON "{[join $resultsJSONItems {, }]}"
		puts $resultsJSON
		exit 0
	}
	"dict" {
		puts "Content-Type: text/plain"
		puts ""
		puts $resultsDict











		exit 0
	}
	default {
		exit 1
	}
}