View Single Post
juise-'s Avatar
Posts: 186 | Thanked: 192 times | Joined on Jan 2010 @ Finland
#5
Originally Posted by maxximuscool View Post
My python code is at:
/usr/lib/hildon-desktop

Location of my shortcut:
/usr/share/applications/hildon-status-menu/

How do i edit a file as root inside python code?
The file I want to change is class as "root" rw-r--r--
In a hurry, are you?

First of all, to change permissions on file owned by root, your code needs to be root.

Second, the methods you are looking for are os.chown() (for changing owner, if you need to) and os.chmod() (for changing permissions). The library reference is your friend:
http://docs.python.org/library/os.html

So, to change the permission:
Code:
import os
import stat

os.chmod('/your/file', stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH)
(See the documentation of stat module for more info about the flags)
__________________
Trout have underwater weapons.

Last edited by juise-; 2010-08-30 at 11:12.
 

The Following User Says Thank You to juise- For This Useful Post: