[OT] Problems with permissions etc

Mike Meyer mwm at mired.org
Thu Jul 28 04:59:27 CEST 2005

"Frank Millman" <frank at chagford.com> writes:

> While developing under linux, I use my own computer, as the only user,
> so it has become my habit to login as root and do all my work as a
> superuser. I know that this is not desirable, but it has become a
> habit, which I am now trying to get out of.

Ack. Phht. Well, at least you're trying to get out of the habit. Your
problems are generally caused by doing things as the wrong user. You
need to figure out which things you have to do as root, and then do
those (and only those) as root, and do the rest as you.

> 1. The application I am developing will eventually be deployed as a
> multi-user accounting/business system. I want to identify the physical
> workstation that generates each transaction, so I am using the mac
> address. My method for extracting this is as follows -
> 	mac = os.popen("ifconfig|grep Ether|awk {print '$5'}").read()[:-1]  #
> I did not come up with this myself, I cribbed it from somewhere
> As root, this works fine. As non-root, ifconfig is not found. The
> reason is that it is in /sbin, and this is not included in the default
> path for non-root users. I could either include /sbin in my path, or I
> could change the above line to /sbin/ifconfig ... Alternatively, there
> may be a better way of getting the mac address or identifying the
> workstation.

Put "/sbin/ifconfig" in a string variable. Place that somewhere where
a person porting the program will find it. Then use the variable name
in the os.popen call. Of course, if ifconfig is in /sbin, it's likely
that their ifconfig won't work that way anyway. Mine certainly

BTW, I'd consider doing the grep/awk part of the process via
python. Python won't be as fast as the grep/awk, but ifconfig's output
is short, so the cost of launching the new processes probably swamps
that. Something like:

for line in os.popen(IFCONFIG):
    if line.find('Ether'):
       mac = line.split()[4]

should do it. On the other hand, if its fast enough and works, don't
touch it.

> 2. I am using wxPython, which was compiled from source. It so happens
> that I did this with a colleague who also has a user account on my
> machine, so the compile and install of wxPython was done from his home
> directory.

Python modules should be installed as root. That should put them in
the correct place.

> When I start my app as non-root, the import of wx fails, as it cannot
> find certain files. They are in the other user's home directory, but as
> the top-level directory has permissions of drwx------, my user cannot
> read anything in that directory. I can change the directory
> permissions, or I can move the files to another area which all users
> can read. If the latter, is there a 'correct' place to put them?

Yes. In the python libraries site-packages directory.

You really want to check out your platforms package management
system. It's *much* easier to type "sudo port install wx-python" than
it is to download, configure, compile, and install the package. The
exact command will depend on your distro. It's probably one of rpm or
apt-get, but might be emerge, or maybe even port.

Mike Meyer <mwm at mired.org>			http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.

More information about the Python-list mailing list