From d478526b085306891d2d2d258a8ca27f7f407a6c Mon Sep 17 00:00:00 2001 From: Sebastien Helleu Date: Mon, 8 Nov 2010 15:10:13 +0100 Subject: [PATCH] Add info "python2_bin" (path to python 2.x interpreter) in Python plugin --- ChangeLog | 1 + doc/de/autogen/plugin_api/infos.txt | 2 + doc/en/autogen/plugin_api/infos.txt | 2 + doc/fr/autogen/plugin_api/infos.txt | 2 + doc/it/autogen/plugin_api/infos.txt | 2 + po/cs.po | 5 +- po/de.po | 5 +- po/es.po | 5 +- po/fr.po | 7 +- po/hu.po | 5 +- po/it.po | 5 +- po/pl.po | 5 +- po/ru.po | 5 +- po/weechat.pot | 5 +- src/plugins/scripts/python/weechat-python.c | 84 +++++++++++++++++++++ 15 files changed, 130 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index b8cf2ad08..7aed7df66 100644 --- a/ChangeLog +++ b/ChangeLog @@ -59,6 +59,7 @@ Version 0.3.4 (under dev!) expressions (bug #26964) * relay: beta version of IRC proxy * scripts: add missing function "infolist_reset_item_cursor" in API (bug #31057) +* python: add info "python2_bin" (path to python 2.x interpreter) * lua: fix crash when unloading script * ruby: fix compilation with Ruby 1.9.2 (patch #7316) diff --git a/doc/de/autogen/plugin_api/infos.txt b/doc/de/autogen/plugin_api/infos.txt index 631609c1c..2e5c88033 100644 --- a/doc/de/autogen/plugin_api/infos.txt +++ b/doc/de/autogen/plugin_api/infos.txt @@ -22,6 +22,8 @@ | irc | irc_server_isupport_value | Wert der Funktion, sofern es vom Server unterstützt wird (durch IRC Message 005) | Server,Funktion +| python | python2_bin | path to python 2.x interpreter | - + | weechat | charset_internal | Interner WeeChat Zeichensatz | - | weechat | charset_terminal | Terminal Zeichensatz | - diff --git a/doc/en/autogen/plugin_api/infos.txt b/doc/en/autogen/plugin_api/infos.txt index 9de4fb5c6..db75a89d5 100644 --- a/doc/en/autogen/plugin_api/infos.txt +++ b/doc/en/autogen/plugin_api/infos.txt @@ -22,6 +22,8 @@ | irc | irc_server_isupport_value | value of feature, if supported by server (from IRC message 005) | server,feature +| python | python2_bin | path to python 2.x interpreter | - + | weechat | charset_internal | WeeChat internal charset | - | weechat | charset_terminal | terminal charset | - diff --git a/doc/fr/autogen/plugin_api/infos.txt b/doc/fr/autogen/plugin_api/infos.txt index 4c16c9100..a51dbcb36 100644 --- a/doc/fr/autogen/plugin_api/infos.txt +++ b/doc/fr/autogen/plugin_api/infos.txt @@ -22,6 +22,8 @@ | irc | irc_server_isupport_value | valeur de la fonctionnalité, si supportée par le serveur (du message IRC 005) | serveur,fonctionnalité +| python | python2_bin | chemin vers l'interpréteur python 2.x | - + | weechat | charset_internal | charset interne à WeeChat | - | weechat | charset_terminal | charset du terminal | - diff --git a/doc/it/autogen/plugin_api/infos.txt b/doc/it/autogen/plugin_api/infos.txt index 96bdaa5e8..fdee19485 100644 --- a/doc/it/autogen/plugin_api/infos.txt +++ b/doc/it/autogen/plugin_api/infos.txt @@ -22,6 +22,8 @@ | irc | irc_server_isupport_value | valore della caratteristica, se supportata dal servre (dal messaggio IRC 005) | server,caratteristica +| python | python2_bin | path to python 2.x interpreter | - + | weechat | charset_internal | set caratteri interno di WeeChat | - | weechat | charset_terminal | set caratteri terminale | - diff --git a/po/cs.po b/po/cs.po index 5470c8cb2..ebccad6b0 100644 --- a/po/cs.po +++ b/po/cs.po @@ -20,7 +20,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.3.4-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2010-11-07 09:27+0100\n" +"POT-Creation-Date: 2010-11-08 15:03+0100\n" "PO-Revision-Date: 2010-11-06 11:55+0100\n" "Last-Translator: Jiri Golembiovsky \n" "Language-Team: weechat-dev \n" @@ -6581,6 +6581,9 @@ msgstr "%s%s: nemůžu přesměrovat stdout" msgid "%s%s: unable to redirect stderr" msgstr "%s%s: nemohu přesměrovat stderr" +msgid "path to python 2.x interpreter" +msgstr "" + #, c-format msgid "%s%s: unable to launch global interpreter" msgstr "%s%s: nemohu spustit globální interpreter" diff --git a/po/de.po b/po/de.po index cd2b4112d..e1b97a663 100644 --- a/po/de.po +++ b/po/de.po @@ -22,7 +22,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.3.3-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2010-11-07 09:27+0100\n" +"POT-Creation-Date: 2010-11-08 15:03+0100\n" "PO-Revision-Date: 2010-11-06 11:55+0100\n" "Last-Translator: Nils G.\n" "Language-Team: weechat-dev \n" @@ -6852,6 +6852,9 @@ msgstr "%s%s: Kann Standardausgabe (stdout) nicht umlenken" msgid "%s%s: unable to redirect stderr" msgstr "%s%s: Kann Standardfehlerausgabe (stderr) nicht umlenken" +msgid "path to python 2.x interpreter" +msgstr "" + #, c-format msgid "%s%s: unable to launch global interpreter" msgstr "%s%s: Kann globalen Interpreter nicht starten" diff --git a/po/es.po b/po/es.po index 6be671233..329f3c30a 100644 --- a/po/es.po +++ b/po/es.po @@ -21,7 +21,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.3.4-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2010-11-07 09:27+0100\n" +"POT-Creation-Date: 2010-11-08 15:03+0100\n" "PO-Revision-Date: 2010-11-06 11:56+0100\n" "Last-Translator: Elián Hanisch \n" "Language-Team: weechat-dev \n" @@ -6657,6 +6657,9 @@ msgstr "%s%s: no es posible redirigir la salida stdout" msgid "%s%s: unable to redirect stderr" msgstr "%s%s: no es posible redirigir la salida stderr" +msgid "path to python 2.x interpreter" +msgstr "" + #, c-format msgid "%s%s: unable to launch global interpreter" msgstr "%s%s: no es posible iniciar el intérprete global" diff --git a/po/fr.po b/po/fr.po index a680fddd5..518d459cd 100644 --- a/po/fr.po +++ b/po/fr.po @@ -21,8 +21,8 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.3.4-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2010-11-07 09:27+0100\n" -"PO-Revision-Date: 2010-11-07 09:29+0100\n" +"POT-Creation-Date: 2010-11-08 15:03+0100\n" +"PO-Revision-Date: 2010-11-08 15:03+0100\n" "Last-Translator: Sebastien Helleu \n" "Language-Team: weechat-dev \n" "Language: French\n" @@ -6758,6 +6758,9 @@ msgstr "%s%s: impossible de rediriger stdout" msgid "%s%s: unable to redirect stderr" msgstr "%s%s: impossible de rediriger stderr" +msgid "path to python 2.x interpreter" +msgstr "chemin vers l'interpréteur python 2.x" + #, c-format msgid "%s%s: unable to launch global interpreter" msgstr "%s%s: impossible de lancer l'interpréteur global" diff --git a/po/hu.po b/po/hu.po index ef4f1822e..3a4a9e89c 100644 --- a/po/hu.po +++ b/po/hu.po @@ -20,7 +20,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.3.4-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2010-11-07 09:27+0100\n" +"POT-Creation-Date: 2010-11-08 15:03+0100\n" "PO-Revision-Date: 2010-11-05 17:17+0100\n" "Last-Translator: Andras Voroskoi \n" "Language-Team: weechat-dev \n" @@ -6302,6 +6302,9 @@ msgstr "Nem sikerült a(z) \"%s\" naplófájlt írni\n" msgid "%s%s: unable to redirect stderr" msgstr "%s nem sikerült a szervert létrehozni\n" +msgid "path to python 2.x interpreter" +msgstr "" + #, fuzzy, c-format msgid "%s%s: unable to launch global interpreter" msgstr "%s nem sikerült a szervert létrehozni\n" diff --git a/po/it.po b/po/it.po index 1bcd643e8..3aca8687e 100644 --- a/po/it.po +++ b/po/it.po @@ -20,7 +20,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.3.4-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2010-11-07 09:27+0100\n" +"POT-Creation-Date: 2010-11-08 15:03+0100\n" "PO-Revision-Date: 2010-11-06 11:56+0100\n" "Last-Translator: Marco Paolone \n" "Language-Team: weechat-dev \n" @@ -6696,6 +6696,9 @@ msgstr "%s%s: impossibile reindirizzare stdout" msgid "%s%s: unable to redirect stderr" msgstr "%s%s: impossibile reindirizzare stderr" +msgid "path to python 2.x interpreter" +msgstr "" + #, c-format msgid "%s%s: unable to launch global interpreter" msgstr "%s%s: impossibile avviare l'interprete globale" diff --git a/po/pl.po b/po/pl.po index acb2e7c86..a6129ddfa 100644 --- a/po/pl.po +++ b/po/pl.po @@ -21,7 +21,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.3.4-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2010-11-07 09:27+0100\n" +"POT-Creation-Date: 2010-11-08 15:03+0100\n" "PO-Revision-Date: 2010-11-06 11:56+0100\n" "Last-Translator: Krzysztof Koroscik \n" "Language-Team: weechat-dev \n" @@ -6603,6 +6603,9 @@ msgstr "%s%s: nie można przekierować wyjścia" msgid "%s%s: unable to redirect stderr" msgstr "%s%s: nie można przekierować wyjścia błędu" +msgid "path to python 2.x interpreter" +msgstr "" + #, c-format msgid "%s%s: unable to launch global interpreter" msgstr "%s%s: nie można uruchomić globalnego interpretera" diff --git a/po/ru.po b/po/ru.po index 1c52bc8be..4c0f75b08 100644 --- a/po/ru.po +++ b/po/ru.po @@ -20,7 +20,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.3.4-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2010-11-07 09:27+0100\n" +"POT-Creation-Date: 2010-11-08 15:03+0100\n" "PO-Revision-Date: 2010-11-05 17:17+0100\n" "Last-Translator: Pavel Shevchuk \n" "Language-Team: weechat-dev \n" @@ -6315,6 +6315,9 @@ msgstr "Не могу записать лог-файл \"%s\"\n" msgid "%s%s: unable to redirect stderr" msgstr "%s не могу создать сервер\n" +msgid "path to python 2.x interpreter" +msgstr "" + #, fuzzy, c-format msgid "%s%s: unable to launch global interpreter" msgstr "%s не могу создать сервер\n" diff --git a/po/weechat.pot b/po/weechat.pot index 461c06c65..88fdd23d9 100644 --- a/po/weechat.pot +++ b/po/weechat.pot @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2010-11-07 09:27+0100\n" +"POT-Creation-Date: 2010-11-08 15:03+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -5528,6 +5528,9 @@ msgstr "" msgid "%s%s: unable to redirect stderr" msgstr "" +msgid "path to python 2.x interpreter" +msgstr "" + #, c-format msgid "%s%s: unable to launch global interpreter" msgstr "" diff --git a/src/plugins/scripts/python/weechat-python.c b/src/plugins/scripts/python/weechat-python.c index dadf38fb7..a49aad852 100644 --- a/src/plugins/scripts/python/weechat-python.c +++ b/src/plugins/scripts/python/weechat-python.c @@ -25,6 +25,9 @@ #undef _ #include +#include +#include +#include #include "../../weechat-plugin.h" #include "../script.h" @@ -47,6 +50,7 @@ struct t_plugin_script *python_current_script = NULL; struct t_plugin_script *python_registered_script = NULL; const char *python_current_script_filename = NULL; PyThreadState *python_mainThreadState = NULL; +char *python2_bin = NULL; /* * string used to execute action "install": @@ -67,6 +71,54 @@ char *python_action_remove_list = NULL; char python_buffer_output[128]; +/* + * weechat_python_set_python2_bin: set path to python 2.x interpreter + */ + +void +weechat_python_set_python2_bin () +{ + const char *dir_separator; + char *path, **paths, bin[4096]; + char *versions[] = { "2", "2.7", "2.6", "2.5", "2.4", "2.3", "2.2", NULL }; + int num_paths, i, j, rc; + struct stat stat_buf; + + python2_bin = NULL; + + dir_separator = weechat_info_get ("dir_separator", ""); + path = getenv ("PATH"); + + if (dir_separator && path) + { + paths = weechat_string_split (path, ":", 0, 0, &num_paths); + if (paths) + { + for (i = 0; i < num_paths; i++) + { + for (j = 0; versions[j]; j++) + { + snprintf (bin, sizeof (bin), "%s%s%s%s", + paths[i], dir_separator, "python", + versions[j]); + rc = stat (bin, &stat_buf); + if ((rc == 0) && (S_ISREG(stat_buf.st_mode))) + { + python2_bin = strdup (bin); + break; + } + } + if (python2_bin) + break; + } + weechat_string_free_split (paths); + } + } + + if (!python2_bin) + python2_bin = strdup ("python"); +} + /* * weechat_python_hashtable_map_cb: callback called for each key/value in a * hashtable @@ -794,6 +846,26 @@ weechat_python_completion_cb (void *data, const char *completion_item, return WEECHAT_RC_OK; } +/* + * weechat_python_info_cb: callback for info + */ + +const char * +weechat_python_info_cb (void *data, const char *info_name, + const char *arguments) +{ + /* make C compiler happy */ + (void) data; + (void) arguments; + + if (weechat_strcasecmp (info_name, "python2_bin") == 0) + { + return python2_bin; + } + + return NULL; +} + /* * weechat_python_infolist_cb: callback for infolist */ @@ -939,6 +1011,16 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]) { weechat_python_plugin = plugin; + /* + * hook info to get path to python 2.x interpreter + * (some scripts using hook_process need that) + */ + weechat_python_set_python2_bin (); + weechat_hook_info ("python2_bin", + N_("path to python 2.x interpreter"), + NULL, + &weechat_python_info_cb, NULL); + /* init stdout/stderr buffer */ python_buffer_output[0] = '\0'; @@ -1019,6 +1101,8 @@ weechat_plugin_end (struct t_weechat_plugin *plugin) } /* free some data */ + if (python2_bin) + free (python2_bin); if (python_action_install_list) free (python_action_install_list); if (python_action_remove_list)