summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2010-01-01 02:58:25 +0200
committerLars Wirzenius <liw@liw.fi>2010-01-01 02:58:25 +0200
commit769ff2d2dd5434cec535a8ff4be9a9ba3a81e4bf (patch)
tree2eb2e4a175fb221408e3a3b9a1359b56e6aa590f
parent96f9c72e35c9a496d1ad439518e7072591b3ec92 (diff)
downloadsummain-769ff2d2dd5434cec535a8ff4be9a9ba3a81e4bf.tar.gz
Implement lookup of username corresponding to st_uid. With unit test.
-rw-r--r--summainlib.py5
-rw-r--r--summainlib_tests.py3
2 files changed, 8 insertions, 0 deletions
diff --git a/summainlib.py b/summainlib.py
index 5ce9f10..ff0bf12 100644
--- a/summainlib.py
+++ b/summainlib.py
@@ -15,6 +15,7 @@
import os
+import pwd
import time
import urllib
@@ -41,11 +42,15 @@ class FilesystemObject(object):
self['Nlink'] = '%d' % stat_result.st_nlink
self['Size'] = '%d' % stat_result.st_size
self['Uid'] = '%d' % stat_result.st_uid
+ self['Username'] = self.lookup_username(stat_result.st_uid)
def format_time(self, timestamp):
return time.strftime('%Y-%m-%d %H:%M:%S +0000',
time.gmtime(timestamp))
+ def lookup_username(self, uid):
+ return pwd.getpwuid(uid).pw_name
+
def hook_name(self, value):
return urllib.quote(value)
diff --git a/summainlib_tests.py b/summainlib_tests.py
index 7f5a9fd..db2e6b5 100644
--- a/summainlib_tests.py
+++ b/summainlib_tests.py
@@ -69,3 +69,6 @@ class FilesystemObjectTests(unittest.TestCase):
def test_formats_uid_correctly(self):
self.assertEqual(self.new('foo')['Uid'], '0')
+ def test_formats_username_correctly(self):
+ self.assertEqual(self.new('foo')['Username'], 'root')
+