def run(self): search = Search(self.src_path, self.dst_path, self.src_regex, self.dst_regex) imagelist = search.find_images() artistlist = search.find_artists() if len(imagelist) == 0 and len(artistlist) == 0: print("Error: Nothing found neither in source or destination.") print("Maybe you have supplied the paths in the wrong order?") print( "It should be source path first and destination path second.") exit(1) for artist in artistlist: sepparator = "--------------------------------------------" artiststring = "%s\nChecking artist with id: %s" % (sepparator, artist.id) imagestring = "" for image in imagelist: if artist.id == image.artist_id: imgpath = image.path.encode("utf-8") artistpath = artist.path.encode("utf-8") image.copy(artist.path) # assemble string for status about copying tempstring = "\n\tCopying image" copystring = "\n\t%s\n\tto\n\t%s" % (imgpath, artistpath) tempstring = tempstring + copystring imagestring = imagestring + tempstring if imagestring != "": print(artiststring + imagestring) print("Finished! Have a nice day.")
def test_find_images(): """Test search of images.""" src_regex = re.compile("(?<=^\()\d*(?=\))") dst_regex = re.compile("(?<=\()\d*(?=\)$)") search = Search("./test/testsource", "./test/testdestination", src_regex, dst_regex) imglist = search.find_images() assert len(imglist) == 2 for img in imglist: print(img.artist_id) assert img.artist_id in ("206921", "814837")
def test_find_artists(): """Test search of artists.""" src_regex = re.compile("(?<=^\()\d*(?=\))") dst_regex = re.compile("(?<=\()\d*(?=\)$)") search = Search("./test/testsource", "./test/testdestination", src_regex, dst_regex) artistlist = search.find_artists() assert len(artistlist) == 2 for artist in artistlist: assert artist.id in ("206921", "814837")