From 944593be94abf2bbdf2d44f477a2c32a34964605 Mon Sep 17 00:00:00 2001 From: Bradlee Speice Date: Thu, 10 Jan 2013 10:11:50 -0500 Subject: [PATCH] Fix a bug where scanning would add the same file many times --- archiver/archive.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/archiver/archive.py b/archiver/archive.py index 82f3869..5312a48 100644 --- a/archiver/archive.py +++ b/archiver/archive.py @@ -66,11 +66,14 @@ class Archive (models.Model): if re.match(regex, filename): #Make sure that `filename` is in the database try: - self.songs.get(url = filename) + rel_url = os.path.join(dirname, filename) + full_url = os.path.abspath(rel_url) + self.songs.get(url = full_url) except ObjectDoesNotExist, e: #Song needs to be added to database - full_url = os.path.join(dirname, filename) + rel_url = os.path.join(dirname, filename) + full_url = os.path.abspath(rel_url) new_song = Song(url = full_url) new_song.save() self.songs.add(new_song) @@ -131,10 +134,10 @@ class Archive (models.Model): def reorganize(self, format_string, progress_function = lambda w, x, y, z: None, dry_run = False): """Reorganize a music archive using a specified format string. Recognized escape characters: - %a - Artist Name %A - Album Name - %d - Disc Number %e - Number of discs - %f - Current Filename (no extension) %g - Current Filename (with extension) - %n - Track Number %o - Number of tracks on disc + %a - Artist Name %A - Album Name + %d - Disc Number %e - Number of discs + %f - Current Filename (with extension) %g - Current Filename (no extension) + %n - Track Number %o - Number of tracks on disc %y - Album year Note that all organization takes place relative to the archive's root folder. @@ -153,13 +156,13 @@ class Archive (models.Model): new_location = format_string.replace("%a", song.artist)\ .replace("%A", song.album)\ - .replace("%d", song.disc_number)\ - .replace("%e", song.disc_total)\ + .replace("%d", str(song.disc_number))\ + .replace("%e", str(song.disc_total))\ .replace("%f", _current_filename)\ .replace("%g", _current_filename_no_extension)\ - .replace("%n", song.track_number)\ - .replace("%o", song.track_total)\ - .replace("%y", _release_year) + .replace("%n", str(song.track_number))\ + .replace("%o", str(song.track_total))\ + .replace("%y", str(_release_year)) new_url = os.path.join(self.root_folder, new_location)