예제 #1
0
 def make_directory(self):
     gnomevfs.make_directory(
         self.get_text_uri(),
         gnomevfs.PERM_USER_ALL
         | gnomevfs.PERM_GROUP_READ
         | gnomevfs.PERM_GROUP_EXEC
         | gnomevfs.PERM_OTHER_READ
         | gnomevfs.PERM_OTHER_EXEC,
     )
     self.close()
     return True
예제 #2
0
def vfs_makedirs(uri, mode=0777):
    """Similar to os.makedirs, but with gnomevfs"""

    if isinstance(uri, basestring):
        uri = gnomevfs.URI(uri)
    path = uri.path

    # start at root
    uri = uri.resolve_relative("/")

    for folder in path.split("/"):
        if not folder:
            continue
        uri = uri.append_string(folder)
        try:
            gnomevfs.make_directory(uri, mode)
        except gnomevfs.FileExistsError:
            pass
예제 #3
0
파일: vfs_util.py 프로젝트: mgood/germanium
def vfs_makedirs(uri, mode=0777):
    """Similar to os.makedirs, but with gnomevfs"""

    if isinstance(uri, basestring):
        uri = gnomevfs.URI(uri)
    path = uri.path

    # start at root
    uri =  uri.resolve_relative("/")
    
    for folder in path.split("/"):
        if not folder:
            continue
        uri = uri.append_string(folder)
        try:
            gnomevfs.make_directory(uri, mode)
        except gnomevfs.FileExistsError:
            pass
예제 #4
0
def vfs_makedirs(path_to_create):
	"""Similar to os.makedirs, but with gnomevfs"""
	
	uri = gnomevfs.URI(path_to_create)
	path = uri.path

	# start at root
	uri =  uri.resolve_relative("/")
	
	for folder in path.split("/"):
		if not folder:
			continue
		uri = uri.append_string(folder)
		try:
			gnomevfs.make_directory(uri, 0777)
		except gnomevfs.FileExistsError:
			pass
		except:
			return False
	return True	
예제 #5
0
    def make_directory_and_parents(self):
        dirs = []

        directory = self._URI
        exists = gnomevfs.exists(self._URI)
        while not exists:
            dirs.append(directory)
            directory = directory.parent
            exists = gnomevfs.exists(directory)

        dirs.reverse()
        for d in dirs:
            log.debug("Making directory %s" % d)
            gnomevfs.make_directory(
                str(d),
                gnomevfs.PERM_USER_ALL
                | gnomevfs.PERM_GROUP_READ
                | gnomevfs.PERM_GROUP_EXEC
                | gnomevfs.PERM_OTHER_READ
                | gnomevfs.PERM_OTHER_EXEC,
            )
예제 #6
0
    def new_folder(self, widget):
        """
        Create a new folder in the current directory.
        
        @param widget: Reference to the button.
        @type widget: A Button object.
        """
        
        sel_model, sel_iter = self.treeview.get_selection().get_selected()
        dir_iter = None
        
        new_file_dir = self.flist.get_current_dir()
        path = None
        
        # If some selection exists
        if sel_iter != None:
            path = self.treestore.get_path(sel_iter)

            if len(path) == 1: # New file will be created in current folder
                dir_iter = None
            else:
                dir_iter = self.treestore.get_iter(path[0:len(path) - 1])
            
            for i in range(1, len(path)):
                dir_iter = self.treestore.get_iter(path[0:i])
                iter_value = self.treestore.get_value(dir_iter, 1)
                new_file_dir = os.path.join(new_file_dir, iter_value)
            
        #Create file
        i = 1
        new_file_name = _("New Folder")
        new_file_uri = os.path.join(new_file_dir, new_file_name)

        while gnomevfs.exists(new_file_uri):
            new_file_uri = \
            os.path.join(new_file_dir, new_file_name + " " + str(i))
            i += 1
        
        old_file_dir = self.flist.get_current_dir()
        self.flist.set_current_dir(new_file_dir)
        
        try:
            files = self.flist.get_files(False)
            gnomevfs.make_directory(new_file_uri, 0755)
        except gnomevfs.AccessDeniedError:
            main_text = _("<b>You can't create a folder.</b>")
            secondary_text = _("You don't have the required permissions to create a folder in this directory.") 
            error = ErrorDialog(main_text, secondary_text)
            error_return = error.run()
            
            if error_return == gtk.RESPONSE_DELETE_EVENT:
                error.destroy()
                return
            elif error_return == 1:
                error.destroy()
                return
        
        # Verifying if the directory is empty to delete "(Empty)" string.
        if len(files) == 0:
            if dir_iter == None:
                empty_path = (0,)
            else:
                empty_path = list(path)
                empty_path[len(path)-1] = 0
                empty_path = tuple(empty_path)
                
            empty_iter = self.treestore.get_iter(empty_path)
            self.treestore.remove(empty_iter)
        
        icon = self.treeview.render_icon(gtk.STOCK_DIRECTORY,
                                         gtk.ICON_SIZE_MENU)
        name = gnomevfs.URI(new_file_uri).short_name
        new_iter = self.treestore.append(dir_iter, [icon, name])
        
        if len(files) == 0 and dir_iter != None:
            self.treeview.expand_row(path[0:len(path) - 1], False)
        
        self.flist.set_current_dir(old_file_dir)
        
        path = self.treestore.get_path(new_iter)
        self.cell2.set_property('editable', True)
        self.treeview.set_cursor_on_cell(path, self.tvcolumn, self.cell2,
                                         start_editing=True)
        self.cell2.set_property('editable', False)