Esempio n. 1
0
    def _get_right_part(self, bar):
        right = bar.right
        if self.column is None:
            return

        target = self.column.target
        if target is None \
                or not target.accessible \
                or (target.is_directory and target.files is None):
            return

        pos = target.scroll_begin
        max_pos = len(target) - self.column.hei
        base = 'scroll'

        if self.fm.thisdir.filter:
            right.add(" f=`", base, 'filter')
            right.add(self.fm.thisdir.filter.pattern, base, 'filter')
            right.add("', ", "space")

        if target.marked_items:
            if len(target.marked_items) == len(target.files):
                right.add(human_readable(target.disk_usage, separator=''))
            else:
                sumsize = sum(
                    f.size for f in target.marked_items
                    if not f.is_directory or f._cumulative_size_calculated)
                right.add(human_readable(sumsize, separator=''))
            right.add("/" + str(len(target.marked_items)))
        else:
            right.add(human_readable(target.disk_usage, separator='') + " sum")
            try:
                free = get_free_space(target.mount_path)
            except OSError:
                pass
            else:
                right.add(", ", "space")
                right.add(human_readable(free, separator='') + " free")
        right.add("  ", "space")

        if target.marked_items:
            # Indicate that there are marked files. Useful if you scroll
            # away and don't see them anymore.
            right.add('Mrk', base, 'marked')
        elif len(target.files):
            right.add(
                str(target.pointer + 1) + '/' + str(len(target.files)) + '  ',
                base)
            if max_pos <= 0:
                right.add('All', base, 'all')
            elif pos == 0:
                right.add('Top', base, 'top')
            elif pos >= max_pos:
                right.add('Bot', base, 'bot')
            else:
                right.add('{0:0>.0f}%'.format(100.0 * pos / max_pos), base,
                          'percentage')
        else:
            right.add('0/0  All', base, 'all')
Esempio n. 2
0
    def _get_right_part(self, bar):
        right = bar.right
        if self.column is None:
            return

        target = self.column.target
        if target is None \
                or not target.accessible \
                or (target.is_directory and target.files is None):
            return

        pos = target.scroll_begin
        max_pos = len(target) - self.column.hei
        base = 'scroll'

        if self.fm.thisdir.filter:
            right.add(" f=`", base, 'filter')
            right.add(self.fm.thisdir.filter.pattern, base, 'filter')
            right.add("', ", "space")

        if target.marked_items:
            if len(target.marked_items) == len(target.files):
                right.add(human_readable(target.disk_usage, separator=''))
            else:
                sumsize = sum(f.size for f in target.marked_items if not
                        f.is_directory or f._cumulative_size_calculated)
                right.add(human_readable(sumsize, separator=''))
            right.add("/" + str(len(target.marked_items)))
        else:
            right.add(human_readable(target.disk_usage, separator='') + " sum")
            try:
                free = get_free_space(target.mount_path)
            except OSError:
                pass
            else:
                right.add(", ", "space")
                right.add(human_readable(free, separator='') + " free")
        right.add("  ", "space")

        if target.marked_items:
            # Indicate that there are marked files. Useful if you scroll
            # away and don't see them anymore.
            right.add('Mrk', base, 'marked')
        elif len(target.files):
            right.add(str(target.pointer + 1) + '/'
                    + str(len(target.files)) + '  ', base)
            if max_pos <= 0:
                right.add('All', base, 'all')
            elif pos == 0:
                right.add('Top', base, 'top')
            elif pos >= max_pos:
                right.add('Bot', base, 'bot')
            else:
                right.add('{0:0>.0f}%'.format(100.0 * pos / max_pos),
                        base, 'percentage')
        else:
            right.add('0/0  All', base, 'all')
Esempio n. 3
0
    def _get_right_part(self, bar):
        right = bar.right
        if self.column is None:
            return

        target = self.column.target
        if target is None \
          or not target.accessible \
          or (target.is_directory and target.files is None):
            return

        pos = target.scroll_begin
        max_pos = len(target) - self.column.hei
        base = 'scroll'

        if self.env.cwd.filter:
            right.add(" f=", base, 'filter')
            right.add(repr(self.env.cwd.filter), base, 'filter')
            right.add(", ", "space")

        if target.marked_items:
            if len(target.marked_items) == len(target.files):
                right.add(human_readable(target.disk_usage, seperator=''))
            else:
                right.add(human_readable(sum(f.size \
                 for f in target.marked_items \
                 if f.is_file), seperator=''))
            right.add("/" + str(len(target.marked_items)))
        else:
            right.add(
                human_readable(target.disk_usage, seperator='') + " sum, ")
            right.add(human_readable(self.env.get_free_space( \
              target.mount_path), seperator='') + " free")
        right.add("  ", "space")

        if target.marked_items:
            # Indicate that there are marked files. Useful if you scroll
            # away and don't see them anymore.
            right.add('Mrk', base, 'marked')
        elif len(target.files):
            right.add(
                str(target.pointer + 1) + '/' + str(len(target.files)) + '  ',
                base)
            if max_pos == 0:
                right.add('All', base, 'all')
            elif pos == 0:
                right.add('Top', base, 'top')
            elif pos >= max_pos:
                right.add('Bot', base, 'bot')
            else:
                right.add('{0:0>.0f}%'.format(100.0 * pos / max_pos), base,
                          'percentage')
        else:
            right.add('0/0  All', base, 'all')
Esempio n. 4
0
	def _get_right_part(self, bar):
		right = bar.right
		if self.column is None:
			return

		target = self.column.target
		if target is None \
				or not target.accessible \
				or (target.is_directory and target.files is None):
			return

		pos = target.scroll_begin
		max_pos = len(target) - self.column.hei
		base = 'scroll'

		if self.env.cwd.filter:
			right.add(" f=", base, 'filter')
			right.add(repr(self.env.cwd.filter), base, 'filter')
			right.add(", ", "space")

		if target.marked_items:
			if len(target.marked_items) == len(target.files):
				right.add(human_readable(target.disk_usage, seperator=''))
			else:
				right.add(human_readable(sum(f.size \
					for f in target.marked_items \
					if f.is_file), seperator=''))
			right.add("/" + str(len(target.marked_items)))
		else:
			right.add(human_readable(target.disk_usage, seperator='') +
					" sum, ")
			right.add(human_readable(self.env.get_free_space( \
					target.mount_path), seperator='') + " free")
		right.add("  ", "space")

		if target.marked_items:
			# Indicate that there are marked files. Useful if you scroll
			# away and don't see them anymore.
			right.add('Mrk', base, 'marked')
		elif len(target.files):
			right.add(str(target.pointer + 1) + '/'
					+ str(len(target.files)) + '  ', base)
			if max_pos == 0:
				right.add('All', base, 'all')
			elif pos == 0:
				right.add('Top', base, 'top')
			elif pos >= max_pos:
				right.add('Bot', base, 'bot')
			else:
				right.add('{0:0>.0f}%'.format(100.0 * pos / max_pos),
						base, 'percentage')
		else:
			right.add('0/0  All', base, 'all')
