@@ -4,15 +4,14 @@ import (
44 "fmt"
55 "os"
66 "os/exec"
7- "os/user"
87 "strings"
98 "time"
109
1110 "github.com/BurntSushi/toml"
1211 "github.com/grisu48/gopenqa"
1312)
1413
15- const VERSION = "1.1 .0"
14+ const VERSION = "1.2 .0"
1615
1716/* Group is a single configurable monitoring unit. A group contains all parameters that will be queried from openQA */
1817type Group struct {
@@ -170,7 +169,7 @@ func checkReviewed(job int64, instance *gopenqa.Instance) (bool, error) {
170169 return false , nil
171170}
172171
173- func FetchJobGroups (instance gopenqa.Instance ) (map [int ]gopenqa.JobGroup , error ) {
172+ func FetchJobGroups (instance * gopenqa.Instance ) (map [int ]gopenqa.JobGroup , error ) {
174173 jobGroups := make (map [int ]gopenqa.JobGroup )
175174 groups , err := instance .GetJobGroups ()
176175 if err != nil {
@@ -183,7 +182,7 @@ func FetchJobGroups(instance gopenqa.Instance) (map[int]gopenqa.JobGroup, error)
183182}
184183
185184/* Get job or clone current job of the given job ID */
186- func FetchJob (id int64 , instance gopenqa.Instance ) (gopenqa.Job , error ) {
185+ func FetchJob (id int64 , instance * gopenqa.Instance ) (gopenqa.Job , error ) {
187186 var job gopenqa.Job
188187 for i := 0 ; i < 25 ; i ++ { // Max recursion depth is 25
189188 var err error
@@ -202,9 +201,7 @@ func FetchJob(id int64, instance gopenqa.Instance) (gopenqa.Job, error) {
202201}
203202
204203/* Fetch the given jobs from the instance at once */
205- func fetchJobs (ids []int64 , instance gopenqa.Instance ) ([]gopenqa.Job , error ) {
206- jobs := make ([]gopenqa.Job , 0 )
207-
204+ func fetchJobs (ids []int64 , instance * gopenqa.Instance ) ([]gopenqa.Job , error ) {
208205 jobs , err := instance .GetJobs (ids )
209206 if err != nil {
210207 return jobs , err
@@ -225,7 +222,7 @@ func fetchJobs(ids []int64, instance gopenqa.Instance) ([]gopenqa.Job, error) {
225222
226223type FetchJobsCallback func (int , int , int , int )
227224
228- func FetchJobs (instance gopenqa.Instance , callback FetchJobsCallback ) ([]gopenqa.Job , error ) {
225+ func FetchJobs (instance * gopenqa.Instance , callback FetchJobsCallback ) ([]gopenqa.Job , error ) {
229226 ret := make ([]gopenqa.Job , 0 )
230227 for i , group := range cf .Groups {
231228 params := group .Params
@@ -270,17 +267,6 @@ func rabbitRemote(remote string) string {
270267 return remote
271268}
272269
273- /** Updates the known job based on the Job ID. Returns true if it has been updated and the updated instance and false if and the job if the job id hasn't been found */
274- func updateJob (job gopenqa.Job ) (gopenqa.Job , bool ) {
275- for i , j := range knownJobs {
276- if j .ID == job .ID {
277- knownJobs [i ] = job
278- return knownJobs [i ], true
279- }
280- }
281- return job , false
282- }
283-
284270func getKnownJob (id int64 ) (gopenqa.Job , bool ) {
285271 for _ , j := range knownJobs {
286272 if j .ID == id {
@@ -303,22 +289,6 @@ func updateJobStatus(status gopenqa.JobStatus) (gopenqa.Job, bool) {
303289 return job , false
304290}
305291
306- func fileExists (filename string ) bool {
307- _ , err := os .Stat (filename )
308- if os .IsNotExist (err ) {
309- return false
310- }
311- return true
312- }
313-
314- func homeDir () string {
315- usr , err := user .Current ()
316- if err != nil {
317- panic (err )
318- }
319- return usr .HomeDir
320- }
321-
322292func loadDefaultConfig () error {
323293 configFile := homeDir () + "/.openqa-revtui.toml"
324294 if fileExists (configFile ) {
@@ -329,15 +299,6 @@ func loadDefaultConfig() error {
329299 return nil
330300}
331301
332- // Split a NAME=VALUE string
333- func splitNV (v string ) (string , string , error ) {
334- i := strings .Index (v , "=" )
335- if i < 0 {
336- return "" , "" , fmt .Errorf ("no separator" )
337- }
338- return v [:i ], v [i + 1 :], nil
339- }
340-
341302func parseProgramArgs () error {
342303 n := len (os .Args )
343304 for i := 1 ; i < n ; i ++ {
@@ -354,30 +315,30 @@ func parseProgramArgs() error {
354315 os .Exit (0 )
355316 } else if arg == "-c" || arg == "--config" {
356317 if i ++ ; i >= n {
357- return fmt .Errorf ("Missing argument: %s" , "config file" )
318+ return fmt .Errorf ("missing argument: %s" , "config file" )
358319 }
359320 filename := os .Args [i ]
360321 if err := cf .LoadToml (filename ); err != nil {
361- return fmt .Errorf ("In %s: %s" , filename , err )
322+ return fmt .Errorf ("in %s: %s" , filename , err )
362323 }
363324 } else if arg == "-r" || arg == "--remote" {
364325 if i ++ ; i >= n {
365- return fmt .Errorf ("Missing argument: %s" , "remote" )
326+ return fmt .Errorf ("missing argument: %s" , "remote" )
366327 }
367328 cf .Instance = os .Args [i ]
368329 } else if arg == "-q" || arg == "--rabbit" || arg == "--rabbitmq" {
369330 if i ++ ; i >= n {
370- return fmt .Errorf ("Missing argument: %s" , "RabbitMQ link" )
331+ return fmt .Errorf ("missing argument: %s" , "RabbitMQ link" )
371332 }
372333 cf .RabbitMQ = os .Args [i ]
373334 } else if arg == "-i" || arg == "--hide" || arg == "--hide-status" {
374335 if i ++ ; i >= n {
375- return fmt .Errorf ("Missing argument: %s" , "Status to hide" )
336+ return fmt .Errorf ("missing argument: %s" , "Status to hide" )
376337 }
377338 cf .HideStatus = append (cf .HideStatus , strings .Split (os .Args [i ], "," )... )
378339 } else if arg == "-p" || arg == "--param" {
379340 if i ++ ; i >= n {
380- return fmt .Errorf ("Missing argument: %s" , "parameter" )
341+ return fmt .Errorf ("missing argument: %s" , "parameter" )
381342 }
382343 if name , value , err := splitNV (os .Args [i ]); err != nil {
383344 return fmt .Errorf ("argument parameter is invalid: %s" , err )
@@ -389,7 +350,7 @@ func parseProgramArgs() error {
389350 } else if arg == "-m" || arg == "--mute" || arg == "--silent" || arg == "--no-notify" {
390351 cf .Notify = false
391352 } else {
392- return fmt .Errorf ("Illegal argument: %s" , arg )
353+ return fmt .Errorf ("illegal argument: %s" , arg )
393354 }
394355 } else {
395356 // Convenience logic. If it contains a = then assume it's a parameter, otherwise assume it's a config file
@@ -402,7 +363,7 @@ func parseProgramArgs() error {
402363 } else {
403364 // Assume it's a config file
404365 if err := cf .LoadToml (arg ); err != nil {
405- return fmt .Errorf ("In %s: %s" , arg , err )
366+ return fmt .Errorf ("in %s: %s" , arg , err )
406367 }
407368 }
408369 }
@@ -483,7 +444,7 @@ func main() {
483444 instance := gopenqa .CreateInstance (cf .Instance )
484445 instance .SetUserAgent ("openqa-mon/revtui" )
485446
486- // Refresh rates below 5 minutes are not allowed on public instances due to the rather large load it puts on them
447+ // Refresh rates below 5 minutes are not allowed on public instances due to the load it puts on them
487448 updatedRefresh = false
488449 if cf .RefreshInterval < 300 {
489450 if strings .Contains (cf .Instance , "://openqa.suse.de" ) || strings .Contains (cf .Instance , "://openqa.opensuse.org" ) {
@@ -504,7 +465,7 @@ func main() {
504465 os .Exit (1 )
505466 }
506467 tui .SetHideStatus (cf .HideStatus )
507- err := tui_main (& tui , instance )
468+ err := tui_main (& tui , & instance )
508469 tui .LeaveAltScreen () // Ensure we leave alt screen
509470 if err != nil {
510471 fmt .Fprintf (os .Stderr , "%s\n " , err )
@@ -575,7 +536,7 @@ func browserJobs(jobs []gopenqa.Job) error {
575536}
576537
577538// main routine for the TUI instance
578- func tui_main (tui * TUI , instance gopenqa.Instance ) error {
539+ func tui_main (tui * TUI , instance * gopenqa.Instance ) error {
579540 title := "openqa Review TUI Dashboard v" + VERSION
580541 var rabbitmq gopenqa.RabbitMQ
581542 var err error
@@ -587,7 +548,7 @@ func tui_main(tui *TUI, instance gopenqa.Instance) error {
587548 if ! refreshing {
588549 refreshing = true
589550 go func () {
590- if err := refreshJobs (tui , & instance ); err != nil {
551+ if err := refreshJobs (tui , instance ); err != nil {
591552 tui .SetStatus (fmt .Sprintf ("Error while refreshing: %s" , err ))
592553 }
593554 refreshing = false
@@ -615,7 +576,8 @@ func tui_main(tui *TUI, instance gopenqa.Instance) error {
615576 if len (jobs ) == 0 {
616577 tui .SetStatus ("No visible jobs" )
617578 } else if len (jobs ) > 10 && key == 'o' {
618- tui .SetStatus ("Refusing to open more than 10 job links. Use 'O' to override" )
579+ status := fmt .Sprintf ("Refuse to open %d (>10) job links. Use 'O' to override" , len (jobs ))
580+ tui .SetTemporaryStatus (status , 5 )
619581 } else {
620582 if err := browserJobs (jobs ); err != nil {
621583 tui .SetStatus (fmt .Sprintf ("error: %s" , err ))
@@ -638,13 +600,13 @@ func tui_main(tui *TUI, instance gopenqa.Instance) error {
638600 fmt .Println (title )
639601 fmt .Println ("" )
640602 if updatedRefresh {
641- fmt .Printf (ANSI_YELLOW + "WARNING: For OSD and O3 a rate limit of 5 minutes between polling has been applied ." + ANSI_RESET + "\n \n " )
603+ fmt .Printf (ANSI_YELLOW + "WARNING: For OSD and O3 a rate limit of 5 minutes between polling is enforced ." + ANSI_RESET + "\n \n " )
642604 }
643605 fmt .Printf ("Initial querying instance %s ... \n " , cf .Instance )
644606 fmt .Println ("\t Get job groups ... " )
645607 jobgroups , err := FetchJobGroups (instance )
646608 if err != nil {
647- return fmt .Errorf ("Error fetching job groups: %s" , err )
609+ return fmt .Errorf ("error fetching job groups: %s" , err )
648610 }
649611 if len (jobgroups ) == 0 {
650612 fmt .Fprintf (os .Stderr , "Warn: No job groups\n " )
@@ -664,15 +626,15 @@ func tui_main(tui *TUI, instance gopenqa.Instance) error {
664626 })
665627 fmt .Println ()
666628 if err != nil {
667- return fmt .Errorf ("Error fetching jobs: %s" , err )
629+ return fmt .Errorf ("error fetching jobs: %s" , err )
668630 }
669631 // Failed jobs will be also scanned for comments
670632 for _ , job := range jobs {
671633 state := job .JobState ()
672634 if state == "failed" || state == "incomplete" || state == "parallel_failed" {
673- reviewed , err := isReviewed (job , & instance , state == "parallel_failed" )
635+ reviewed , err := isReviewed (job , instance , state == "parallel_failed" )
674636 if err != nil {
675- return fmt .Errorf ("Error fetching job comment: %s" , err )
637+ return fmt .Errorf ("error fetching job comment: %s" , err )
676638 }
677639 tui .Model .SetReviewed (job .ID , reviewed )
678640 }
@@ -697,7 +659,7 @@ func tui_main(tui *TUI, instance gopenqa.Instance) error {
697659 go func () {
698660 for {
699661 time .Sleep (time .Duration (cf .RefreshInterval ) * time .Second )
700- if err := refreshJobs (tui , & instance ); err != nil {
662+ if err := refreshJobs (tui , instance ); err != nil {
701663 tui .SetStatus (fmt .Sprintf ("Error while refreshing: %s" , err ))
702664 }
703665 }
0 commit comments