summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2010-01-19 18:34:12 +0100
committerhut <hut@lavabit.com>2010-01-19 18:34:12 +0100
commita1274aba49793e6a48be95c2cece7d32e5d334f2 (patch)
tree3c7cd7f6d265122bc87a1f5a571902d96bc7247c
parent2d32d870e21c533872fc18cf9b93a8756b123992 (diff)
downloadranger-a1274aba49793e6a48be95c2cece7d32e5d334f2.tar.gz
done #34: display free disk space
-rw-r--r--TODO2
-rw-r--r--ranger/container/environment.py5
-rw-r--r--ranger/ext/human_readable.py6
-rw-r--r--ranger/ext/mount_path.py10
-rw-r--r--ranger/fsobject/directory.py5
-rw-r--r--ranger/gui/widgets/statusbar.py5
6 files changed, 29 insertions, 4 deletions
diff --git a/TODO b/TODO
index 1f7be5e7..d19beb47 100644
--- a/TODO
+++ b/TODO
@@ -25,7 +25,7 @@ General
    (X) #29  10/01/06  add chmod command
    (X) #30  10/01/06  add a way to create symlinks
    ( ) #32  10/01/08  place the (hidden) cursor to a meaningful position
-   ( ) #34  10/01/09  display free disk space
+   (X) #34  10/01/09  display free disk space
    ( ) #35  10/01/09  display disk usage of files in current directory
    ( ) #36  10/01/11  help coloring is terribly inefficient
    ( ) #37  10/01/13  better tab completion for OpenConsole
diff --git a/ranger/container/environment.py b/ranger/container/environment.py
index 075ecf3f..2f15694b 100644
--- a/ranger/container/environment.py
+++ b/ranger/container/environment.py
@@ -101,6 +101,11 @@ class Environment(SettingsAware):
 			obj = Directory(path)
 			self.directories[path] = obj
 			return obj
+	
+	def get_free_space(self, path):
+		from os import statvfs
+		stat = statvfs(path)
+		return stat.f_bavail * stat.f_bsize
 
 	def assign_correct_cursor_positions(self):
 		"""Assign correct cursor positions for subdirectories"""
diff --git a/ranger/ext/human_readable.py b/ranger/ext/human_readable.py
index 410138b7..ad883907 100644
--- a/ranger/ext/human_readable.py
+++ b/ranger/ext/human_readable.py
@@ -16,7 +16,7 @@ ONE_KB = 1024
 UNITS = 'BKMGTP'
 MAX_EXPONENT = len(UNITS) - 1
 
-def human_readable(byte):
+def human_readable(byte, seperator=' '):
 	import math
 
 	if not byte:
@@ -29,7 +29,7 @@ def human_readable(byte):
 		return '>9000' # off scale
 
 	if int(flt) == flt:
-		return '%.0f %s' % (flt, UNITS[exponent])
+		return '%.0f%s%s' % (flt, seperator, UNITS[exponent])
 
 	else:
-		return '%.2f %s' % (flt, UNITS[exponent])
+		return '%.2f%s%s' % (flt, seperator, UNITS[exponent])
diff --git a/ranger/ext/mount_path.py b/ranger/ext/mount_path.py
new file mode 100644
index 00000000..5758d36d
--- /dev/null
+++ b/ranger/ext/mount_path.py
@@ -0,0 +1,10 @@
+from os.path import realpath, abspath, dirname, ismount
+
+def mount_path(path):
+	"""Get the mount root of a directory"""
+	path = abspath(realpath(path))
+	while path != '/':
+		if ismount(path):
+			return path
+		path = dirname(path)
+	return '/'
diff --git a/ranger/fsobject/directory.py b/ranger/fsobject/directory.py
index 6dc3ae39..79b39f69 100644
--- a/ranger/fsobject/directory.py
+++ b/ranger/fsobject/directory.py
@@ -46,6 +46,8 @@ class Directory(FileSystemObject, Accumulator, SettingsAware):
 	scroll_begin = 0
 	scroll_offset = 0
 
+	mount_path = '/'
+
 	last_update_time = -1
 	load_content_mtime = -1
 
@@ -138,6 +140,7 @@ class Directory(FileSystemObject, Accumulator, SettingsAware):
 		# log("generating loader for " + self.path + "(" + str(id(self)) + ")")
 		from os.path import join, isdir, basename
 		from os import listdir
+		import ranger.ext.mount_path
 
 		self.loading = True
 		self.load_if_outdated()
@@ -145,6 +148,8 @@ class Directory(FileSystemObject, Accumulator, SettingsAware):
 		try:
 			if self.exists and self.runnable:
 				yield
+				self.mount_path = ranger.ext.mount_path.mount_path(self.path)
+
 				filenames = []
 				for fname in listdir(self.path):
 					if not self.settings.show_hidden:
diff --git a/ranger/gui/widgets/statusbar.py b/ranger/gui/widgets/statusbar.py
index 0fcab000..a1fc4973 100644
--- a/ranger/gui/widgets/statusbar.py
+++ b/ranger/gui/widgets/statusbar.py
@@ -25,6 +25,7 @@ from grp import getgrgid
 from os import getuid
 from time import strftime, localtime
 
+from ranger.ext.human_readable import human_readable
 from . import Widget
 from ranger.gui.bar import Bar
 
@@ -198,6 +199,10 @@ class StatusBar(Widget):
 		max_pos = len(target) - self.column.hei
 		base = 'scroll'
 
+		right.add(human_readable(self.env.get_free_space(target.mount_path),
+			seperator=''))
+		right.add(" ", "space")
+
 		if target.marked_items:
 			# Indicate that there are marked files. Useful if you scroll
 			# away and don't see them anymore.