Esempio n. 5
0
    def generate(self):
	if not self.copy_buffer or len(self.copy_buffer) > 1:
	    return

	from ranger.ext import shutil_generatorized as shutil_g
	# TODO: Don't calculate size when renaming (needs detection)
	bytes_per_tick = shutil_g.BLOCK_SIZE
	size = max(1, self._calculate_size(bytes_per_tick))
	size_str = " (" + human_readable(self._calculate_size(1)) + ")"
	done = 0

	self.description = "copying: " + self.one_file.path + size_str

	fobj = self.copy_buffer[0]
	if os.path.isdir(fobj.path) and not os.path.islink(fobj.path):
	    n = 0
	    for n in shutil_g.copytree(
		    src=fobj.path,
		    dst=os.path.join(self.original_path, fobj.basename),
		    symlinks=True,
		    overwrite=self.overwrite,
	    ):
		self.percent = ((done + n) / size) * 100.
		yield
	    done += n
	else:
	    n = 0
	    for n in shutil_g.copy2(fobj.path, self.original_path,
				    symlinks=True, overwrite=self.overwrite):
		self.percent = ((done + n) / size) * 100.
		yield
	    done += n

	cwd = self.fm.get_directory(self.original_path)
	cwd.load_content()
Esempio n. 6
0
    def infostring(self, fobj, metadata):

        if fobj.is_directory:
            dir_size = subprocess.getoutput('du -sh "{}"'.format(
                fobj.path)).split("\t")[0]
            return dir_size
        else:
            return human_readable(fobj.size)
Esempio n. 7
0
 def generate(self):
     from ranger.ext import shutil_generatorized as shutil_g
     if self.copy_buffer:
         # TODO: Don't calculate size when renaming (needs detection)
         bytes_per_tick = shutil_g.BLOCK_SIZE
         size = max(1, self._calculate_size(bytes_per_tick))
         size_str = " (" + human_readable(self._calculate_size(1)) + ")"
         done = 0
         if self.do_cut:
             self.original_copy_buffer.clear()
             if len(self.copy_buffer) == 1:
                 self.description = "moving: " + self.one_file.path + size_str
             else:
                 self.description = "moving files from: " + self.one_file.dirname + size_str
             for f in self.copy_buffer:
                 for tf in self.fm.tags.tags:
                     if tf == f.path or str(tf).startswith(f.path):
                         tag = self.fm.tags.tags[tf]
                         self.fm.tags.remove(tf)
                         self.fm.tags.tags[tf.replace(
                             f.path,
                             self.original_path + '/' + f.basename)] = tag
                         self.fm.tags.dump()
                 d = 0
                 for d in shutil_g.move(src=f.path,
                                        dst=self.original_path,
                                        overwrite=self.overwrite):
                     self.percent = float(done + d) / size * 100.
                     yield
                 done += d
         else:
             if len(self.copy_buffer) == 1:
                 self.description = "copying: " + self.one_file.path + size_str
             else:
                 self.description = "copying files from: " + self.one_file.dirname + size_str
             for f in self.copy_buffer:
                 if os.path.isdir(f.path) and not os.path.islink(f.path):
                     d = 0
                     for d in shutil_g.copytree(src=f.path,
                                                dst=os.path.join(
                                                    self.original_path,
                                                    f.basename),
                                                symlinks=True,
                                                overwrite=self.overwrite):
                         self.percent = float(done + d) / size * 100.
                         yield
                     done += d
                 else:
                     d = 0
                     for d in shutil_g.copy2(f.path,
                                             self.original_path,
                                             symlinks=True,
                                             overwrite=self.overwrite):
                         self.percent = float(done + d) / size * 100.
                         yield
                     done += d
         cwd = self.fm.get_directory(self.original_path)
         cwd.load_content()
Esempio n. 8
0
    def generate(self):
        if not self.copy_buffer:
            return

        from ranger.ext import shutil_generatorized as shutil_g
        # TODO: Don't calculate size when renaming (needs detection)
        bytes_per_tick = shutil_g.BLOCK_SIZE
        size = max(1, self._calculate_size(bytes_per_tick))
        size_str = " (" + human_readable(self._calculate_size(1)) + ")"
        done = 0
        if self.do_cut:
            self.original_copy_buffer.clear()
            if len(self.copy_buffer) == 1:
                self.description = "moving: " + self.one_file.path + size_str
            else:
                self.description = "moving files from: " + self.one_file.dirname + size_str
            for fobj in self.copy_buffer:
                for path in self.fm.tags.tags:
                    if path == fobj.path or str(path).startswith(fobj.path):
                        tag = self.fm.tags.tags[path]
                        self.fm.tags.remove(path)
                        self.fm.tags.tags[
                            path.replace(fobj.path, path.join(self.original_path, fobj.basename))
                        ] = tag
                        self.fm.tags.dump()
                n = 0
                for n in shutil_g.move(src=fobj.path, dst=self.original_path,
                                       overwrite=self.overwrite):
                    self.percent = ((done + n) / size) * 100.
                    yield
                done += n
        else:
            if len(self.copy_buffer) == 1:
                self.description = "copying: " + self.one_file.path + size_str
            else:
                self.description = "copying files from: " + self.one_file.dirname + size_str
            for fobj in self.copy_buffer:
                if os.path.isdir(fobj.path) and not os.path.islink(fobj.path):
                    n = 0
                    for n in shutil_g.copytree(
                            src=fobj.path,
                            dst=os.path.join(self.original_path, fobj.basename),
                            symlinks=True,
                            overwrite=self.overwrite,
                    ):
                        self.percent = ((done + n) / size) * 100.
                        yield
                    done += n
                else:
                    n = 0
                    for n in shutil_g.copy2(fobj.path, self.original_path,
                                            symlinks=True, overwrite=self.overwrite):
                        self.percent = ((done + n) / size) * 100.
                        yield
                    done += n
        cwd = self.fm.get_directory(self.original_path)
        cwd.load_content()
