Exemplo n.º 1
0
def vfs_walk(uri):
	"""in the style of os.path.walk, but using gnomevfs.
	
	uri -- the base folder uri.
	return a list of uri.
	
	"""

	if not isinstance(uri, gnomevfs.URI):
		uri = gnomevfs.URI(uri)

	if str(uri)[-1] != '/':
		uri = uri.append_string("/")

	#info = gnomevfs.get_file_info(uri, gnomevfs.FILE_INFO_GET_MIME_TYPE)
	filelist = []	

	try:
		dirlist = gnomevfs.open_directory(uri)
	except:
		log(_("skipping: '%s'") % uri)
		return filelist
		
	for file_info in dirlist:
		if file_info.name[0] == ".":
			continue
	
		if file_info.type == gnomevfs.FILE_TYPE_DIRECTORY:
			filelist.extend(
				vfs_walk(uri.append_path(file_info.name)) )

		if file_info.type == gnomevfs.FILE_TYPE_REGULAR:
			filelist.append( str(uri.append_file_name(file_info.name)) )
	return filelist
def vfs_walk(uri):
	"""similar to os.path.walk, but with gnomevfs.
	
	uri -- the base folder uri.
	return a list of uri.
	
	"""
	if str(uri)[-1] != '/':
		uri = uri.append_string("/")

	info = gnomevfs.get_file_info(uri, gnomevfs.FILE_INFO_GET_MIME_TYPE)
	filelist = []	

	try:
		dirlist = gnomevfs.open_directory(uri)
	except:
		pass
		print "skipping:", uri
		return filelist
		
	for file_info in dirlist:
		if file_info.name[0] == ".":
			continue
	
		if file_info.type == 2:
			filelist.extend(
				vfs_walk(
					uri.resolve_relative(file_info.name)
					))

		if file_info.type == 1:
			filelist.append( str(uri.append_string(file_info.name)) )
	return filelist
Exemplo n.º 3
0
def vfs_walk(uri):
    """similar to os.path.walk, but with gnomevfs.

    uri -- the base folder uri.
    return a list of uri.

    """
    if str(uri)[-1] != "/":
        uri = uri.append_string("/")

    filelist = []

    try:
        dirlist = gnomevfs.open_directory(uri, gnomevfs.FILE_INFO_FOLLOW_LINKS)
        for file_info in dirlist:
            try:
                if file_info.name[0] == ".":
                    continue

                if file_info.type == gnomevfs.FILE_TYPE_DIRECTORY:
                    filelist.extend(vfs_walk(uri.append_path(file_info.name)))

                if file_info.type == gnomevfs.FILE_TYPE_REGULAR:
                    filelist.append(str(uri.append_file_name(file_info.name)))
            except ValueError:
                # this can happen when you do not have sufficent
                # permissions to read file info.
                log("skipping: '%s'" % file_info.name)
    except:
        log("skipping: '%s'" % uri)
        return filelist

    return filelist
Exemplo n.º 4
0
 def cacheFiles(self):
     """
     Fetches the files contained on the directory for posterior usage of
     them. This should be called on the worker side to work or the files
     wouldn't be the expected ones.
     """
     import gnomevfs
     log.debug('vfsgnome', 'getting files for %s' % (self.path, ))
     retval = []
     try:
         fileInfos = gnomevfs.open_directory(self.path)
     except gnomevfs.AccessDeniedError:
         raise AccessDeniedError
     if self.path != '/':
         retval.append(
             GnomeVFSDirectory(os.path.dirname(self.path), name='..'))
     for fileInfo in fileInfos:
         filename = fileInfo.name
         if filename.startswith('.'):
             continue
         if fileInfo.type == gnomevfs.FILE_TYPE_DIRECTORY:
             obj = GnomeVFSDirectory(os.path.join(self.path, fileInfo.name))
         else:
             obj = GnomeVFSFile(self.path, fileInfo)
         retval.append(obj)
     log.log('vfsgnome', 'returning %r' % (retval, ))
     self._cachedFiles = retval
