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     12   }
    13     13   set key [lindex $info end]
    14     14   set resultFormat "html"
    15     15   if {[llength $info] > 1} {
    16     16   	set resultFormat [lindex $info 0]
    17     17   }
    18     18   
           19  +set scheme http
           20  +if {[info exists ::env(HTTPS)]} {
           21  +	set scheme https
           22  +}
           23  +set base_url "${scheme}://kitcreator.rkeene.org/kits/$key"
           24  +
    19     25   set status "Unknown"
    20     26   set terminal 0
    21     27   if {![regexp {^[0-9a-f]+$} $key]} {
    22     28   	set status "Invalid Key"
    23     29   	set terminal 1
    24     30   
    25     31   	unset key
................................................................................
   110    116   		append description ", Packages: [join $buildinfo(packages) {, }]"
   111    117   	} else {
   112    118   		append description ", No packages"
   113    119   	}
   114    120   }
   115    121   
   116    122   if {[info exists outfile]} {
          123  +	set build_log_url "${base_url}/${filename}.log"
   117    124   	if {[file exists $outfile]} {
   118    125   		set status "Complete"
   119    126   		set terminal 1
   120    127   
   121         -		set url "http://kitcreator.rkeene.org/kits/$key/$filename"
          128  +		set url "${base_url}/$filename"
   122    129   	} elseif {[file exists "${outfile}.buildfail"]} {
   123    130   		set status "Failed"
   124    131   		set terminal 1
   125    132   	} else {
   126    133   		set status "Building"
   127    134   	}
   128    135   }
   129    136   
   130    137   if {$resultFormat in {json dict}} {
   131    138   	set terminalBoolean [lindex {false true} $terminal]
          139  +
          140  +	set resultsDict [dict create \
          141  +		status [string tolower $status] \
          142  +		terminal $terminalBoolean \
          143  +	]
          144  +	if {[string tolower $status] eq "complete"} {
          145  +		dict set resultsDict kit_url $url
          146  +	}
          147  +	if {[string tolower $status] in {complete building}} {
          148  +		dict set resultsDict build_log_url $build_log_url
          149  +	}
   132    150   }
   133    151   
   134    152   switch -exact -- $resultFormat {
   135    153   	"html" {
   136    154   		# Handled below
   137    155   	}
   138    156   	"json" {
   139    157   		puts "Content-Type: application/json"
   140    158   		puts ""
   141         -		if {$status eq "Complete"} {
   142         -			puts "{\"status\":\"[string tolower $status]\", \"terminal\": $terminalBoolean, \"kit_url\":\"$url\"}"
   143         -		} else {
   144         -			puts "{\"status\":\"[string tolower $status]\", \"terminal\": $terminalBoolean}"
          159  +		set resultsJSONItems [list]
          160  +		foreach {key value} $resultsDict {
          161  +			switch -exact -- $key {
          162  +				"terminal" {
          163  +				}
          164  +				default {
          165  +					set value "\"$value\""
          166  +				}
          167  +			}
          168  +			lappend resultsJSONItems "\"$key\": $value"
   145    169   		}
          170  +		set resultsJSON "{[join $resultsJSONItems {, }]}"
          171  +		puts $resultsJSON
   146    172   		exit 0
   147    173   	}
   148    174   	"dict" {
   149    175   		puts "Content-Type: text/plain"
   150    176   		puts ""
   151         -		if {$status eq "Complete"} {
   152         -			puts [dict create \
   153         -				status [string tolower $status] \
   154         -				terminal $terminalBoolean \
   155         -				kit_url $url \
   156         -			]
   157         -		} else {
   158         -			puts [dict create \
   159         -				status [string tolower $status] \
   160         -				terminal $terminalBoolean \
   161         -			]
   162         -		}
          177  +		puts $resultsDict
   163    178   		exit 0
   164    179   	}
   165    180   	default {
   166    181   		exit 1
   167    182   	}
   168    183   }
   169    184