Esempio n. 9
0
 def generate(self):
     from ranger.ext import shutil_generatorized as shutil_g
     if self.copy_buffer:
         # TODO: Don't calculate size when renaming (needs detection)
         bytes_per_tick = shutil_g.BLOCK_SIZE
         size = max(1, self._calculate_size(bytes_per_tick))
         size_str = " (" + human_readable(self._calculate_size(1)) + ")"
         done = 0
         if self.do_cut:
             self.original_copy_buffer.clear()
             if len(self.copy_buffer) == 1:
                 self.description = "moving: " + self.one_file.path + size_str
             else:
                 self.description = "moving files from: " + self.one_file.dirname + size_str
             for f in self.copy_buffer:
                 for tf in self.fm.tags.tags:
                     if tf == f.path or str(tf).startswith(f.path):
                         tag = self.fm.tags.tags[tf]
                         self.fm.tags.remove(tf)
                         self.fm.tags.tags[tf.replace(f.path, self.original_path
                                 + '/' + f.basename)] = tag
                         self.fm.tags.dump()
                 d = 0
                 for d in shutil_g.move(src=f.path,
                         dst=self.original_path,
                         overwrite=self.overwrite):
                     self.percent = float(done + d) / size * 100.
                     yield
                 done += d
         else:
             if len(self.copy_buffer) == 1:
                 self.description = "copying: " + self.one_file.path + size_str
             else:
                 self.description = "copying files from: " + self.one_file.dirname + size_str
             for f in self.copy_buffer:
                 if os.path.isdir(f.path) and not os.path.islink(f.path):
                     d = 0
                     for d in shutil_g.copytree(src=f.path,
                             dst=os.path.join(self.original_path, f.basename),
                             symlinks=True,
                             overwrite=self.overwrite):
                         self.percent = float(done + d) / size * 100.
                         yield
                     done += d
                 else:
                     d = 0
                     for d in shutil_g.copy2(f.path, self.original_path,
                             symlinks=True,
                             overwrite=self.overwrite):
                         self.percent = float(done + d) / size * 100.
                         yield
                     done += d
         cwd = self.fm.get_directory(self.original_path)
         cwd.load_content()
Esempio n. 10
0
 def infostring(self, fobj, metadata):
     if fobj.stat is None:
         return '?'
     size = human_readable(fobj.size)
     file_date = datetime.fromtimestamp(fobj.stat.st_mtime)
     time_diff = datetime.now().date() - file_date.date()
     if time_diff.days > 364:
         return "%s %11s" % (size, file_date.strftime("%-d %b %Y"))
     if time_diff.days > 6:
         return "%s %11s" % (size, file_date.strftime("%-d %b"))
     elif time_diff.days >= 1:
         return "%s %11s" % (size, file_date.strftime("%a"))
     else:
         return "%s %11s" % (size, file_date.strftime("%H:%M"))
Esempio n. 11
0
    def generate(self):
        if not self.copy_buffer or len(self.copy_buffer) > 1:
            return

        from ranger.ext import shutil_generatorized as shutil_g
        # TODO: Don't calculate size when renaming (needs detection)
        bytes_per_tick = shutil_g.BLOCK_SIZE
        size = max(1, self._calculate_size(bytes_per_tick))
        size_str = " (" + human_readable(self._calculate_size(1)) + ")"
        done = 0

        self.description = "copying: " + self.one_file.path + size_str

        fobj = self.copy_buffer[0]
        if os.path.isdir(fobj.path) and not os.path.islink(fobj.path):
            n = 0
            for n in shutil_g.copytree(
                    src=fobj.path,
                    dst=os.path.join(self.original_path, fobj.basename),
                    symlinks=True,
                    overwrite=self.overwrite,
            ):
                self.percent = ((done + n) / size) * 100.
                yield
            done += n
        else:
            n = 0
            for n in shutil_g.copy2(fobj.path,
                                    self.original_path,
                                    symlinks=True,
                                    overwrite=self.overwrite):
                self.percent = ((done + n) / size) * 100.
                yield
            done += n

        cwd = self.fm.get_directory(self.original_path)
        cwd.load_content()
Esempio n. 12
0
    def load_bit_by_bit(self):
        """An iterator that loads a part on every next() call

        Returns a generator which load a part of the directory
        in each iteration.
        """

        self.loading = True
        self.percent = 0
        self.load_if_outdated()

        try:
            if self.runnable:
                yield
                mypath = self.path

                self.mount_path = mount_path(mypath)

                filelist = os.listdir(mypath)

                if self._cumulative_size_calculated:
                    # If self.content_loaded is true, this is not the first
                    # time loading.  So I can't really be sure if the
                    # size has changed and I'll add a "?".
                    if self.content_loaded:
                        if self.fm.settings.autoupdate_cumulative_size:
                            self.look_up_cumulative_size()
                        else:
                            self.infostring = ' %s' % human_readable(
                                self.size, separator='? ')
                    else:
                        self.infostring = ' %s' % human_readable(self.size)
                else:
                    self.size = len(filelist)
                    self.infostring = ' %d' % self.size
                if self.is_link:
                    self.infostring = '->' + self.infostring

                filenames = [mypath + (mypath == '/' and fname or '/' + fname)
                        for fname in filelist]
                yield

                self.load_content_mtime = os.stat(mypath).st_mtime

                marked_paths = [obj.path for obj in self.marked_items]

                files = []
                disk_usage = 0

                if self.settings.vcs_aware:
                    self.has_vcschild = False
                    self.load_vcs(None)

                for name in filenames:
                    try:
                        file_lstat = os_lstat(name)
                        if file_lstat.st_mode & 0o170000 == 0o120000:
                            file_stat = os_stat(name)
                        else:
                            file_stat = file_lstat
                        stats = (file_stat, file_lstat)
                        is_a_dir = file_stat.st_mode & 0o170000 == 0o040000
                    except:
                        stats = None
                        is_a_dir = False
                    if is_a_dir:
                        try:
                            item = self.fm.get_directory(name)
                            item.load_if_outdated()
                        except:
                            item = Directory(name, preload=stats,
                                    path_is_abs=True)
                            item.load()
                    else:
                        item = File(name, preload=stats, path_is_abs=True)
                        item.load()
                        disk_usage += item.size

                    # Load vcs data
                    if self.settings.vcs_aware:
                        item.load_vcs(self)
                        if item.vcs_enabled:
                            self.has_vcschild = True

                    files.append(item)
                    self.percent = 100 * len(files) // len(filenames)
                    yield
                self.disk_usage = disk_usage
                self.vcs_outdated = False

                self.filenames = filenames
                self.files_all = files

                self._clear_marked_items()
                for item in self.files_all:
                    if item.path in marked_paths:
                        item._mark(True)
                        self.marked_items.append(item)
                    else:
                        item._mark(False)

                self.sort()

                if files:
                    if self.pointed_obj is not None:
                        self.sync_index()
                    else:
                        self.move(to=0)
            else:
                self.filenames = None
                self.files_all = None
                self.files = None

            self.cycle_list = None
            self.content_loaded = True
            self.last_update_time = time()
            self.correct_pointer()

        finally:
            self.loading = False
            self.fm.signal_emit("finished_loading_dir", directory=self)