Exemplo n.º 5
0
def vfs_walk(uri):
    """in the style of os.path.walk, but using gnomevfs.
	
	uri -- the base folder uri.
	return a list of uri.
	"""
    if not isinstance(uri, gnomevfs.URI):
        uri = gnomevfs.URI(uri)
    if str(uri)[-1] != '/':
        uri = uri.append_string("/")
    filelist = []
    try:
        dirlist = gnomevfs.open_directory(uri)
    except:
        log(_("skipping: '%s'") % uri)
        return filelist

    for file_info in dirlist:
        if file_info.name[0] == ".":
            continue

        if file_info.type == gnomevfs.FILE_TYPE_DIRECTORY:
            filelist.extend(vfs_walk(uri.append_path(file_info.name)))

        if file_info.type == gnomevfs.FILE_TYPE_REGULAR:
            filelist.append(str(uri.append_file_name(file_info.name)))
    return filelist
Exemplo n.º 6
0
 def cacheFiles(self):
     """
     Fetches the files contained on the directory for posterior usage of
     them. This should be called on the worker side to work or the files
     wouldn't be the expected ones.
     """
     import gnomevfs
     log.debug('vfsgnome', 'getting files for %s' % (self.path, ))
     retval = []
     try:
         fileInfos = gnomevfs.open_directory(self.path)
     except gnomevfs.AccessDeniedError:
         raise AccessDeniedError
     if self.path != '/':
         retval.append(GnomeVFSDirectory(os.path.dirname(self.path),
                                         name='..'))
     for fileInfo in fileInfos:
         filename = fileInfo.name
         if filename.startswith('.'):
             continue
         if fileInfo.type == gnomevfs.FILE_TYPE_DIRECTORY:
             obj = GnomeVFSDirectory(os.path.join(self.path,
                                                  fileInfo.name))
         else:
             obj = GnomeVFSFile(self.path, fileInfo)
         retval.append(obj)
     log.log('vfsgnome', 'returning %r' % (retval, ))
     self._cachedFiles = retval
Exemplo n.º 7
0
def vfs_walk(uri):
    """similar to os.path.walk, but with gnomevfs.

    uri -- the base folder uri.
    return a list of uri.

    """
    if str(uri)[-1] != '/':
        uri = uri.append_string('/')

    filelist = []

    try:
        dirlist = gnomevfs.open_directory(uri, gnomevfs.FILE_INFO_FOLLOW_LINKS)
        for file_info in dirlist:
            try:
                if file_info.name[0] == '.':
                    continue

                if file_info.type == gnomevfs.FILE_TYPE_DIRECTORY:
                    filelist.extend(vfs_walk(uri.append_path(file_info.name)))

                if file_info.type == gnomevfs.FILE_TYPE_REGULAR:
                    filelist.append(str(uri.append_file_name(file_info.name)))
            except ValueError:
                # this can happen when you do not have sufficent
                # permissions to read file info.
                log("skipping: \'%s\'" % file_info.name)
    except:
        log("skipping: '%s\'" % uri)
        return filelist

    return filelist
Exemplo n.º 8
0
 def _trash_dir_changed(self):
     count = 0
     try:
         for file in gnomevfs.open_directory(self.trash_uri):
             if file.name not in (".", ".."):
                 count += 1
     except gnomevfs.Error:
         pass
     self.trash_cnt = count
     self.emit("count-changed")
Exemplo n.º 9
0
 def __init__(self, current_dir=os.getenv("HOME")):
     """
     Constructor.
     
     @param current_dir: a directory path.
     @type current_dir: a string.
     """
     if current_dir == "":
         self.current_dir = os.getenv("HOME")
     else:
         self.current_dir = current_dir
         try:
             gnomevfs.open_directory(self.current_dir)
         except gnomevfs.NotFoundError:
             self.current_dir = os.getenv("HOME")
         except gnomevfs.IOError:
             self.current_dir = os.getenv("HOME")
         except gnomevfs.AccessDeniedError:
             self.current_dir = os.getenv("HOME")
