Example #1
0
    def transfer(self, overwrite, cancel_func):
        if cancel_func:
            self._cancel_func = cancel_func

        if overwrite:
            mode = gnomevfs.XFER_OVERWRITE_MODE_REPLACE
        else:
            mode = gnomevfs.XFER_OVERWRITE_MODE_SKIP

        log.debug("Transfering File %s -> %s" % (self._source, self._dest))

        # recursively create all parent dirs if needed
        parent = str(self._dest.parent)
        if not gnomevfs.exists(parent):
            d = FileImpl(None, impl=self._dest.parent)
            d.make_directory_and_parents()

        # Copy the file
        try:
            result = gnomevfs.xfer_uri(
                source_uri=self._source,
                target_uri=self._dest,
                xfer_options=gnomevfs.XFER_NEW_UNIQUE_DIRECTORY,
                error_mode=gnomevfs.XFER_ERROR_MODE_ABORT,
                overwrite_mode=mode,
                progress_callback=self._xfer_progress_callback,
            )
            # FIXME: Check error
            return True, FileImpl(None, impl=self._dest)
        except gnomevfs.InterruptedError:
            return False, None
        except Exception, e:
            log.warn("File transfer error: %s" % e)
            return False, None
Example #2
0
def vfs_rename(original, newname):
    """Rename a gnomevfs file"""
    
    uri = gnomevfs.URI(newname)
    dirname = uri.parent
    if dirname and not gnomevfs.exists(dirname):
        log('Creating folder: \'%s\'' % dirname)
        if not vfs_makedirs(str(dirname)):
            show_error(_('Cannot create folder!'), unquote_filename(dirname.path))
            return 'cannot-create-folder'

    try:
        gnomevfs.xfer_uri(gnomevfs.URI(original), uri,
                          gnomevfs.XFER_REMOVESOURCE,
                          gnomevfs.XFER_ERROR_MODE_ABORT,
                          gnomevfs.XFER_OVERWRITE_MODE_ABORT
                         )
    except Exception as error:
        # TODO: maybe we need a special case here. If dest folder is unwritable. Just stop.
        # or an option to stop all processing.
        show_error(_('Error while renaming file!'), '%s: %s' % (beautify_uri(newname), error))
        return 'cannot-rename-file'
Example #3
0
def vfs_rename(original, newname):
    """Rename a gnomevfs file"""

    uri = gnomevfs.URI(newname)
    dirname = uri.parent
    if dirname and not gnomevfs.exists(dirname):
        log('Creating folder: \'%s\'' % dirname)
        if not vfs_makedirs(str(dirname)):
            show_error(_('Cannot create folder!'),
                       unquote_filename(dirname.path))
            return 'cannot-create-folder'

    try:
        gnomevfs.xfer_uri(gnomevfs.URI(original), uri,
                          gnomevfs.XFER_REMOVESOURCE,
                          gnomevfs.XFER_ERROR_MODE_ABORT,
                          gnomevfs.XFER_OVERWRITE_MODE_ABORT)
    except Exception as error:
        # TODO: maybe we need a special case here. If dest folder is unwritable. Just stop.
        # or an option to stop all processing.
        show_error(_('Error while renaming file!'),
                   '%s: %s' % (beautify_uri(newname), error))
        return 'cannot-rename-file'
Example #4
0
    old = termios.tcgetattr(fd)
    atexit.register(_restore_term_mode, fd, old)
    new = termios.tcgetattr(fd)
    new[3] = new[3] & ~termios.ICANON
    termios.tcsetattr(fd, termios.TCSADRAIN, new)


parser = OptionParser(usage="usage: %prog [options] source-uri dest-uri")
options, args = parser.parse_args()

if len(args) != 2:
    parser.error("wrong number of arguments")

src = gnomevfs.URI(args[0])
dst = gnomevfs.URI(args[1])

def progress_info_cb(info, data):
    assert data == 0x1234
    try:
        print "%s: %f %%\r" % (info.target_name,
                               info.bytes_copied/float(info.bytes_total)*100),
    except Exception, ex:
        pass
    return True
set_non_canonical(sys.stdout)
gnomevfs.xfer_uri(source_uri=src, target_uri=dst,
                  xfer_options=gnomevfs.XFER_DEFAULT,
                  error_mode=gnomevfs.XFER_ERROR_MODE_ABORT,
                  overwrite_mode=gnomevfs.XFER_OVERWRITE_MODE_ABORT,
                  progress_callback=progress_info_cb, data=0x1234)
Example #5
0
    def save(self):
        """Save the file, then close this window"""

        if self.already_saved:
            return

        self.player.stop()

        save_succesful = False

        if Preferences().has_gnomevfs():
            import gnomevfs

            try:
                trysave = gnomevfs.xfer_uri(
                    gnomevfs.URI("file://%s" % self.location),
                    gnomevfs.URI(self.filechooser.get_uri()),
                    gnomevfs.XFER_DELETE_ITEMS,
                    gnomevfs.XFER_ERROR_MODE_ABORT,
                    gnomevfs.XFER_OVERWRITE_MODE_ABORT,
                )
            except gnomevfs.FileExistsError:
                dialog = gtk.MessageDialog(
                    self,
                    gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
                    gtk.MESSAGE_QUESTION,
                    gtk.BUTTONS_YES_NO,
                    _('A file named "%s" already exists.  Do you want to replace it?') % self.filechooser.get_uri(),
                )
                dialog.format_secondary_text(
                    _('The file already exists in "%s".  Replacing it will overwrite its contents.')
                    % (self.filechooser.get_current_folder())
                )
                res = dialog.run()
                dialog.hide()
                if res == gtk.RESPONSE_YES:
                    try:
                        trysave = gnomevfs.xfer_uri(
                            gnomevfs.URI("file://%s" % self.location),
                            gnomevfs.URI(self.filechooser.get_uri()),
                            gnomevfs.XFER_DELETE_ITEMS,
                            gnomevfs.XFER_ERROR_MODE_ABORT,
                            gnomevfs.XFER_OVERWRITE_MODE_REPLACE,
                        )
                    except Exception:
                        dialog = gtk.MessageDialog(
                            self,
                            gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
                            gtk.MESSAGE_QUESTION,
                            gtk.BUTTONS_OK,
                            _('There was an unknown error writing to "%s".  Please try a different file or location.')
                            % (self.filechooser.get_uri()),
                        )
                        dialog.run()
                        dialog.hide()
                    else:
                        save_succesful = True
            else:
                save_succesful = True
        else:
            # we do not have Gnomevfs so let us use normal python calls to
            # move the file
            # the file chooser uri will start with file:// so take character 8
            # onwards
            import shutil

            try:
                shutil.move(self.location, self.filechooser.get_uri()[7:])
            except Exception:
                dialog = gtk.MessageDialog(
                    self,
                    gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
                    gtk.MESSAGE_QUESTION,
                    gtk.BUTTONS_OK,
                    _('There was an unknown error writing to "%s".  Please try a different file or location.')
                    % (self.filechooser.get_uri()),
                )
                dialog.run()
                dialog.hide()
            else:
                save_succesful = True

        if save_succesful:

            # Save seemed to be succesful
            self.already_saved = True
            self.save_location = self.filechooser.get_uri()
            self.player.set_location(self.save_location)
            self.save_button.set_sensitive(False)

            # Close the save dialog. This should be removed if the
            # "edit" stuff has been implemented
            self.destroy()