Esempio n. 13
0
    def load(self):  # pylint: disable=too-many-statements
        """Loads information about the directory itself.

        reads useful information about the filesystem-object from the
        filesystem and caches it for later use
        """

        self.loaded = True
        if self.settings.freeze_files:
            return

        self.display_data = {}
        self.fm.update_preview(self.path)

        # Get the stat object, either from preload or from [l]stat
        self.permissions = None
        new_stat = None
        path = self.path
        self.is_link = False
        if self.preload:
            new_stat = self.preload[1]
            self.is_link = new_stat.st_mode & 0o170000 == 0o120000
            if self.is_link:
                new_stat = self.preload[0]
            self.preload = None
            self.exists = bool(new_stat)
        else:
            try:
                new_stat = lstat(path)
                self.is_link = new_stat.st_mode & 0o170000 == 0o120000
                if self.is_link:
                    new_stat = stat(path)
                self.exists = True
            except OSError:
                self.exists = False

        # Set some attributes

        self.accessible = bool(new_stat)
        mode = new_stat.st_mode if new_stat else 0

        fmt = mode & 0o170000
        if fmt in (0o020000, 0o060000):  # stat.S_IFCHR/BLK
            self.is_device = True
            self.size = 0
            self.infostring = 'dev'
        elif fmt == 0o010000:  # stat.S_IFIFO
            self.is_fifo = True
            self.size = 0
            self.infostring = 'fifo'
        elif fmt == 0o140000:  # stat.S_IFSOCK
            self.is_socket = True
            self.size = 0
            self.infostring = 'sock'
        elif self.is_file:
            if new_stat:
                self.size = new_stat.st_size
                self.infostring = ' ' + human_readable(self.size)
            else:
                self.size = 0
                self.infostring = '?'
        if self.is_link and not self.is_directory:
            self.infostring = '-> ' + readlink(
                self.path) + ' ' + self.infostring

        self.stat = new_stat
        self.last_load_time = time()
Esempio n. 14
0
    def _get_right_part(self, bar):  # pylint: disable=too-many-branches,too-many-statements
        right = bar.right
        if self.column is None:
            return

        target = self.column.target
        if target is None \
                or not target.accessible \
                or (target.is_directory and target.files is None):
            return

        pos = target.scroll_begin
        max_pos = len(target) - self.column.hei
        base = 'scroll'

        right.add(" ", "space")

        if self.fm.thisdir.flat:
            right.add("flat=", base, 'flat')
            right.add(str(self.fm.thisdir.flat), base, 'flat')
            right.add(", ", "space")

        if self.fm.thisdir.narrow_filter:
            right.add("narrowed")
            right.add(", ", "space")

        if self.fm.thisdir.filter:
            right.add("f=`", base, 'filter')
            right.add(self.fm.thisdir.filter.pattern, base, 'filter')
            right.add("', ", "space")

        if target.marked_items:
            if len(target.marked_items) == target.size:
                right.add(human_readable(target.disk_usage, separator=''))
            else:
                sumsize = sum(f.size for f in target.marked_items
                              if not f.is_directory or f.cumulative_size_calculated)
                right.add(human_readable(sumsize, separator=''))
            right.add("/" + str(len(target.marked_items)))
        else:
            right.add(human_readable(target.disk_usage, separator='') + " sum")
            if self.settings.display_free_space_in_status_bar:
                try:
                    free = get_free_space(target.path)
                except OSError:
                    pass
                else:
                    right.add(", ", "space")
                    right.add(human_readable(free, separator='') + " free")
        right.add("  ", "space")

        if target.marked_items:
            # Indicate that there are marked files. Useful if you scroll
            # away and don't see them anymore.
            right.add('Mrk', base, 'marked')
        elif target.files:
            right.add(str(target.pointer + 1) + '/' + str(len(target.files)) + '  ', base)
            if max_pos <= 0:
                right.add('All', base, 'all')
            elif pos == 0:
                right.add('Top', base, 'top')
            elif pos >= max_pos:
                right.add('Bot', base, 'bot')
            else:
                right.add('{0:0.0%}'.format((pos / max_pos)),
                          base, 'percentage')
        else:
            right.add('0/0  All', base, 'all')

        if self.settings.freeze_files:
            # Indicate that files are frozen and will not be loaded
            right.add("  ", "space")
            right.add('FROZEN', base, 'frozen')
Esempio n. 15
0
 def infostring(self, file, metadata):
     ctime=strftime(self.timeformat, localtime(file.stat.st_ctime))
     size = human_readable(file.size, separator='')
     return "%s %s %s %s %s" % (file.get_permission_string(),
             file.user, file.group, size, ctime)
Esempio n. 16
0
    def _get_right_part(self, bar):  # pylint: disable=too-many-branches,too-many-statements
        right = bar.right
        if self.column is None:
            return

        target = self.column.target
        if target is None \
                or not target.accessible \
                or (target.is_directory and target.files is None):
            return

        pos = target.scroll_begin
        max_pos = len(target) - self.column.hei
        base = 'scroll'

        right.add(" ", "space")

        if self.fm.thisdir.flat:
            right.add("flat=", base, 'flat')
            right.add(str(self.fm.thisdir.flat), base, 'flat')
            right.add(", ", "space")

        if self.fm.thisdir.narrow_filter:
            right.add("narrowed")
            right.add(", ", "space")

        if self.fm.thisdir.filter:
            right.add("f=`", base, 'filter')
            right.add(self.fm.thisdir.filter.pattern, base, 'filter')
            right.add("', ", "space")

        if target.marked_items:
            if len(target.marked_items) == target.size:
                right.add(human_readable(target.disk_usage, separator=''))
            else:
                sumsize = sum(
                    f.size for f in target.marked_items
                    if not f.is_directory or f.cumulative_size_calculated)
                right.add(human_readable(sumsize, separator=''))
            right.add("/" + str(len(target.marked_items)))
        else:
            right.add(human_readable(target.disk_usage, separator='') + " sum")
            if self.settings.display_free_space_in_status_bar:
                try:
                    free = get_free_space(target.mount_path)
                except OSError:
                    pass
                else:
                    right.add(", ", "space")
                    right.add(human_readable(free, separator='') + " free")
        right.add("  ", "space")

        if target.marked_items:
            # Indicate that there are marked files. Useful if you scroll
            # away and don't see them anymore.
            right.add('Mrk', base, 'marked')
        elif target.files:
            right.add(
                str(target.pointer + 1) + '/' + str(len(target.files)) + '  ',
                base)
            if max_pos <= 0:
                right.add('All', base, 'all')
            elif pos == 0:
                right.add('Top', base, 'top')
            elif pos >= max_pos:
                right.add('Bot', base, 'bot')
            else:
                right.add('{0:0.0%}'.format((pos / max_pos)), base,
                          'percentage')
        else:
            right.add('0/0  All', base, 'all')

        if self.settings.freeze_files:
            # Indicate that files are frozen and will not be loaded
            right.add("  ", "space")
            right.add('FROZEN', base, 'frozen')
