Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Utility that contains methods for both CT master and worker scripts. | 1 // Utility that contains methods for both CT master and worker scripts. |
| 2 package util | 2 package util |
| 3 | 3 |
| 4 import ( | 4 import ( |
| 5 "bufio" | 5 "bufio" |
| 6 "encoding/json" | 6 "encoding/json" |
| 7 "fmt" | 7 "fmt" |
| 8 "io" | 8 "io" |
| 9 "io/ioutil" | 9 "io/ioutil" |
| 10 "os" | 10 "os" |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 276 pagesetContent, err := os.Open(pagesetPath) | 276 pagesetContent, err := os.Open(pagesetPath) |
| 277 if err != nil { | 277 if err != nil { |
| 278 return decodedPageset, fmt.Errorf("Could not read %s: %s", pages etPath, err) | 278 return decodedPageset, fmt.Errorf("Could not read %s: %s", pages etPath, err) |
| 279 } | 279 } |
| 280 if err := json.NewDecoder(pagesetContent).Decode(&decodedPageset); err ! = nil { | 280 if err := json.NewDecoder(pagesetContent).Decode(&decodedPageset); err ! = nil { |
| 281 return decodedPageset, fmt.Errorf("Could not JSON decode %s: %s" , pagesetPath, err) | 281 return decodedPageset, fmt.Errorf("Could not JSON decode %s: %s" , pagesetPath, err) |
| 282 } | 282 } |
| 283 return decodedPageset, nil | 283 return decodedPageset, nil |
| 284 } | 284 } |
| 285 | 285 |
| 286 // ValidateSKPs moves all root_dir/dir_name/*.skp into the root_dir and validate s them. | 286 // ValidateSKPs moves all root_dir/index/dir_name/*.skp into the root_dir/index |
| 287 // SKPs that fail validation are logged and deleted. | 287 // and validates them. SKPs that fail validation are logged and deleted. |
| 288 func ValidateSKPs(pathToSkps string) error { | 288 func ValidateSKPs(pathToSkps, pathToPyFiles string) error { |
| 289 » // This splice will be used to run remove_invalid_skp.py on. | |
|
dogben
2016/05/19 16:48:41
s/splice/slice/, s/ on//
rmistry
2016/05/19 17:01:25
Done.
| |
| 290 » skps := []string{} | |
| 289 // List all directories in pathToSkps and copy out the skps. | 291 // List all directories in pathToSkps and copy out the skps. |
| 290 » skpFileInfos, err := ioutil.ReadDir(pathToSkps) | 292 » indexDirs, err := filepath.Glob(path.Join(pathToSkps, "*")) |
| 291 if err != nil { | 293 if err != nil { |
| 292 » » return fmt.Errorf("Unable to read %s: %s", pathToSkps, err) | 294 » » return fmt.Errorf("Unable to read %s: %s", indexDirs, err) |
|
dogben
2016/05/19 16:48:41
s/indexDirs/pathToSkps/
rmistry
2016/05/19 17:01:24
Done.
| |
| 293 } | 295 } |
| 294 » for _, fileInfo := range skpFileInfos { | 296 » for _, indexDir := range indexDirs { |
| 295 » » if !fileInfo.IsDir() { | 297 » » index := path.Base(indexDir) |
| 296 » » » // We are only interested in directories. | 298 » » skpFileInfos, err := ioutil.ReadDir(indexDir) |
| 297 » » » continue | 299 » » if err != nil { |
| 300 » » » return fmt.Errorf("Unable to read %s: %s", indexDir, err ) | |
| 298 } | 301 } |
| 299 » » skpName := fileInfo.Name() | 302 » » for _, fileInfo := range skpFileInfos { |
| 300 » » // Find the largest layer in this directory. | 303 » » » if !fileInfo.IsDir() { |
| 301 » » layerInfos, err := ioutil.ReadDir(filepath.Join(pathToSkps, skpN ame)) | 304 » » » » // We are only interested in directories. |
| 302 » » if err != nil { | 305 » » » » continue |
| 303 » » » glog.Errorf("Unable to read %s: %s", filepath.Join(pathT oSkps, skpName), err) | 306 » » » } |
| 304 » » } | 307 » » » skpName := fileInfo.Name() |
| 305 » » if len(layerInfos) > 0 { | 308 » » » // Find the largest layer in this directory. |
| 306 » » » largestLayerInfo := layerInfos[0] | 309 » » » layerInfos, err := ioutil.ReadDir(filepath.Join(pathToSk ps, index, skpName)) |
| 307 » » » for _, layerInfo := range layerInfos { | 310 » » » if err != nil { |
| 308 » » » » if layerInfo.Size() > largestLayerInfo.Size() { | 311 » » » » glog.Errorf("Unable to read %s: %s", filepath.Jo in(pathToSkps, index, skpName), err) |
| 309 » » » » » largestLayerInfo = layerInfo | 312 » » » } |
| 313 » » » if len(layerInfos) > 0 { | |
| 314 » » » » largestLayerInfo := layerInfos[0] | |
| 315 » » » » for _, layerInfo := range layerInfos { | |
| 316 » » » » » if layerInfo.Size() > largestLayerInfo.S ize() { | |
| 317 » » » » » » largestLayerInfo = layerInfo | |
| 318 » » » » » } | |
| 319 » » » » } | |
| 320 » » » » // Only save SKPs greater than 6000 bytes. Less than that are probably | |
| 321 » » » » // malformed. | |
| 322 » » » » if largestLayerInfo.Size() > 6000 { | |
| 323 » » » » » layerPath := filepath.Join(pathToSkps, i ndex, skpName, largestLayerInfo.Name()) | |
| 324 » » » » » destSKP := filepath.Join(pathToSkps, ind ex, skpName+".skp") | |
| 325 » » » » » util.Rename(layerPath, destSKP) | |
| 326 » » » » » skps = append(skps, destSKP) | |
| 327 » » » » } else { | |
| 328 » » » » » glog.Warningf("Skipping %s because size was less than 6000 bytes", skpName) | |
| 310 } | 329 } |
| 311 } | 330 } |
| 312 » » » // Only save SKPs greater than 6000 bytes. Less than tha t are probably | 331 » » » // We extracted what we needed from the directory, now d elete it. |
| 313 » » » // malformed. | 332 » » » util.RemoveAll(filepath.Join(pathToSkps, index, skpName) ) |
| 314 » » » if largestLayerInfo.Size() > 6000 { | |
| 315 » » » » layerPath := filepath.Join(pathToSkps, skpName, largestLayerInfo.Name()) | |
| 316 » » » » destSKP := filepath.Join(pathToSkps, skpName+".s kp") | |
| 317 » » » » util.Rename(layerPath, destSKP) | |
| 318 » » » } else { | |
| 319 » » » » glog.Warningf("Skipping %s because size was less than 6000 bytes", skpName) | |
| 320 » » » } | |
| 321 } | 333 } |
| 322 // We extracted what we needed from the directory, now delete it . | |
| 323 util.RemoveAll(filepath.Join(pathToSkps, skpName)) | |
| 324 } | 334 } |
| 325 | 335 |
| 326 // Create channel that contains all SKP file paths. This channel will | 336 // Create channel that contains all SKP file paths. This channel will |
| 327 // be consumed by the worker pool below to run remove_invalid_skp.py in | 337 // be consumed by the worker pool below to run remove_invalid_skp.py in |
| 328 // parallel. | 338 // parallel. |
| 329 skps, err := ioutil.ReadDir(pathToSkps) | |
| 330 if err != nil { | |
| 331 return fmt.Errorf("Unable to read %s: %s", pathToSkps, err) | |
| 332 } | |
| 333 skpsChannel := make(chan string, len(skps)) | 339 skpsChannel := make(chan string, len(skps)) |
| 334 for _, skp := range skps { | 340 for _, skp := range skps { |
| 335 » » skpsChannel <- filepath.Join(pathToSkps, skp.Name()) | 341 » » skpsChannel <- skp |
| 336 } | 342 } |
| 337 close(skpsChannel) | 343 close(skpsChannel) |
| 338 | 344 |
| 339 glog.Info("Calling remove_invalid_skp.py") | 345 glog.Info("Calling remove_invalid_skp.py") |
| 340 // Sync Skia tree. | 346 // Sync Skia tree. |
| 341 util.LogErr(SyncDir(SkiaTreeDir)) | 347 util.LogErr(SyncDir(SkiaTreeDir)) |
| 342 // Build tools. | 348 // Build tools. |
| 343 util.LogErr(BuildSkiaTools()) | 349 util.LogErr(BuildSkiaTools()) |
| 344 // Run remove_invalid_skp.py in parallel goroutines. | 350 // Run remove_invalid_skp.py in parallel goroutines. |
| 345 // Construct path to the python script. | 351 // Construct path to the python script. |
| 346 _, currentFile, _, _ := runtime.Caller(0) | |
| 347 pathToPyFiles := filepath.Join( | |
| 348 filepath.Dir((filepath.Dir(filepath.Dir(currentFile)))), | |
| 349 "py") | |
| 350 pathToRemoveSKPs := filepath.Join(pathToPyFiles, "remove_invalid_skp.py" ) | 352 pathToRemoveSKPs := filepath.Join(pathToPyFiles, "remove_invalid_skp.py" ) |
| 351 pathToSKPInfo := filepath.Join(SkiaTreeDir, "out", "Release", "skpinfo") | 353 pathToSKPInfo := filepath.Join(SkiaTreeDir, "out", "Release", "skpinfo") |
| 352 | 354 |
| 353 var wg sync.WaitGroup | 355 var wg sync.WaitGroup |
| 354 | 356 |
| 355 // Loop through workers in the worker pool. | 357 // Loop through workers in the worker pool. |
| 356 for i := 0; i < REMOVE_INVALID_SKPS_WORKER_POOL; i++ { | 358 for i := 0; i < REMOVE_INVALID_SKPS_WORKER_POOL; i++ { |
| 357 // Increment the WaitGroup counter. | 359 // Increment the WaitGroup counter. |
| 358 wg.Add(1) | 360 wg.Add(1) |
| 359 | 361 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 458 | 460 |
| 459 // GetPathToPyFiles returns the location of CT's python scripts. | 461 // GetPathToPyFiles returns the location of CT's python scripts. |
| 460 func GetPathToPyFiles(runOnSwarming bool) string { | 462 func GetPathToPyFiles(runOnSwarming bool) string { |
| 461 if runOnSwarming { | 463 if runOnSwarming { |
| 462 return filepath.Join(filepath.Dir(filepath.Dir(os.Args[0])), "sr c", "go.skia.org", "infra", "ct", "py") | 464 return filepath.Join(filepath.Dir(filepath.Dir(os.Args[0])), "sr c", "go.skia.org", "infra", "ct", "py") |
| 463 } else { | 465 } else { |
| 464 _, currentFile, _, _ := runtime.Caller(0) | 466 _, currentFile, _, _ := runtime.Caller(0) |
| 465 return filepath.Join(filepath.Dir(filepath.Dir(filepath.Dir(curr entFile))), "py") | 467 return filepath.Join(filepath.Dir(filepath.Dir(filepath.Dir(curr entFile))), "py") |
| 466 } | 468 } |
| 467 } | 469 } |
| OLD | NEW |