def write_files(app, files):
    """Helper function that takes a Serpentine application adds the files
    to the music list and writes them. When no `app` is provided a
    HeadlessApplication is created."""
    files = map(os.path.abspath, files)
    files = map(urlutil.normalize, files)
    queue = OperationsQueue()
    queue.append(app.add_files(files))
    queue.append(CallableOperation(lambda: app.write_files().start()))
    queue.start()
    def add_hints (self, hints_list, insert = None):
        assert insert is None or isinstance (insert, IntType)

        queue = OperationsQueue()
        queue.abort_on_failure = False
        
        handler = self.Handler ()
        
        handler.prepare_queue (self, queue)
        
        i = 0
        for h in hints_list:
            pls = self.__filter_location (h["location"])
            
            if pls is not None and len (pls) > 0:
                # normalize the returning elements
                map(normalize_hints, pls)
                # We add this to the queue so it is
                # processed before the next file on the list
                queue.append (self.add_hints(pls, insert))
                continue
                
            ins = insert
            if insert != None:
                ins += i
            
            a = AddFile (self.music_list, h, ins, self._app())
            handler.prepare_add_file (self, a)
            
            queue.append (a)
            
            i += 1
        
        handler.finish_queue (self, queue)
        return queue
def write_files (app, files):
    """Helper function that takes a Serpentine application adds the files
    to the music list and writes them. When no `app` is provided a
    HeadlessApplication is created."""
    files = map (os.path.abspath, files)
    files = map (urlutil.normalize, files)
    queue = OperationsQueue ()
    queue.append (app.add_files (files))
    queue.append (CallableOperation (lambda: app.write_files().start()))
    queue.start ()
    def add_hints (self, hints_list, insert = None):
        assert insert is None or isinstance (insert, IntType)

        queue = OperationsQueue()
        queue.abort_on_failure = False
        
        handler = self.Handler ()
        
        handler.prepare_queue (self, queue)
        
        i = 0
        for h in hints_list:
            pls = self.__filter_location (h["location"])
            if pls is not None and len (pls) > 0:
                # We add this to the queue so it is
                # processed before the next file on the list
                queue.append (self.add_hints(pls, insert))
                continue
                
            ins = insert
            if insert != None:
                ins += i
            
            a = AddFile (self.music_list, h, ins)
            handler.prepare_add_file (self, a)
            
            queue.append (a)
            
            i += 1
        
        handler.finish_queue (self, queue)
        return queue
	def add_file (self, hints):
		w = gtkutil.get_root_parent (self)
		assert isinstance(w, gtk.Window)
		pls = self.__add_playlist (hints['location'])
		if pls is not None:
			self.add_files (pls)
			return
			
		trapper = ErrorTrapper (w)
		a = AddFile (self.source, hints)
		queue = OperationsQueue()
		queue.abort_on_failure = False
		queue.append (a)
		queue.append (trapper)
		queue.start()
	def add_files (self, hints_list, insert = None):
		assert insert is None or isinstance (insert, IntType)
		# Lock graphical updating on each request and
		# only refresh the UI later
		w = gtkutil.get_root_parent (self)
		assert isinstance(w, gtk.Window), type(w)
		
		trapper = ErrorTrapper (w)
		queue = OperationsQueue()
		queue.abort_on_failure = False
		queue.append (SetGraphicalUpdate (self, False))
		i = 0

		for h in hints_list:
			pls = self.__filter_location (h['location'])
			if pls is not None:
				self.add_files(pls, insert)
				continue
				
			ins = insert
			if insert != None:
				ins += i
			a = AddFile (self.source, h, ins)
			a.listeners.append (trapper)
			queue.append (a)
			i += 1
			
		queue.append (SetGraphicalUpdate (self, True))
		queue.append (trapper)
		queue.start()