Active Topics

 



Notices


Reply
Thread Tools
Posts: 3,664 | Thanked: 1,530 times | Joined on Sep 2009 @ Hamilton, New Zealand
#1
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--

==========

As above I'm writing a small plugin and wanted to know how to do the packaging. Can someone link me to the handy tutorial?

Last edited by maxximuscool; 2010-08-30 at 22:25.
 
Posts: 3,664 | Thanked: 1,530 times | Joined on Sep 2009 @ Hamilton, New Zealand
#2
 
Posts: 3,664 | Thanked: 1,530 times | Joined on Sep 2009 @ Hamilton, New Zealand
#3
Anyone know how to change the file permission for temporary via python?
 
Posts: 3,664 | Thanked: 1,530 times | Joined on Sep 2009 @ Hamilton, New Zealand
#4
What is the equilvalent of Python to this Xterminal command?

root
chmod -R 666 path/to/file?
 
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:
Posts: 200 | Thanked: 300 times | Joined on Nov 2009 @ The Netherlands
#6
Originally Posted by maxximuscool View Post
What is the equilvalent of Python to this Xterminal command?

root
chmod -R 666 path/to/file?
Code:
import os  # if not already done
os.system('chmod -R 666 path/to/file')
 

The Following 2 Users Say Thank You to digitalvoid For This Useful Post:
Posts: 3,664 | Thanked: 1,530 times | Joined on Sep 2009 @ Hamilton, New Zealand
#7
Originally Posted by juise- View Post
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)
Yes was a bit hurry, I'm testing my little plugin. And hoping to release it very soon to accomidating people who has the problem with their FM Transmitter.

By the way how do i be as root on my python script?
 
Posts: 3,664 | Thanked: 1,530 times | Joined on Sep 2009 @ Hamilton, New Zealand
#8
Originally Posted by digitalvoid View Post
Code:
import os  # if not already done
os.system('chmod -R 666 path/to/file')
This script doesn't do anything because it doesn't have root access to do anything.
 
Posts: 3,664 | Thanked: 1,530 times | Joined on Sep 2009 @ Hamilton, New Zealand
#9
 
Posts: 3,664 | Thanked: 1,530 times | Joined on Sep 2009 @ Hamilton, New Zealand
#10
Woohoo SUCESS!!! Now All I need to do is to packaging it. But how?
Any tutorial lol?

Is this the one?
http://wiki.maemo.org/PyMaemo/Scratc...ackaging_guide

Last edited by maxximuscool; 2010-08-30 at 21:43.
 
Reply


 
Forum Jump


All times are GMT. The time now is 11:23.