[Scons-dev] Installing files
Managan, Rob
managan1 at llnl.gov
Tue Jun 19 12:37:29 EDT 2012
Since I weighed in on the question about getting CheckLib to do what you want I recall that in the past there have been questions about Install. Where is a good spot to make available my Install_fun that installs the requested file but also lets you set permission bits, owner, and group since when I install an executable in a public space I need to get those set correctly.
I suppose the next question is whether something like that should go into the core code?
Since it is fairly short here is the coding.
Usage is:
env['INSTALL']=installFunc
env['INSTALL_GROUP']='mygroup'
env['INSTALL_MODE']=0710 # leading 0 implies octal
The code is:
def installFunc(dest, source, env):
"""Install a source file into a destination by copying it (and its
permission/mode bits)."""
owner = env.get('INSTALL_OWNER', None)
if owner:
try:
uid = pwd.getpwnam(owner)[2]
except TypeError:
uid = owner
else:
uid = -1
group = env.get('INSTALL_GROUP', None)
# print 'group',group
if group:
try:
gid = grp.getgrnam(group)[2]
except TypeError:
gid = group
else:
gid = -1
mode = env.get('INSTALL_MODE', None)
# print 'mode',mode
if not mode:
st = os.stat(source)
mode = (stat.S_IMODE(st[stat.ST_MODE]) | stat.S_IWRITE)
dirname = os.path.dirname(dest)
if not os.path.isdir(dirname):
os.makedirs(dirname)
shutil.copy2(source, dest)
if owner or group:
os.chown(dest, uid, gid)
os.chmod(dest, mode)
return 0
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
Rob Managan email managan at llnl.gov
LLNL phone: 925-423-0903
P.O. Box 808, L-095 FAX: 925-422-3389
Livermore, CA 94551-0808
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://two.pairlist.net/pipermail/scons-dev/attachments/20120619/f53f1621/attachment.html>
More information about the Scons-dev
mailing list