Beispiel #1
0
 def flush_watch(self, directory, last_ran, all_files=False):
     """
     flush a single watch/imported directory. useful when wanting to to
     rescan, or add a watched/imported directory
     """
     songs = set([])
     added = modded = deleted = 0
     for f in mmp.walk_supported(directory, clean_empties=False):
         songs.add(f)
         # We decide whether to update a file's metadata by checking its
         # system modification date. If it's above the value self.last_ran
         # which is passed to us that means media monitor wasn't aware when
         # this changes occured in the filesystem hence it will send the
         # correct events to sync the database with the filesystem
         if os.path.getmtime(f) > last_ran:
             modded += 1
             dispatcher.send(signal=self.watch_signal, sender=self,
                     event=ModifyFile(f))
     db_songs = set(( song for song in self.db.directory_get_files(directory,
         all_files)
         if mmp.sub_path(directory,song) ))
     # Get all the files that are in the database but in the file
     # system. These are the files marked for deletions
     for to_delete in db_songs.difference(songs):
         dispatcher.send(signal=self.watch_signal, sender=self,
                         event=DeleteFile(to_delete))
         deleted += 1
     for to_add in songs.difference(db_songs):
         dispatcher.send(signal=self.watch_signal, sender=self,
                         event=NewFile(to_add))
         added += 1
     self.logger.info( "Flushed watch directory (%s). \
             (added, modified, deleted) = (%d, %d, %d)"
             % (directory, added, modded, deleted) )
 def directory_get_files(self, directory, all_files=True):
     """ returns all the files(recursively) in a directory. a
     directory is an "actual" directory path instead of its id. This
     is super hacky because you create one request for the recorded
     directory and one for the imported directory even though they're
     the same dir in the database so you get files for both dirs in 1
     request... """
     normal_dir = os.path.normpath(unicode(directory))
     if normal_dir not in self.dir_to_id:
         raise NoDirectoryInAirtime( normal_dir, self.dir_to_id )
     all_files = self.dir_id_get_files( self.dir_to_id[normal_dir],
             all_files )
     if normal_dir == self.recorded_path():
         all_files = [ p for p in all_files if
                 mmp.sub_path( self.recorded_path(), p ) ]
     elif normal_dir == self.import_path():
         all_files = [ p for p in all_files if
                 mmp.sub_path( self.import_path(), p ) ]
     elif normal_dir == self.storage_path():
         self.logger.info("Warning, you're getting all files in '%s' which \
                 includes imported + record" % normal_dir)
     return set(all_files)