[kupfer] utils: Add get_display_path_for_bytestring, from objects.FileLeaf



commit f332bd882c448b4509fb7f919b6263d95a4d424d
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Sat Aug 22 19:34:55 2009 +0200

    utils: Add get_display_path_for_bytestring, from objects.FileLeaf

 kupfer/objects.py |    8 +-------
 kupfer/utils.py   |   14 +++++++++++++-
 2 files changed, 14 insertions(+), 8 deletions(-)
---
diff --git a/kupfer/objects.py b/kupfer/objects.py
index 58a47c7..0535639 100644
--- a/kupfer/objects.py
+++ b/kupfer/objects.py
@@ -269,13 +269,7 @@ class FileLeaf (Leaf):
 		"""Format the path shorter:
 		replace homedir by ~/
 		"""
-		# Use glib filename reading to make display name out of filenames
-		# this function returns a `unicode` object
-		desc = gobject.filename_display_name(self.object)
-		homedir = path.expanduser("~/")
-		if desc.startswith(homedir) and homedir != desc:
-			desc = desc.replace(homedir, "~/", 1)
-		return desc
+		return utils.get_display_path_for_bytestring(self.object)
 
 	def get_actions(self):
 		acts = [RevealFile(), ]
diff --git a/kupfer/utils.py b/kupfer/utils.py
index 3ace778..ef7dcd0 100644
--- a/kupfer/utils.py
+++ b/kupfer/utils.py
@@ -3,6 +3,8 @@ import os
 from os import path as os_path
 import locale
 
+import gobject
+
 from kupfer import pretty
 
 def get_dirlist(folder, depth=0, include=None, exclude=None):
@@ -66,7 +68,6 @@ def locale_sort(seq, key=unicode):
 	return seq
 
 def spawn_async(argv, in_dir="."):
-	import gobject
 	pretty.print_debug(__name__, "Spawn commandline", argv, in_dir)
 	try:
 		return gobject.spawn_async (argv, working_directory=in_dir,
@@ -145,3 +146,14 @@ def get_destpath_in_directory(directory, filename, extension=None):
 		destpath = os_path.join(directory, basename)
 	return destpath
 
+def get_display_path_for_bytestring(filepath):
+	"""Return a unicode path for display for bytestring @filepath
+
+	Will use glib's filename decoding functions, and will
+	format nicely (denote home by ~/ etc)
+	"""
+	desc = gobject.filename_display_name(filepath)
+	homedir = os.path.expanduser("~/")
+	if desc.startswith(homedir) and homedir != desc:
+		desc = desc.replace(homedir, "~/", 1)
+	return desc



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]