Esempio n. 17
0
 def infostring(self, fobj, metadata):
     if fobj.stat is None:
         return '?'
     return "%s %s" % (human_readable(
         fobj.size), datetime.fromtimestamp(
             fobj.stat.st_mtime).strftime("%Y-%m-%d %H:%M"))
Esempio n. 18
0
	def load(self):
		"""
		reads useful information about the filesystem-object from the
		filesystem and caches it for later use
		"""

		self.loaded = True

		# Get the stat object, either from preload or from [l]stat
		new_stat = None
		path = self.path
		is_link = False
		if self.preload:
			new_stat = self.preload[1]
			is_link = new_stat.st_mode & 0o170000 == 0o120000
			if is_link:
				new_stat = self.preload[0]
			self.preload = None
			self.exists = True if new_stat else False
		else:
			try:
				new_stat = lstat(path)
				is_link = new_stat.st_mode & 0o170000 == 0o120000
				if is_link:
					new_stat = stat(path)
				self.exists = True
			except:
				self.exists = False

		# Set some attributes

		self.accessible = True if new_stat else False
		mode = new_stat.st_mode if new_stat else 0

		format = mode & 0o170000
		if format == 0o020000 or format == 0o060000:  # stat.S_IFCHR/BLK
			self.is_device = True
			self.size = 0
			self.infostring = 'dev'
		elif format == 0o010000:  # stat.S_IFIFO
			self.is_fifo = True
			self.size = 0
			self.infostring = 'fifo'
		elif format == 0o140000:  # stat.S_IFSOCK
			self.is_socket = True
			self.size = 0
			self.infostring = 'sock'
		elif self.is_file:
			if new_stat:
				self.size = new_stat.st_size
				self.infostring = ' ' + human_readable(self.size)
			else:
				self.size = 0
				self.infostring = '?'
		elif self.is_directory:
			try:
				self.size = len(listdir(path))  # bite me
			except OSError:
				self.size = 0
				self.infostring = '?'
				self.accessible = False
			else:
				self.infostring = ' %d' % self.size
				self.accessible = True
				self.runnable = True
		if is_link:
			self.infostring = '->' + self.infostring
			self.is_link = True

		self.stat = new_stat
Esempio n. 19
0
 def look_up_cumulative_size(self):
     self.cumulative_size_calculated = True
     self.size = self._get_cumulative_size()
     self.infostring = ('-> ' if self.is_link else ' ') + human_readable(
         self.size)
Esempio n. 20
0
 def infostring(self, file, metadata):
     return "%s %s" % (human_readable(file.size),
                       datetime.fromtimestamp(file.stat.st_mtime).strftime("%Y-%m-%d %H:%M"))
Esempio n. 21
0
 def look_up_cumulative_size(self):
     self.cumulative_size_calculated = True
     self.size = self._get_cumulative_size()
     self.infostring = ('-> ' if self.is_link else ' ') + human_readable(self.size)
Esempio n. 22
0
 def infostring(self, fobj, metadata):
     if fobj.stat is None:
         return '?'
     return "%s %s" % (human_readable(fobj.size),
                       datetime.fromtimestamp(fobj.stat.st_mtime).strftime("%Y-%m-%d %H:%M"))
Esempio n. 23
0
 def infostring(self, fobj, metadata):
     if fobj.stat is None:
         return '?'
     humanSize = human_readable(fobj.size)
     return "%s" % humanSize
Esempio n. 24
0
    def _get_right_part(self, bar):
        right = bar.right

	# This chunk is to get file size working on the right side.
        if self.column is not None and self.column.target is not None\
                and self.column.target.is_directory:
            target = self.column.target.pointed_obj
        else:
            directory = self.fm.thistab.at_level(0)
            if directory:
                target = directory.pointed_obj
            else:
                return
        try:
            stat = target.stat
        except:
            return
        if stat is None:
            return
        if self.fm.mode != 'normal':
            perms = '--%s--' % self.fm.mode.upper()
        else:
            perms = target.get_permission_string()
        how = getuid() == stat.st_uid and 'good' or 'bad'
        if target.is_link:
            how = target.exists and 'good' or 'bad'
            try:
                dest = readlink(target.path)
            except:
                dest = '?'
            right.add(' -> ' + dest, 'link', how)
        else:
            if self.settings.display_size_in_status_bar and target.infostring:
                right.add("  " + target.infostring.replace(" ", ""))
                right.add(" »", "space")

        if self.column is None:
            return

        target = self.column.target
        if target is None \
                or not target.accessible \
                or (target.is_directory and target.files is None):
            return

        pos = target.scroll_begin
        max_pos = len(target) - self.column.hei
        base = 'scroll'

        if self.fm.thisdir.filter:
            right.add(" f=`", base, 'filter')
            right.add(self.fm.thisdir.filter.pattern, base, 'filter')
            right.add("', ", "space")

        if target.marked_items:
            if len(target.marked_items) == len(target.files):
                #right.add(human_readable(target.disk_usage, separator=''))
                right.add(" " + human_readable(target.disk_usage, separator=''))
            else:
                sumsize = sum(f.size for f in target.marked_items if not
                        f.is_directory or f._cumulative_size_calculated)
                #right.add(human_readable(sumsize, separator=''))
                right.add(" " + human_readable(sumsize, separator=''))
            right.add("/" + str(len(target.marked_items)))
        else:
            #right.add(human_readable(target.disk_usage, separator='') + " sum")
            right.add(" " + human_readable(target.disk_usage, separator=''))
            try:
                free = get_free_space(target.mount_path)
            except OSError:
                pass
            else:
                #right.add(", ", "space")
                right.add(" » ", "space")
                #right.add(human_readable(free, separator='') + " free")
                right.add(human_readable(free, separator=''))
        right.add("  ", "space")

        if target.marked_items:
            # Indicate that there are marked files. Useful if you scroll
            # away and don't see them anymore.
            right.add('Mrk', base, 'marked')
