def test_gidFromGroupnameString(self): """ When L{gidFromString} is called with a base-ten string representation of an integer, it returns the integer. """ grent = grp.getgrgid(os.getgid()) self.assertEqual(util.gidFromString(grent.gr_name), grent.gr_gid)
def getid(uid, gid): """ Convert one or both of a string representation of a UID and GID into integer form. On platforms where L{pwd} and L{grp} is available, user and group names can be converted. @type uid: C{str} or C{NoneType} @param uid: A string giving the base-ten representation of a UID or the name of a user which can be converted to a UID via L{pwd.getpwnam}, or None if no UID value is to be obtained. @type gid: C{str} or C{NoneType} @param uid: A string giving the base-ten representation of a GID or the name of a group which can be converted to a GID via L{grp.getgrnam}, or None if no UID value is to be obtained. @return: A two-tuple giving integer UID and GID information for whichever (or both) parameter is provided with a non-C{None} value. @raise ValueError: If a user or group name is supplied and L{pwd} or L{grp} is not available. """ if uid is not None: uid = uidFromString(uid) if gid is not None: gid = gidFromString(gid) return (uid, gid)
def switchUID(uid, gid): """ Switch uid and gid to what the user has specified on the command line. """ if uid: uid = util.uidFromString(uid) if gid: gid = util.gidFromString(gid) util.switchUID(uid, gid)
def test_gidFromNumericString(self): """ When L{gidFromString} is called with a base-ten string representation of an integer, it returns the integer. """ self.assertEqual(util.gidFromString("100"), 100)