Exemplo n.º 10
0
    def __init__(self, uri = None):
        gtk.GenericTreeModel.__init__(self)

        if uri:
            self.uri = gnomevfs.URI(uri)
        else:
            self.uri = gnomevfs.URI(os.getcwd())
        if str(self.uri)[-1] != '/':
            self.uri = self.uri.append_string('/')

        self.files = {}
        dhandle = gnomevfs.open_directory(self.uri)

        dirs = []
        files = []
        self.fileInfos = {}
        
        for entry in dhandle:
            file = self.uri.resolve_relative(entry.name)
            info = gnomevfs.get_file_info(file, gnomevfs.FILE_INFO_GET_MIME_TYPE)
            self.fileInfos[entry.name] = info
            
            if entry.type == gnomevfs.FILE_TYPE_DIRECTORY:
                dirs.append(entry.name)
            elif entry.type == gnomevfs.FILE_TYPE_SYMBOLIC_LINK:
                # FIXME: check if it points to dir or file
                files.append(entry.name)
            else:
                files.append(entry.name)
        
        dirs = dirs[2:] # getrid of . and ..
        dirs.sort()
        files.sort()
        self.files = dirs + files

        self.iconTheme = gtk.icon_theme_get_default()
        self.iconFactory = gnome.ui.ThumbnailFactory(gnome.ui.THUMBNAIL_SIZE_NORMAL)
Exemplo n.º 11
0
    def load_tree(self, target):
        """
        Loads the tree information from the target backup directory
        """
        self.treestore.clear()

        # Checking if the target directory is local or remote
        local = True
        try:
            if gnomevfs.URI(target).is_local:
                target = gnomevfs.get_local_path_from_uri(target)
            else:
                local = False
        except:
            pass

        self.local = local
        self.target = target

        # Checking if it is a readable directory
        if local:
            if not (os.path.exists(target) and os.path.isdir(target)
                    and os.access(target, os.R_OK | os.X_OK)):
                self.treestore.append(
                    None, ["Error: backups directory does not exist!"])
                self.target = False
        else:
            if not (gnomevfs.exists(target)
                    and gnomevfs.get_file_info(target).type == 2):
                self.treestore.append(
                    None, ["Error: backups directory does not exist!"])
                self.target = False

        # Get list of backup directories
        r = re.compile(
            r"^(\d{4})-(\d{2})-(\d{2})_(\d{2})[\:\.](\d{2})[\:\.](\d{2})\.\d+\..*?\.(.+)$"
        )

        listing = []

        if local and self.target:
            listing = os.listdir(target)
            listing = filter(r.search, listing)
        elif self.target:
            try:
                d = gnomevfs.open_directory(target)
                listing = []
                for f in d:
                    if f.type == 2 and f.name != "." and f.name != ".." and r.search(
                            f.name):
                        listing.append(f.name)
            except:
                pass

        # Check if these directories are complete and remove from the list those that are not
        for adir in listing[:]:
            if not gnomevfs.exists(self.target + "/" + adir + "/ver"):
                listing.remove(adir)
                continue
            else:
                if str(
                        gnomevfs.read_entire_file(self.target + "/" + adir +
                                                  "/ver"))[:3] != "1.4":
                    listing.remove(adir)
                    continue

        listing.sort()
        listing.reverse()

        self.vtree = {}

        if listing == []:
            self.treestore.append(
                None, ["Error: no backups found in the target directory"])
            self.target = False
        else:
            for base in listing:
                if str(gnomevfs.read_entire_file(target + "/" + base +
                                                 "/ver"))[:3] == "1.4":
                    self.vtree[base] = str(
                        gnomevfs.read_entire_file(target + "/" + base +
                                                  "/flist")).split("\000")
                else:
                    self.vtree[base] = str(
                        gnomevfs.read_entire_file(target + "/" + base +
                                                  "/flist")).split("\n")

        self.blist.clear()

        for base in listing:
            self.blist.append([base])

        self.good = False
        self.on_selection_change()
        if self.target:
            self.treestore.append(None, [
                "Select any of the available backups to see list of files that can be restored."
            ])
Exemplo n.º 12
0
    def ls(self, dir=''):
        dir = self.cwd.resolve_relative(dir)

        dhandle = gnomevfs.open_directory(dir)
        for file_info in dhandle:
            print file_info.name