[sabayon] Applying profiles to members of a group



Hi all,

I attached the first iteration of a small script that applies a
profile to the members of a given group.
You can run it like

sabayon4grps.py <groupname> <profilename>

I've also pasted the code into http://live.gnome.org/PythonSabayon

Cheers,
-sdg-


--
Sayamindu Dasgupta
[http://sayamindu.randomink.org/ramblings]
# -*- coding: utf-8 -*-
#!/usr/bin/env python

import grp
import pwd
import os
import sys
import sabayon
# A quick hack to apply a given Sabayon profile to all the
# members of a group.
# Written by Sayamindu Dasgupta (sayamindu randomink org)

if len(sys.argv) < 3:
	print "Usage:\n\t %s <group> <profile>" % (sys.argv[0])
	sys.exit()

def apply_profile(user, profile):
	if os.fork():
		return() # Parent goes back to the loop, child continues and applies profile
	uprofile = sabayon.userprofile.UserProfile(profile)
	uid = pwd.getpwnam(user)[2]
	home = pwd.getpwnam(user)[5]
	os.chdir(home)
	os.setuid(uid)
	uprofile.apply(False)
	sys.exit() # get rid of child


group = sys.argv[1]
profile = sys.argv[2]

grp_members = grp.getgrnam(group)[3]
#TODO - user foo is usually implicitly a member of 
#       group foo. Need to implement that.

for user in grp_members:
	apply_profile(user, profile)


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