def handle(self, *args, **options): for i in ScanPath.objects.all(): self.stdout.write("Scanning path: %s ...\n" % i.path) for p in os.listdir(i.path): self.stdout.write("\n\t%s ... " % p) if not p.endswith('.jpg'): self.stdout.write("Ignored!") continue try: save_photo(i, p) self.stdout.write("Saved!") except Exception, e: self.stdout.write("Extract photo info failed!") self.stdout.write(str(e))
def on_btn_scan_clicked(self): items = self.tbl_scan_path.selectedItems() for i in items[::2]: path = ScanPath.objects.get(path=i.text()) for dirpath, dirnames, filenames in os.walk(path.path): print "Scanning %s ..." % dirpath sp, created = ScanPath.objects.get_or_create(path=dirpath) has_photo = False for f in filenames: if f.endswith('.jpg'): has_photo = True print "Save photo %s ..." % f try: get_square_thumb_80(sp.path, f) save_photo(sp, f) except Exception, e: logging.exception(e) if not has_photo: sp.delete()