Esempio n. 25
0
    def load_bit_by_bit(self):
        """An iterator that loads a part on every next() call

        Returns a generator which load a part of the directory
        in each iteration.
        """

        self.loading = True
        self.percent = 0
        self.load_if_outdated()

        basename_is_rel_to = self.path if self.flat else None

        try:  # pylint: disable=too-many-nested-blocks
            if self.runnable:
                yield
                mypath = self.path

                self.mount_path = mount_path(mypath)

                if self.flat:
                    filelist = []
                    for dirpath, dirnames, filenames in walklevel(mypath, self.flat):
                        dirlist = [
                            os.path.join("/", dirpath, d)
                            for d in dirnames
                            if self.flat == -1 or
                            (dirpath.count(os.path.sep) - mypath.count(os.path.sep)) <= self.flat
                        ]
                        filelist += dirlist
                        filelist += [os.path.join("/", dirpath, f) for f in filenames]
                    filenames = filelist
                    self.load_content_mtime = mtimelevel(mypath, self.flat)
                else:
                    filelist = os.listdir(mypath)
                    filenames = [mypath + (mypath == '/' and fname or '/' + fname)
                                 for fname in filelist]
                    self.load_content_mtime = os.stat(mypath).st_mtime

                if self.cumulative_size_calculated:
                    # If self.content_loaded is true, this is not the first
                    # time loading.  So I can't really be sure if the
                    # size has changed and I'll add a "?".
                    if self.content_loaded:
                        if self.fm.settings.autoupdate_cumulative_size:
                            self.look_up_cumulative_size()
                        else:
                            self.infostring = ' %s' % human_readable(
                                self.size, separator='? ')
                    else:
                        self.infostring = ' %s' % human_readable(self.size)
                else:
                    self.size = len(filelist)
                    self.infostring = ' %d' % self.size
                if self.is_link:
                    self.infostring = '->' + self.infostring

                yield

                marked_paths = [obj.path for obj in self.marked_items]

                files = []
                disk_usage = 0

                has_vcschild = False
                for name in filenames:
                    try:
                        file_lstat = os_lstat(name)
                        if file_lstat.st_mode & 0o170000 == 0o120000:
                            file_stat = os_stat(name)
                        else:
                            file_stat = file_lstat
                    except OSError:
                        file_lstat = None
                        file_stat = None
                    if file_lstat and file_stat:
                        stats = (file_stat, file_lstat)
                        is_a_dir = file_stat.st_mode & 0o170000 == 0o040000
                    else:
                        stats = None
                        is_a_dir = False

                    if is_a_dir:
                        item = self.fm.get_directory(name, preload=stats, path_is_abs=True,
                                                     basename_is_rel_to=basename_is_rel_to)
                        item.load_if_outdated()
                        if self.flat:
                            item.relative_path = os.path.relpath(item.path, self.path)
                        else:
                            item.relative_path = item.basename
                        item.relative_path_lower = item.relative_path.lower()
                        if item.vcs and item.vcs.track:
                            if item.vcs.is_root_pointer:
                                has_vcschild = True
                            else:
                                item.vcsstatus = \
                                    item.vcs.rootvcs.status_subpath(  # pylint: disable=no-member
                                        os.path.join(self.realpath, item.basename),
                                        is_directory=True,
                                    )
                    else:
                        item = File(name, preload=stats, path_is_abs=True,
                                    basename_is_rel_to=basename_is_rel_to)
                        item.load()
                        disk_usage += item.size
                        if self.vcs and self.vcs.track:
                            item.vcsstatus = \
                                self.vcs.rootvcs.status_subpath(  # pylint: disable=no-member
                                    os.path.join(self.realpath, item.basename))

                    files.append(item)
                    self.percent = 100 * len(files) // len(filenames)
                    yield
                self.has_vcschild = has_vcschild
                self.disk_usage = disk_usage

                self.filenames = filenames
                self.files_all = files

                self._clear_marked_items()
                for item in self.files_all:
                    if item.path in marked_paths:
                        item.mark_set(True)
                        self.marked_items.append(item)
                    else:
                        item.mark_set(False)

                self.sort()

                if files:
                    if self.pointed_obj is not None:
                        self.sync_index()
                    else:
                        self.move(to=0)
            else:
                self.filenames = None
                self.files_all = None
                self.files = None

            self.cycle_list = None
            self.content_loaded = True
            self.last_update_time = time()
            self.correct_pointer()

        finally:
            self.loading = False
            self.fm.signal_emit("finished_loading_dir", directory=self)
            if self.vcs:
                self.fm.ui.vcsthread.process(self)
Esempio n. 26
0
 def infostring(self, fobj, metadata):
     if fobj.stat is None:
         return '?'
     size = human_readable(fobj.size)
     return "%s %11s" % (size, human_readable_time(fobj.stat.st_mtime))
