Skip to content
Browse files

Added --reindex option to indexer

  • Loading branch information...
1 parent bde7e64 commit 53f2e90665bbe7afae4e47ec2550aa903af0cd05 @dbrgn committed Apr 7, 2013
Showing with 13 additions and 3 deletions.
  1. +12 −2 indexer.py
  2. +1 −1 shiva/models.py
View
14 indexer.py
@@ -4,12 +4,13 @@
pictures from Last.FM.
Usage:
- shiva-indexer [-h] [-v] [-q] [--lastfm] [--nometadata]
+ shiva-indexer [-h] [-v] [-q] [--lastfm] [--nometadata] [--reindex]
Options:
-h, --help Show this help message and exit
--lastfm Retrieve artist and album covers from Last.FM API.
--nometadata Don't read file's metadata when indexing.
+ --reindex Remove all existing data from the database before indexing.
-v --verbose Show debugging messages about the progress.
-q --quiet Suppress warnings.
"""
@@ -27,7 +28,8 @@
class Indexer(object):
- def __init__(self, config=None, use_lastfm=False, no_metadata=False, verbose=False, quiet=False):
+ def __init__(self, config=None, use_lastfm=False, no_metadata=False, reindex=False,
+ verbose=False, quiet=False):
self.config = config
self.use_lastfm = use_lastfm
self.no_metadata = no_metadata
@@ -55,6 +57,13 @@ def __init__(self, config=None, use_lastfm=False, no_metadata=False, verbose=Fal
print("Remember to set the MEDIA_DIRS option, otherwise I don't "
'know where to look for.')
+ if reindex:
+ models = [m.Artist, m.Album, m.Track, m.Lyrics]
+ for model in models:
+ print('Deleting all rows from {} model...'.format(model.__name__))
+ model.query.delete()
+ self.session.commit()
+
def get_artist(self, name):
if name in self.artists:
return self.artists[name]
@@ -198,6 +207,7 @@ def run(self):
kwargs = {
'use_lastfm': arguments['--lastfm'],
'no_metadata': arguments['--nometadata'],
+ 'reindex': arguments['--reindex'],
'verbose': arguments['--verbose'],
'quiet': arguments['--quiet'],
}
View
2 shiva/models.py
@@ -7,7 +7,7 @@
db = SQLAlchemy()
-__all__ = ('db', 'Artist', 'Album', 'Track')
+__all__ = ('db', 'Artist', 'Album', 'Track', 'Lyrics')
def slugify(model, field_name):

0 comments on commit 53f2e90

Please sign in to comment.
Something went wrong with that request. Please try again.