def update_labels(self): pair = self.pairs[self.index] feedback = pair.get_feedback() if feedback is None: feedback = "not yet" background = self.background elif feedback == 0: feedback = "not similar" background = "#FFE0E0" elif feedback == 1: feedback = "similar" background = "#E0FFE0" else: assert 0 img1 = ImageRelated(pair.path1, self.max_image_size, background) img2 = ImageRelated(pair.path2, self.max_image_size, background) self.ref_counting = (img1, img2) self.item_frame.config(background=background) text = "%d/%d similarity=%f feedback = %s skip=%d" % ( self.index + 1, len(self.pairs), self.pairs[self.index].similarity, feedback, self.skip_pairs_with_feedback) self.label_sim.config(background=background, text=text) self.label_imgl.config(text=None, image=img1.tk_image) self.label_imgr.config(text=None, image=img2.tk_image) size1 = img1.file_size size2 = img2.file_size color1, color2 = get_colors(cmp(size1, size2)) self.label_pathl.config(text=split_path(img1.path)) self.label_pathr.config(text=split_path(img2.path)) self.label_sizel.config(fg=color1, text=format_bytes(size1)) self.label_sizer.config(fg=color2, text=format_bytes(size2)) color1, color2 = get_colors(cmp(img1.pixels, img2.pixels)) self.label_pixelsl.config(fg=color1, text=format_bytes(img1.pixels)) self.label_pixelsr.config(fg=color2, text=format_bytes(img2.pixels)) self.label_resl.config(fg=color1, text="%d x %d" % img1.image.size) self.label_resr.config(fg=color2, text="%d x %d" % img2.image.size) color1, color2 = get_colors(cmp(img1.bpp, img2.bpp)) self.label_bppl.config(fg=color1, text="%f" % img1.bpp) self.label_bppr.config(fg=color2, text="%f" % img2.bpp)
def resolve(self, pair): progress = "[%d.%d/%d] " % ( pair.ctxt_index + 1, pair.ctxt_subindex + 1, pair.ctxt_size) print "\nThe following files are equal and %s bytes large" % ( format_bytes(pair.size)) while True: print " [1] %s" % pair.path1 print " [2] %s" % pair.path2 msg = progress + "sPreserve what? Press 1, 2, " if not pair.hardlinked: msg += "'a' (to delete all), " msg += "'s' (to skip)." print msg if self.default_preserve: if self.default_preserve == 1: to_delete = [pair.path2] elif self.default_preserve == 2: to_delete = [pair.path1] else: assert 0 else: input = raw_input("> ") to_delete = self._evaluate_input(input, pair) if to_delete is None: continue elif to_delete == []: break self._delete(to_delete) break
def test_format_bytes(self): self.assertEqual(format_bytes(0), "0") self.assertEqual(format_bytes(1), "1") self.assertEqual(format_bytes(2), "2") self.assertEqual(format_bytes(999), "999") self.assertEqual(format_bytes(1000), "1,000") self.assertEqual(format_bytes(1023), "1,023") self.assertEqual(format_bytes(1024), "1,024 (1.0 KiB)") self.assertEqual(format_bytes(2048), "2,048 (2.0 KiB)") self.assertEqual(format_bytes(414747471), "414,747,471 (395.5 MiB)") self.assertEqual(format_bytes(34418050942), "34,418,050,942 (32.1 GiB)") self.assertEqual(format_bytes(2000*(2**40)), "2,199,023,255,552,000 (2000.0 TiB)") self.assertEqual(format_bytes(2*(10**15)), "2,000,000,000,000,000 (1819.0 TiB)")