Esempio n. 27
0
    def load_bit_by_bit(self):
        """An iterator that loads a part on every next() call

        Returns a generator which load a part of the directory
        in each iteration.
        """

        self.loading = True
        self.percent = 0
        self.load_if_outdated()

        basename_is_rel_to = self.path if self.flat else None

        try:
            if self.runnable:
                yield
                mypath = self.path

                self.mount_path = mount_path(mypath)

                if self.flat:
                    filelist = []
                    for dirpath, dirnames, filenames in walklevel(
                            mypath, self.flat):
                        dirlist = [
                            os.path.join("/", dirpath, d) for d in dirnames
                            if self.flat == -1 or dirpath.count(os.path.sep) -
                            mypath.count(os.path.sep) <= self.flat
                        ]
                        filelist += dirlist
                        filelist += [
                            os.path.join("/", dirpath, f) for f in filenames
                        ]
                    filenames = filelist
                    self.load_content_mtime = mtimelevel(mypath, self.flat)
                else:
                    filelist = os.listdir(mypath)
                    filenames = [
                        mypath + (mypath == '/' and fname or '/' + fname)
                        for fname in filelist
                    ]
                    self.load_content_mtime = os.stat(mypath).st_mtime

                if self._cumulative_size_calculated:
                    # If self.content_loaded is true, this is not the first
                    # time loading.  So I can't really be sure if the
                    # size has changed and I'll add a "?".
                    if self.content_loaded:
                        if self.fm.settings.autoupdate_cumulative_size:
                            self.look_up_cumulative_size()
                        else:
                            self.infostring = ' %s' % human_readable(
                                self.size, separator='? ')
                    else:
                        self.infostring = ' %s' % human_readable(self.size)
                else:
                    self.size = len(filelist)
                    self.infostring = ' %d' % self.size
                if self.is_link:
                    self.infostring = '->' + self.infostring

                yield

                marked_paths = [obj.path for obj in self.marked_items]

                files = []
                disk_usage = 0

                if self.settings.vcs_aware:
                    self.has_vcschild = False
                    self.load_vcs(None)

                for name in filenames:
                    try:
                        file_lstat = os_lstat(name)
                        if file_lstat.st_mode & 0o170000 == 0o120000:
                            file_stat = os_stat(name)
                        else:
                            file_stat = file_lstat
                        stats = (file_stat, file_lstat)
                        is_a_dir = file_stat.st_mode & 0o170000 == 0o040000
                    except:
                        stats = None
                        is_a_dir = False
                    if is_a_dir:
                        if self.flat:
                            item = Directory(
                                name,
                                preload=stats,
                                path_is_abs=True,
                                basename_is_rel_to=basename_is_rel_to)
                            item.load()
                        else:
                            try:
                                item = self.fm.get_directory(name)
                                item.load_if_outdated()
                            except:
                                item = Directory(name,
                                                 preload=stats,
                                                 path_is_abs=True)
                                item.load()
                    else:
                        item = File(name,
                                    preload=stats,
                                    path_is_abs=True,
                                    basename_is_rel_to=basename_is_rel_to)
                        item.load()
                        disk_usage += item.size

                    # Load vcs data
                    if self.settings.vcs_aware:
                        item.load_vcs(self)
                        if item.vcs_enabled:
                            self.has_vcschild = True

                    files.append(item)
                    self.percent = 100 * len(files) // len(filenames)
                    yield
                self.disk_usage = disk_usage
                self.vcs_outdated = False

                self.filenames = filenames
                self.files_all = files

                self._clear_marked_items()
                for item in self.files_all:
                    if item.path in marked_paths:
                        item._mark(True)
                        self.marked_items.append(item)
                    else:
                        item._mark(False)

                self.sort()

                if files:
                    if self.pointed_obj is not None:
                        self.sync_index()
                    else:
                        self.move(to=0)
            else:
                self.filenames = None
                self.files_all = None
                self.files = None

            self.cycle_list = None
            self.content_loaded = True
            self.last_update_time = time()
            self.correct_pointer()

        finally:
            self.loading = False
            self.fm.signal_emit("finished_loading_dir", directory=self)
Esempio n. 28
0
	def load_bit_by_bit(self):
		"""
		Returns a generator which load a part of the directory
		in each iteration.
		"""

		self.loading = True
		self.percent = 0
		self.load_if_outdated()

		try:
			if self.runnable:
				yield
				mypath = self.path

				self.mount_path = mount_path(mypath)

				if not self.settings.show_hidden and self.settings.hidden_filter:
					# COMPAT
					# hidden_filter used to be a regex, not a string.  If an
					# old config is used, we don't need to re.compile it.
					if hasattr(self.settings.hidden_filter, 'search'):
						hidden_filter = self.settings.hidden_filter
					else:
						hidden_filter = re.compile(self.settings.hidden_filter)
				else:
					hidden_filter = None

				filelist = os.listdir(mypath)

				if self._cumulative_size_calculated:
					# If self.content_loaded is true, this is not the first
					# time loading.  So I can't really be sure if the
					# size has changed and I'll add a "?".
					if self.content_loaded:
						if self.fm.settings.autoupdate_cumulative_size:
							self.look_up_cumulative_size()
						else:
							self.infostring = ' %s' % human_readable(
								self.size, separator='? ')
					else:
						self.infostring = ' %s' % human_readable(self.size)
				else:
					self.size = len(filelist)
					self.infostring = ' %d' % self.size
				if self.is_link:
					self.infostring = '->' + self.infostring

				filenames = [mypath + (mypath == '/' and fname or '/' + fname)\
						for fname in filelist if accept_file(
							fname, mypath, hidden_filter, self.filter)]
				yield

				self.load_content_mtime = os.stat(mypath).st_mtime

				marked_paths = [obj.path for obj in self.marked_items]

				files = []
				disk_usage = 0
				for name in filenames:
					try:
						file_lstat = os_lstat(name)
						if file_lstat.st_mode & 0o170000 == 0o120000:
							file_stat = os_stat(name)
						else:
							file_stat = file_lstat
						stats = (file_stat, file_lstat)
						is_a_dir = file_stat.st_mode & 0o170000 == 0o040000
					except:
						stats = None
						is_a_dir = False
					if is_a_dir:
						try:
							item = self.fm.get_directory(name)
							item.load_if_outdated()
						except:
							item = Directory(name, preload=stats,
									path_is_abs=True)
							item.load()
					else:
						item = File(name, preload=stats, path_is_abs=True)
						item.load()
						disk_usage += item.size
					files.append(item)
					self.percent = 100 * len(files) // len(filenames)
					yield
				self.disk_usage = disk_usage

				self.filenames = filenames
				self.files = files

				self._clear_marked_items()
				for item in self.files:
					if item.path in marked_paths:
						item._mark(True)
						self.marked_items.append(item)
					else:
						item._mark(False)

				self.sort()

				if files:
					if self.pointed_obj is not None:
						self.sync_index()
					else:
						self.move(to=0)
			else:
				self.filenames = None
				self.files = None

			self.cycle_list = None
			self.content_loaded = True
			self.last_update_time = time()
			self.correct_pointer()

		finally:
			self.loading = False
			self.fm.signal_emit("finished_loading_dir", directory=self)
