View Full Version : [Python]Detect architecture and country
Kiwinote
June 28th, 2007, 04:26 PM
For a program I am writing I have been googling on ways to detect the architecture and locale on a computer.
For the architecture detection I have found the platform.machine() command. The only thing is, is that I can't find a list of all possible outputs. Any ideas? (Preference would be the same way that apt uses to decide which architecture package to download)
I have not yet been able to find anything that can detect the country code of the country you are in. As far as I know this should be hidden in you system somewhere, because when you install Ubuntu you have to select your location. Ideas would be appreciated.
Thanks,
Kiwinote
pmasiar
June 28th, 2007, 11:04 PM
check http://docs.python.org/lib/module-locale.html - does it help?
Kiwinote
June 30th, 2007, 04:43 AM
I found that one, but it didn't seem to work: for me it gives >>> import locale; print locale.getlocale(locale.LC_ALL)
(None, None)
Does it work for you? Any other ideas..?
Kiwinote
July 2nd, 2007, 03:02 AM
ok, solved the architecture one with architecture = commands.getoutput('apt-cache -v')
architecture = architecture.split(" ")[4]
Any ideas on the country detection?
ssam
July 2nd, 2007, 03:51 AM
import os
os.environ['LANG']
will get you language
tz = commands.getoutput('date +%Z')
will get you timezone (though there is probably a neater method)
arch = commands.getoutput('uname -m')
might be more portable (should work on any linux/unix) for getting arch
Kiwinote
July 2nd, 2007, 11:14 AM
import os
os.environ['LANG']
will get you language
The second set of letters is the country of the language. It doesn't refer to the country you are in, so that doesn't help too much. (someone in France could have installed an English system)
tz = commands.getoutput('date +%Z')
will get you timezone (though there is probably a neater method)
doesn't tell you which country in the timezone you are in..
Any other ideas?
Thanks,
Kiwinote
Kiwinote
July 3rd, 2007, 09:26 AM
Anyone else got ideas on country detection? (bash / python / filename)
christhemonkey
July 3rd, 2007, 09:56 AM
The only way i can think of getting the users location accurately is, when installing ubuntu your are prompted for your location, this is saved in your evolution contacts.
So you can get this information by parsing the evolution contacts for the current user names details and then getting the country of their address.
The "about me" dialog has this information by doing just that (but its written in C) if you can try and disect some meaning form how it goes about it see here:
http://svn.gnome.org/viewcvs/gnome-control-center/trunk/capplets/about-me/gnome-about-me.c?revision=7523&view=markup
This should be fairly trivial(ish) to implement.
vBulletin® v3.8.7, Copyright ©2000-2012, vBulletin Solutions, Inc.