def gvfsToWav (src_uri, sink_uri):
		"Converts a given source URI to a wav located in sink URI."
		src = gst.element_factory_make ("gnomevfssrc")
		src.set_property ("location", src_uri)
		handle = gnomevfs.Handle (sink_uri)
		sink = gst.element_factory_make ("gnomevfssink")
		sink.set_property ("handle", handle)
		return sourceToWav (src, sink)
Beispiel #2
0
def vfs_clean_uri(uri):
    """return an uri from an uri or a local path"""
    try:
        gnomevfs.URI(uri)
        gnomevfs.Handle(uri)
    except:  #gnomevfs.InvalidURIError:
        try:
            uri_ = uri.replace('%5C', '/')  # convert backslashes
            gnomevfs.URI(uri_)
            gnomevfs.Handle(uri_)
            uri = uri_
        except:  #gnomevfs.InvalidURIError:
            # maybe a local path ?
            local = os.path.abspath(uri)
            if os.path.exists(local):
                uri = gnomevfs.get_uri_from_local_path(local)
            uri = gnomevfs.escape_host_and_path_string(uri)
    return uri
Beispiel #3
0
def vfs_open(uri, mode="r"):
    """return a file() compatible object from an uri"""
    try:
        uri = vfs_clean_uri(uri)
        uri = gnomevfs.URI(uri)
        f = gnomevfs.Handle(uri)
        return f
    except:
        log("Cannot load '%s'" % str(uri))
        return None
Beispiel #4
0
def vfs_clean_uri(uri):
    """return an uri from an uri or a local path"""
    try:
        gnomevfs.URI(uri)
        gnomevfs.Handle(uri)
    except:  #gnomevfs.InvalidURIError:
        # maybe a local path ?
        local = os.path.abspath(uri)
        if os.path.exists(local):
            uri = gnomevfs.get_uri_from_local_path(local)
        uri = gnomevfs.escape_host_and_path_string(uri)
    return uri
 def save_file(self):
     """Save the file.  The filename must already have been set"""
     try:
         file = cPickle.dumps(self.puzzle, cPickle.HIGHEST_PROTOCOL)
         if self.uri and RECENT_CHOOSER:
             #We know the file by its URI
             handler = gnomevfs.Handle(self.uri, gnomevfs.OPEN_WRITE)
         elif self.filename:
             #We know the file by its filename
             handler = open(self.filename, 'wb')
         handler.write(file)
         handler.close()
         self.set_dirty(False)
     except IOError, (error_number, error_message):
         error_dialog = gtk.MessageDialog(
             self.main_window,
             gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
             gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE, "Error saving file")
         error_dialog.format_secondary_text(error_message)
         error_dialog.run()
         error_dialog.destroy()
 def load_file(self, filename, type="URI"):
     """Opens the FTW file with a the supplied URI or filename and returns True if successful.  We
     prefer to work with URIs than files, as they're easier to add to the recent file list.  In the
     interests of simplicity, we only add URIs to the recent file list"""
     self.set_dirty("clean")
     try:
         if type == "URI" and RECENT_CHOOSER:
             handler = gnomevfs.Handle(filename)
             file_size = handler.get_file_info().size
             new_file = handler.read(file_size)
             self.puzzle = cPickle.loads(new_file)
             handler.close()
             #make a crude guess at a sensible filename from the URI
             uri = filename
             filename = uri[uri.find(':///') + 4:]
             self.set_filename(filename, uri, False)
         else:
             file = open(filename, 'rb')
             self.puzzle = cPickle.load(file)
             self.set_filename(filename, None, False)
             file.close()
         self.puzzle.grid.puzzle = self.puzzle
         #Update the display
         self.update_all_widgets()
         self.set_dirty(False)
         return True
     except:
         #Loading the file failed in some way or another
         error_dialog = gtk.MessageDialog(
             self.main_window,
             gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
             gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE, "Unable to open file")
         error_dialog.format_secondary_text(filename)
         error_dialog.run()
         error_dialog.destroy()
         return False
Beispiel #7
0
def open_for_write(filename, mode=0666):
    try:
        return gnomevfs.create(filename, gnomevfs.OPEN_WRITE, mode)
    except gnomevfs.FileExistsError:
        return gnomevfs.Handle(filename, gnomevfs.OPEN_WRITE)
Beispiel #8
0
def vfs_open(uri, mode="r"):
    """return a file() compatible object from an uri"""
    uri = vfs_clean_uri(uri)
    uri = gnomevfs.URI(uri)
    f = gnomevfs.Handle(uri)
    return f