Merge lp:~thibaultfevry/cardapio/no_subprocess_for_platform into lp:cardapio

Proposed by Thibault Févry
Status: Merged
Merge reported by: Thiago Teixeira
Merged at revision: not available
Proposed branch: lp:~thibaultfevry/cardapio/no_subprocess_for_platform
Merge into: lp:cardapio
Diff against target: 28 lines (+3/-2)
1 file modified
src/cardapio.py (+3/-2)
To merge this branch: bzr merge lp:~thibaultfevry/cardapio/no_subprocess_for_platform
Reviewer Review Type Date Requested Status
Thiago Teixeira Pending
Review via email: mp+40378@code.launchpad.net

Commit message

 Use Python Std Library to get distribution name.

Description of the change

 I looked at the code, and the fact that you used subprocess to get distribution name bogged me, so I made it use Python Std Library instead (Subproccess has more hidden bugs and many python programmers consider it "evil"). The function is documented here : http://docs.python.org/library/platform.html#unix-platforms . If you want backwards compatibility with Python version < 2.5 you may want to use platform.dist() instead of platform.linux_distribution(), but this only changes the function name.

To post a comment you must log in.
Revision history for this message
Thibault Févry (thibaultfevry) wrote :

 I just want to add that I made an error with the indentation level (I use 4 spaces and not tabs), so you have to change this before it works. This is also untested in the programm itself but the results given by the 2 commands are the same.

483. By Thibault Févry

Use project indentation : Tab instead of 4 spaces.

Revision history for this message
Thiago Teixeira (tvst) wrote :

Thanks for the code, and for letting me know about Subprocess. I will take a look at your branch tonight.

Cheers!

Revision history for this message
Thiago Teixeira (tvst) wrote :

Merged! Thanks for posting this.

Removing these "hacky" lines are always a good thing, so your bug report was right on point. So, in that same direction: Do you happen to know an alternative way to get the output of the "which" command in Python?

This would allow us to *completely* remove our reliance on the "commands"/"subprocess" modules in Cardapio :)

Revision history for this message
Thibault Févry (thibaultfevry) wrote :

 I think there's a which.py in python tools (Which comes with the windows version, and that you should be able to download in linux). There is also this thread : http://<email address hidden>/msg250218.html that gives some explanations and gives a link to this : http://code.google.com/p/which/

 So, there isn't really a similar function in python library, but I think it's better to include a light python function (The google project as many other things you don't need.) to get the output than use a subrprocess call. This would be faster, more pythonnic and less buggy. (Someone could have an alias for which in their system for example.)

Revision history for this message
Thiago Teixeira (tvst) wrote :

Ok, I just added the "which" code into Cardapio and now we don't depend on superfluous uses of either "command" or "subprocess". Thanks for the help!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/cardapio.py'
2--- src/cardapio.py 2010-11-08 13:41:56 +0000
3+++ src/cardapio.py 2010-11-08 21:24:51 +0000
4@@ -56,6 +56,7 @@
5 import keybinder
6 import subprocess
7 import dbus, dbus.service
8+ import platform
9
10 from time import time
11 from pango import ELLIPSIZE_END
12@@ -149,7 +150,7 @@
13
14 class Cardapio(dbus.service.Object):
15
16- distro_name = getoutput('lsb_release -is')
17+ distro_name = platform.linux_distribution()[0]
18
19 MIN_VISIBILITY_TOGGLE_INTERVAL = 0.200 # seconds (this is a bit of a hack to fix some focus problems)
20 PANEL_SIZE_CHANGE_IGNORE_INTERVAL = 200 # milliseconds
21@@ -207,7 +208,7 @@
22
23 logging.info('----------------- Cardapio launched -----------------')
24 logging.info('Cardapio version: %s' % Cardapio.version)
25- logging.info('Distribution: %s' % getoutput('lsb_release -ds'))
26+ logging.info('Distribution: %s' % " ".join(platform.linux_distribution()[:2]))
27
28 self.home_folder_path = os.path.abspath(os.path.expanduser('~'))
29

Subscribers

People subscribed via source and target branches