Example #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) )
Example #2
0
def map_events(directory, constructor):
    """ Walks 'directory' and creates an event using 'constructor'.
    Returns a list of the constructed events. """
    # -unknown-path should not appear in the path here but more testing
    # might be necessary
    for f in mmp.walk_supported(directory, clean_empties=False):
        try:
            for e in constructor( FakePyinotify(f) ).pack(): yield e
        except BadSongFile as e: yield e
Example #3
0
def map_events(directory, constructor):
    """ Walks 'directory' and creates an event using 'constructor'.
    Returns a list of the constructed events. """
    # -unknown-path should not appear in the path here but more testing
    # might be necessary
    for f in mmp.walk_supported(directory, clean_empties=False):
        try:
            for e in constructor(FakePyinotify(f)).pack():
                yield e
        except BadSongFile as e:
            yield e
Example #4
0
 def flush_events(self, path):
     """
     organize the whole directory at path. (pretty much by doing what
     handle does to every file
     """
     flushed = 0
     for f in mmp.walk_supported(path, clean_empties=True):
         self.logger.info("Bootstrapping: File in 'organize' directory: \
                 '%s'" % f)
         if not mmp.file_locked(f):
             dispatcher.send(signal=self.signal, sender=self,
                     event=OrganizeFile(f))
         flushed += 1
Example #5
0
 def flush_events(self, path):
     """
     walk over path and send a NewFile event for every file in this
     directory.  Not to be confused with bootstrapping which is a more
     careful process that involved figuring out what's in the database
     first.
     """
     # Songs is a dictionary where every key is the watched the directory
     # and the value is a set with all the files in that directory.
     added = 0
     for f in mmp.walk_supported(path, clean_empties=False):
         added += 1
         dispatcher.send( signal=self.signal, sender=self, event=NewFile(f) )
     self.logger.info( "Flushed watch directory. added = %d" % added )
Example #6
0
 def flush_events(self, path):
     """
     organize the whole directory at path. (pretty much by doing what
     handle does to every file
     """
     flushed = 0
     for f in mmp.walk_supported(path, clean_empties=True):
         self.logger.info("Bootstrapping: File in 'organize' directory: \
                 '%s'" % f)
         if not mmp.file_locked(f):
             dispatcher.send(signal=getsig(self.signal),
                             sender=self,
                             event=OrganizeFile(f))
         flushed += 1
Example #7
0
 def flush_events(self, path):
     """
     walk over path and send a NewFile event for every file in this
     directory.  Not to be confused with bootstrapping which is a more
     careful process that involved figuring out what's in the database
     first.
     """
     # Songs is a dictionary where every key is the watched the directory
     # and the value is a set with all the files in that directory.
     added = 0
     for f in mmp.walk_supported(path, clean_empties=False):
         added += 1
         dispatcher.send(signal=getsig(self.signal),
                         sender=self,
                         event=NewFile(f))
     self.logger.info("Flushed watch directory. added = %d" % added)
Example #8
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))