Esempio n. 29
0
    def load_bit_by_bit(self):
        """An iterator that loads a part on every next() call

        Returns a generator which load a part of the directory
        in each iteration.
        """

        self.loading = True
        self.percent = 0
        self.load_if_outdated()

        basename_is_rel_to = self.path if self.flat else None

        try:  # pylint: disable=too-many-nested-blocks
            if self.runnable:
                yield
                mypath = self.path

                self.mount_path = mount_path(mypath)

                def ignore_files():
                    directory = expanduser("~")
                    files = []
                    for filename in os.listdir(directory):
                        if filename.startswith(
                                "ranger_") and filename.endswith(".txt"):
                            with open(os.path.join(directory, filename),
                                      'r') as f:
                                files += f.read().strip().split("\n")
                    return list(set(files))

                if self.flat:
                    filelist = []
                    for dirpath, dirnames, filenames in walklevel(
                            mypath, self.flat):
                        dirlist = [
                            os.path.join("/", dirpath, d) for d in dirnames
                            if self.flat == -1 or
                            (dirpath.count(os.path.sep) -
                             mypath.count(os.path.sep)) <= self.flat
                        ]
                        filelist += dirlist
                        filelist += [
                            os.path.join("/", dirpath, f) for f in filenames
                        ]
                    filenames = filelist
                    filenames = [
                        f for f in filenames if not f in ignore_files()
                    ]
                    self.load_content_mtime = mtimelevel(mypath, self.flat)
                else:
                    filelist = os.listdir(mypath)
                    filenames = [
                        mypath + (mypath == '/' and fname or '/' + fname)
                        for fname in filelist
                    ]
                    filenames = [
                        f for f in filenames if not f in ignore_files()
                    ]
                    self.load_content_mtime = os.stat(mypath).st_mtime

                if self.cumulative_size_calculated:
                    # If self.content_loaded is true, this is not the first
                    # time loading.  So I can't really be sure if the
                    # size has changed and I'll add a "?".
                    if self.content_loaded:
                        if self.fm.settings.autoupdate_cumulative_size:
                            self.look_up_cumulative_size()
                        else:
                            self.infostring = ' %s' % human_readable(
                                self.size, separator='? ')
                    else:
                        self.infostring = ' %s' % human_readable(self.size)
                else:
                    self.size = len(filelist)
                    self.infostring = ' %d' % self.size
                if self.is_link:
                    self.infostring = '->' + self.infostring

                yield

                marked_paths = [obj.path for obj in self.marked_items]

                files = []
                disk_usage = 0

                has_vcschild = False
                for name in filenames:
                    try:
                        file_lstat = os_lstat(name)
                        if file_lstat.st_mode & 0o170000 == 0o120000:
                            file_stat = os_stat(name)
                        else:
                            file_stat = file_lstat
                    except OSError:
                        file_lstat = None
                        file_stat = None
                    if file_lstat and file_stat:
                        stats = (file_stat, file_lstat)
                        is_a_dir = file_stat.st_mode & 0o170000 == 0o040000
                    else:
                        stats = None
                        is_a_dir = False

                    if is_a_dir:
                        item = self.fm.get_directory(
                            name,
                            preload=stats,
                            path_is_abs=True,
                            basename_is_rel_to=basename_is_rel_to)
                        item.load_if_outdated()
                        if self.flat:
                            item.relative_path = os.path.relpath(
                                item.path, self.path)
                        else:
                            item.relative_path = item.basename
                        item.relative_path_lower = item.relative_path.lower()
                        if item.vcs and item.vcs.track:
                            if item.vcs.is_root_pointer:
                                has_vcschild = True
                            else:
                                item.vcsstatus = \
                                    item.vcs.rootvcs.status_subpath(  # pylint: disable=no-member
                                        os.path.join(self.realpath, item.basename),
                                        is_directory=True,
                                    )
                    else:
                        item = File(name,
                                    preload=stats,
                                    path_is_abs=True,
                                    basename_is_rel_to=basename_is_rel_to)
                        item.load()
                        disk_usage += item.size
                        if self.vcs and self.vcs.track:
                            item.vcsstatus = \
                                self.vcs.rootvcs.status_subpath(  # pylint: disable=no-member
                                    os.path.join(self.realpath, item.basename))

                    files.append(item)
                    self.percent = 100 * len(files) // len(filenames)
                    yield
                self.has_vcschild = has_vcschild
                self.disk_usage = disk_usage

                self.filenames = filenames
                self.files_all = files

                self._clear_marked_items()
                for item in self.files_all:
                    if item.path in marked_paths:
                        item.mark_set(True)
                        self.marked_items.append(item)
                    else:
                        item.mark_set(False)

                self.sort()

                if files:
                    if self.pointed_obj is not None:
                        self.sync_index()
                    else:
                        self.move(to=0)
            else:
                self.filenames = None
                self.files_all = None
                self.files = None

            self.cycle_list = None
            self.content_loaded = True
            self.last_update_time = time()
            self.correct_pointer()

        finally:
            self.loading = False
            self.fm.signal_emit("finished_loading_dir", directory=self)
            if self.vcs:
                self.fm.ui.vcsthread.process(self)
Esempio n. 30
0
 def infostring(self, file, metadata):
     return "%s %s" % (human_readable(file.size),
                       datetime.fromtimestamp(file.stat.st_mtime).strftime("%Y-%m-%d %H:%M"))
Esempio n. 31
0
    def load(self):
        """Loads information about the directory itself.

        reads useful information about the filesystem-object from the
        filesystem and caches it for later use
        """

        self.display_data = {}
        self.fm.update_preview(self.path)
        self.loaded = True

        # Get the stat object, either from preload or from [l]stat
        self.permissions = None
        new_stat = None
        path = self.path
        is_link = False
        if self.preload:
            new_stat = self.preload[1]
            self.is_link = new_stat.st_mode & 0o170000 == 0o120000
            if self.is_link:
                new_stat = self.preload[0]
            self.preload = None
            self.exists = True if new_stat else False
        else:
            try:
                new_stat = lstat(path)
                self.is_link = new_stat.st_mode & 0o170000 == 0o120000
                if self.is_link:
                    new_stat = stat(path)
                self.exists = True
            except:
                self.exists = False

        # Set some attributes

        self.accessible = True if new_stat else False
        mode = new_stat.st_mode if new_stat else 0

        format = mode & 0o170000
        if format == 0o020000 or format == 0o060000:  # stat.S_IFCHR/BLK
            self.is_device = True
            self.size = 0
            self.infostring = 'dev'
        elif format == 0o010000:  # stat.S_IFIFO
            self.is_fifo = True
            self.size = 0
            self.infostring = 'fifo'
        elif format == 0o140000:  # stat.S_IFSOCK
            self.is_socket = True
            self.size = 0
            self.infostring = 'sock'
        elif self.is_file:
            if new_stat:
                self.size = new_stat.st_size
                self.infostring = ' ' + human_readable(self.size)
            else:
                self.size = 0
                self.infostring = '?'
        if self.is_link and not self.is_directory:
            self.infostring = '->' + self.infostring

        self.stat = new_stat
Esempio n. 32
0
 def infostring(self, fobj, metadata):
     if fobj.stat is None:
         return '?'
     size = human_readable(fobj.size)
     return "%s %11s" % (size, human_readable_time(fobj.stat.st_mtime))