Reputation: 7450
How do I use Python to check if the Gnome running is Gnome 2 or Gnome 3 ?
Upvotes: 0
Views: 648
Reputation: 411
Both gnome 2 and gnome 3 use information from a certain file to display gnome version in System Info. The file in question is called gnome-version.xml
In gnome 3 it is part of the package gnome-desktop so it shouldn't be missing from any gnome 3 install regardless the distro. The difference is that in gnome 2 it's either installed in
/usr/share/gnome-about/gnome-version.xml
or missing, while in gnome 3 it's always located here:
/usr/share/gnome/gnome-version.xml
So I guess it's only a matter of checking for the right file in the right location.
Upvotes: 2
Reputation: 86
Use python to run a command such as "gnome-about –gnome-version" in the operating system shell.
This bypasses distribution and indeed operating system package management nightmares as as long as gnome is installed in path it will respond correctly. No messy uses of apt/yum/pkg_*.
Look at python's Operating System module, specifically the os.system() command. http://docs.python.org/library/os.html#os.system . There are more elegant ways I'm sure, but this'll solve your issue.
Of-course this will only work if gnome is actually installed. I assumed it was given that you were asking what version it was. Lubuntu is a remix of standard ubuntu, and does not come with the full gnome desktop installed by default.
The following command will show installed packages that have gnome in the name.
dpkg -l | grep gnome
To find the exact name of the gnome-desktop package you'd do something like the following:
apt-cache search gnome desktop
And then the following to install a specific package.
sudo apt-get install <package_name_here>
Upvotes: 2