Commands for changing ownership of a file
I have a script that I execute as root, but I need to change the ownership of the files created in the script to that of my username. In GNU Bash, the command is something like chown myusername:users. What's the equivalent Python command? I know that there is a command that uses numbers for the username and group, but is there a command that would allow me to use myusername and users instead of numbers? -- http://mail.python.org/mailman/listinfo/python-list
Re: Commands for changing ownership of a file
On Sun, Aug 14, 2011 at 3:56 PM, Jason Hsu jhsu802...@gmail.com wrote: I have a script that I execute as root, but I need to change the ownership of the files created in the script to that of my username. In GNU Bash, the command is something like chown myusername:users. What's the equivalent Python command? I know that there is a command that uses numbers for the username and group, but is there a command that would allow me to use myusername and users instead of numbers? Simply use the `pwd` and `grp` modules to lookup the uid and gid for the username and group-name respectively. Then use the id-based chown function(s) you already came across. http://docs.python.org/library/pwd.html#pwd.getpwnam http://docs.python.org/library/grp.html#grp.getgrnam Cheers, Chris -- http://mail.python.org/mailman/listinfo/python-list
Re: Commands for changing ownership of a file
in python-3.2.1 I'm using os.system() again, from time to time maybe that's the one you were looking for? os.system('chown user:group /tmp/f') 0 os.system('ls -l /tmp/f') -rw-r--r-- 1 user group 0 Aug 15 03:52 /tmp/f and besides os.chown() (where you ned the uid and gid), you could also use subprocess.call() or subprocess.Popen() regards Michael * Jason Hsu jhsu802...@gmail.com [2011-08-15 01:15]: I have a script that I execute as root, but I need to change the ownership of the files created in the script to that of my username. In GNU Bash, the command is something like chown myusername:users. What's the equivalent Python command? I know that there is a command that uses numbers for the username and group, but is there a command that would allow me to use myusername and users instead of numbers? -- http://mail.python.org/mailman/listinfo/python-list -- Michael Poeltl Computational Materials Physics voice: +43-1-4277-51409 Univ. Wien, Sensengasse 8/12 fax: +43-1-4277-9514 (or 9513) A-1090 Wien, AUSTRIA cmp.mpi.univie.ac.at slackware-12.2/ubuntu-10.10 | vim-7.3 | python-3.2.1 | mutt-1.5.18 | elinks-0.12 -- http://mail.python.org/mailman/listinfo/python-list