summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2010-01-01 03:02:20 +0200
committerLars Wirzenius <liw@liw.fi>2010-01-01 03:02:20 +0200
commit37810eaf498b82c8fb54bcf22c0861ad2c370d69 (patch)
tree9c6446dcfddb4c109c2d3389aa176d2adc781058
parent769ff2d2dd5434cec535a8ff4be9a9ba3a81e4bf (diff)
downloadsummain-37810eaf498b82c8fb54bcf22c0861ad2c370d69.tar.gz
Implement formatting of st_gid.
Implement lookup of group name corresponding to st_gid. With unit tests.
-rw-r--r--summainlib.py6
-rw-r--r--summainlib_tests.py9
2 files changed, 14 insertions, 1 deletions
diff --git a/summainlib.py b/summainlib.py
index ff0bf12..4d0a89c 100644
--- a/summainlib.py
+++ b/summainlib.py
@@ -14,6 +14,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+import grp
import os
import pwd
import time
@@ -43,6 +44,8 @@ class FilesystemObject(object):
self['Size'] = '%d' % stat_result.st_size
self['Uid'] = '%d' % stat_result.st_uid
self['Username'] = self.lookup_username(stat_result.st_uid)
+ self['Gid'] = '%d' % stat_result.st_gid
+ self['Group'] = self.lookup_group(stat_result.st_gid)
def format_time(self, timestamp):
return time.strftime('%Y-%m-%d %H:%M:%S +0000',
@@ -51,6 +54,9 @@ class FilesystemObject(object):
def lookup_username(self, uid):
return pwd.getpwuid(uid).pw_name
+ def lookup_group(self, gid):
+ return grp.getgrgid(gid).gr_name
+
def hook_name(self, value):
return urllib.quote(value)
diff --git a/summainlib_tests.py b/summainlib_tests.py
index db2e6b5..b88f7b8 100644
--- a/summainlib_tests.py
+++ b/summainlib_tests.py
@@ -36,7 +36,8 @@ class FilesystemObjectTests(unittest.TestCase):
st_dev=42,
st_nlink=2,
st_size=1,
- st_uid=0)
+ st_uid=0,
+ st_gid=0)
def new(self, name):
return summainlib.FilesystemObject(name, stat_result=self.st)
@@ -72,3 +73,9 @@ class FilesystemObjectTests(unittest.TestCase):
def test_formats_username_correctly(self):
self.assertEqual(self.new('foo')['Username'], 'root')
+ def test_formats_gid_correctly(self):
+ self.assertEqual(self.new('foo')['Gid'], '0')
+
+ def test_formats_group_correctly(self):
+ self.assertEqual(self.new('foo')['Group'], 'root')
+