7fbdb566c6de — russes02 11 years ago
Adds keep option
1 files changed, 10 insertions(+), 3 deletions(-)

M autocompare/main.go
M autocompare/main.go +10 -3
@@ 30,7 30,7 @@ var retries int
 var nthreads int
 var threshold uint
 var nrmsdThresh float64
-var nrmsdOnly bool
+var nrmsdOnly, keep bool
 var totalPages, totalFails int
 
 var version string

          
@@ 42,6 42,7 @@ func main() {
 	flag.UintVar(&threshold, "threshold", 0, "Number of pixels which may differ")
 	flag.BoolVar(&nrmsdOnly, "nrmsd", true, "Use normalized-root-mean-square-deviation method only")
 	flag.Float64Var(&nrmsdThresh, "nrmsd-threshold", 0.1, "Threshold for the NRMSD")
+	flag.BoolVar(&keep, "k", false, "Keep failures (don't delete)")
 	profile := flag.String("prof", "", "Profile and write to this file")
 	help := flag.Bool("h", false, "Print usage information")
 	flag.Usage = func() {

          
@@ 255,13 256,19 @@ func startComparisons(pageStream chan Pa
 		// In all cases, erase the files -- if we succeeded, we don't need
 		// them.  If we didn't, we need to download them again.
 		for page := range processStream {
-			os.Remove(page.OriginImage())
-			os.Remove(page.CopyImage())
 			if (page.State() == FAIL || page.State() == NEW) && page.Attempts() < retries {
+				os.Remove(page.OriginImage())
+				os.Remove(page.CopyImage())
 				page.SetOrigin("")
 				page.SetCopy("")
 				urlStream <- page
 			} else {
+				if !keep {
+					log.Printf("image %s  %s", page.OriginURL(), page.OriginImage())
+					log.Printf("image %s  %s", page.CopyURL(), page.CopyImage())
+					os.Remove(page.OriginImage())
+					os.Remove(page.CopyImage())
+				}
 				outputStream <- page
 			}
 		}