Ejemplo n.º 1
0
 def test_owner_id(self):
     start_path = "testing.mp3"
     id_path = "testing.mp3.identifier"
     o_id = 123
     f = open(id_path, 'w')
     f.write("123")
     f.close()
     possible_id = mmp.owner_id(start_path)
     self.assertFalse(os.path.exists(id_path))
     self.assertEqual(possible_id, o_id)
     self.assertEqual(-1, mmp.owner_id("something.random"))
Ejemplo n.º 2
0
 def test_owner_id(self):
     start_path = "testing.mp3"
     id_path    = "testing.mp3.identifier"
     o_id   = 123
     f = open(id_path, 'w')
     f.write("123")
     f.close()
     possible_id = mmp.owner_id(start_path)
     self.assertFalse( os.path.exists(id_path) )
     self.assertEqual( possible_id, o_id )
     self.assertEqual( -1, mmp.owner_id("something.random") )
Ejemplo n.º 3
0
    def handle(self, sender, event):
        """ Intercept events where a new file has been added to the
        organize directory and place it in the correct path (starting
        with self.target_path) """
        # Only handle this event type
        assert isinstance(event, OrganizeFile), \
            "Organizer can only handle OrganizeFile events.Given '%s'" % event
        try:
            # We must select the target_path based on whether file was recorded
            # by airtime or not.
            # Do we need to "massage" the path using mmp.organized_path?
            target_path = self.recorded_path if event.metadata.is_recorded() \
                                             else self.target_path
            # nasty hack do this properly
            owner_id = mmp.owner_id(event.path)
            if owner_id != -1:
                target_path = os.path.join(target_path, unicode(owner_id))

            mdata = event.metadata.extract()
            new_path = mmp.organized_path(event.path, target_path, mdata)

            # See hack in mmp.magic_move
            def new_dir_watch(d):
                # TODO : rewrite as return lambda : dispatcher.send(...
                def cb():
                    dispatcher.send(signal=getsig("add_subwatch"),
                                    sender=self,
                                    directory=d)

                return cb

            mmp.magic_move(event.path,
                           new_path,
                           after_dir_make=new_dir_watch(dirname(new_path)))

            # The reason we need to go around saving the owner in this
            # backwards way is because we are unable to encode the owner id
            # into the file itself so that the StoreWatchListener listener can
            # detect it from the file
            user().owner.add_file_owner(new_path, owner_id)

            self.logger.info('Organized: "%s" into "%s"' %
                             (event.path, new_path))
        except BadSongFile as e:
            self.report_problem_file(event=event, exception=e)
        # probably general error in mmp.magic.move...
        except Exception as e:
            self.unexpected_exception(e)
            self.report_problem_file(event=event, exception=e)
Ejemplo n.º 4
0
    def handle(self, sender, event):
        """
        Intercept events where a new file has been added to the organize
        directory and place it in the correct path (starting with
        self.target_path)
        """
        # Only handle this event type
        assert isinstance(event, OrganizeFile), \
            "Organizer can only handle OrganizeFile events.Given '%s'" % event
        try:
            # We must select the target_path based on whether file was recorded
            # by airtime or not.
            # Do we need to "massage" the path using mmp.organized_path?
            target_path = self.recorded_path if event.metadata.is_recorded() \
                                             else self.target_path
            # nasty hack do this properly
            owner_id = mmp.owner_id(event.path)
            if owner_id != -1:
                target_path = os.path.join(target_path, unicode(owner_id))

            mdata = event.metadata.extract()
            new_path = mmp.organized_path(event.path, target_path, mdata)

            # See hack in mmp.magic_move
            def new_dir_watch(d):
                # TODO : rewrite as return lambda : dispatcher.send(...
                def cb():
                    dispatcher.send(signal="add_subwatch", sender=self,
                            directory=d)
                return cb

            mmp.magic_move(event.path, new_path,
                    after_dir_make=new_dir_watch(dirname(new_path)))

            # The reason we need to go around saving the owner in this ass
            # backwards way is bewcause we are unable to encode the owner id
            # into the file itself so that the StoreWatchListener listener can
            # detect it from the file
            owners.add_file_owner(new_path, owner_id )

            self.logger.info('Organized: "%s" into "%s"' %
                    (event.path, new_path))
        except BadSongFile as e:
            self.report_problem_file(event=event, exception=e)
        # probably general error in mmp.magic.move...
        except Exception as e:
            self.unexpected_exception( e )
            self.report_problem_file(event=event, exception=e)