doc: add URL transfer in scripting guide
parent
1ae6029b98
commit
4ee60b9ef0
|
@ -616,25 +616,69 @@ gesetzt. Dies ist der Return Code des Befehls.
|
|||
|
||||
Beispiele:
|
||||
|
||||
[source,python]
|
||||
----------------------------------------
|
||||
process_output = ""
|
||||
|
||||
def my_process_cb(data, command, rc, out, err):
|
||||
global process_output
|
||||
if out != "":
|
||||
process_output += out
|
||||
if int(rc) >= 0:
|
||||
weechat.prnt("", process_output)
|
||||
return weechat.WEECHAT_RC_OK
|
||||
|
||||
weechat.hook_process("/bin/ls -l /etc", 10 * 1000, "my_process_cb", "")
|
||||
----------------------------------------
|
||||
|
||||
// TRANSLATION MISSING
|
||||
[[url_transfer]]
|
||||
URL transfer
|
||||
^^^^^^^^^^^^
|
||||
|
||||
_New in version 0.3.7._
|
||||
|
||||
To download URL (or post to URL), you have to use function `hook_process`, or
|
||||
`hook_process_hashtable` if you need to set options for URL transfer.
|
||||
|
||||
Example of URL transfer without option: the HTML page will be received as "out"
|
||||
in callback (standard output of process):
|
||||
|
||||
[source,python]
|
||||
----------------------------------------
|
||||
# Zeigt die Versionen der Linux-Kerne.
|
||||
kernel_txt = ""
|
||||
|
||||
def kernel_process_cb(data, command, rc, stdout, stderr):
|
||||
""" Callback reading command output. """
|
||||
def kernel_process_cb(data, command, rc, out, err):
|
||||
global kernel_txt
|
||||
if stdout != "":
|
||||
kernel_txt += stdout
|
||||
if out != "":
|
||||
kernel_txt += out
|
||||
if int(rc) >= 0:
|
||||
weechat.prnt("", kernel_txt)
|
||||
return weechat.WEECHAT_RC_OK
|
||||
|
||||
weechat.hook_process("python -c \"import urllib; " \
|
||||
"print urllib.urlopen('http://www.kernel.org/kdist/finger_banner').read()\"",
|
||||
10 * 1000, "kernel_process_cb", "")
|
||||
weechat.hook_process("url:http://www.kernel.org/kdist/finger_banner",
|
||||
30 * 1000, "kernel_process_cb", "")
|
||||
----------------------------------------
|
||||
|
||||
Example of URL transfer with an option: download latest WeeChat development
|
||||
package in file '/tmp/weechat-devel.tar.gz':
|
||||
|
||||
[source,python]
|
||||
----------------------------------------
|
||||
def my_process_cb(data, command, rc, out, err):
|
||||
if int(rc) >= 0:
|
||||
weechat.prnt("", "End of transfer (rc=%s)" % rc)
|
||||
return weechat.WEECHAT_RC_OK
|
||||
|
||||
weechat.hook_process_hashtable("url:http://weechat.org/files/src/weechat-devel.tar.gz",
|
||||
{ "file_out": "/tmp/weechat-devel.tar.gz" },
|
||||
30 * 1000, "my_process_cb", "")
|
||||
----------------------------------------
|
||||
|
||||
For more information about URL transfer and available options, see functions
|
||||
`hook_process` and `hook_process_hashtable` in 'WeeChat Plugin API Reference'.
|
||||
|
||||
[[config_options]]
|
||||
Konfiguration / Optionen
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
@ -676,7 +720,7 @@ SKRIPT_NAME = "meinskript"
|
|||
# ...
|
||||
|
||||
def config_cb(data, option, value):
|
||||
""" Callback welcher genutzt wird wenn eine Option verändert wurde. """
|
||||
"""Callback welcher genutzt wird wenn eine Option verändert wurde."""
|
||||
# zum Beispiel werden hier alle Optionen des Skripts in die entsprechenden Variablen geschrieben...
|
||||
# ...
|
||||
return weechat.WEECHAT_RC_OK
|
||||
|
|
|
@ -603,25 +603,68 @@ return code of command.
|
|||
|
||||
Example:
|
||||
|
||||
[source,python]
|
||||
----------------------------------------
|
||||
process_output = ""
|
||||
|
||||
def my_process_cb(data, command, rc, out, err):
|
||||
global process_output
|
||||
if out != "":
|
||||
process_output += out
|
||||
if int(rc) >= 0:
|
||||
weechat.prnt("", process_output)
|
||||
return weechat.WEECHAT_RC_OK
|
||||
|
||||
weechat.hook_process("/bin/ls -l /etc", 10 * 1000, "my_process_cb", "")
|
||||
----------------------------------------
|
||||
|
||||
[[url_transfer]]
|
||||
URL transfer
|
||||
^^^^^^^^^^^^
|
||||
|
||||
_New in version 0.3.7._
|
||||
|
||||
To download URL (or post to URL), you have to use function `hook_process`, or
|
||||
`hook_process_hashtable` if you need to set options for URL transfer.
|
||||
|
||||
Example of URL transfer without option: the HTML page will be received as "out"
|
||||
in callback (standard output of process):
|
||||
|
||||
[source,python]
|
||||
----------------------------------------
|
||||
# Display versions of Linux kernels.
|
||||
kernel_txt = ""
|
||||
|
||||
def kernel_process_cb(data, command, rc, stdout, stderr):
|
||||
""" Callback reading command output. """
|
||||
def kernel_process_cb(data, command, rc, out, err):
|
||||
global kernel_txt
|
||||
if stdout != "":
|
||||
kernel_txt += stdout
|
||||
if out != "":
|
||||
kernel_txt += out
|
||||
if int(rc) >= 0:
|
||||
weechat.prnt("", kernel_txt)
|
||||
return weechat.WEECHAT_RC_OK
|
||||
|
||||
weechat.hook_process("python -c \"import urllib; "
|
||||
"print urllib.urlopen('http://www.kernel.org/kdist/finger_banner').read()\"",
|
||||
10 * 1000, "kernel_process_cb", "")
|
||||
weechat.hook_process("url:http://www.kernel.org/kdist/finger_banner",
|
||||
30 * 1000, "kernel_process_cb", "")
|
||||
----------------------------------------
|
||||
|
||||
Example of URL transfer with an option: download latest WeeChat development
|
||||
package in file '/tmp/weechat-devel.tar.gz':
|
||||
|
||||
[source,python]
|
||||
----------------------------------------
|
||||
def my_process_cb(data, command, rc, out, err):
|
||||
if int(rc) >= 0:
|
||||
weechat.prnt("", "End of transfer (rc=%s)" % rc)
|
||||
return weechat.WEECHAT_RC_OK
|
||||
|
||||
weechat.hook_process_hashtable("url:http://weechat.org/files/src/weechat-devel.tar.gz",
|
||||
{ "file_out": "/tmp/weechat-devel.tar.gz" },
|
||||
30 * 1000, "my_process_cb", "")
|
||||
----------------------------------------
|
||||
|
||||
For more information about URL transfer and available options, see functions
|
||||
`hook_process` and `hook_process_hashtable` in 'WeeChat Plugin API Reference'.
|
||||
|
||||
[[config_options]]
|
||||
Config / options
|
||||
~~~~~~~~~~~~~~~~
|
||||
|
@ -662,7 +705,7 @@ SCRIPT_NAME = "myscript"
|
|||
# ...
|
||||
|
||||
def config_cb(data, option, value):
|
||||
""" Callback called when a script option is changed. """
|
||||
"""Callback called when a script option is changed."""
|
||||
# for example, read all script options to script variables...
|
||||
# ...
|
||||
return weechat.WEECHAT_RC_OK
|
||||
|
|
|
@ -619,25 +619,70 @@ positive, c'est le code retour de la commande.
|
|||
|
||||
Exemple :
|
||||
|
||||
[source,python]
|
||||
----------------------------------------
|
||||
process_output = ""
|
||||
|
||||
def my_process_cb(data, command, rc, out, err):
|
||||
global process_output
|
||||
if out != "":
|
||||
process_output += out
|
||||
if int(rc) >= 0:
|
||||
weechat.prnt("", process_output)
|
||||
return weechat.WEECHAT_RC_OK
|
||||
|
||||
weechat.hook_process("/bin/ls -l /etc", 10 * 1000, "my_process_cb", "")
|
||||
----------------------------------------
|
||||
|
||||
[[url_transfer]]
|
||||
Transfert d'URL
|
||||
^^^^^^^^^^^^^^^
|
||||
|
||||
_Nouveau dans la version 0.3.7._
|
||||
|
||||
Pour télécharger une URL (ou poster vers une URL), vous devez utiliser la
|
||||
fonction `hook_process`, ou `hook_process_hashtable` si vous avez besoin
|
||||
d'options pour le transfert d'URL.
|
||||
|
||||
Exemple de transfert d'URL sans option : la page HTML sera reçue comme "out"
|
||||
dans le "callback" (sortie standard du processus) :
|
||||
|
||||
[source,python]
|
||||
----------------------------------------
|
||||
# Afficher la version des noyaux Linux.
|
||||
kernel_txt = ""
|
||||
|
||||
def kernel_process_cb(data, command, rc, stdout, stderr):
|
||||
""" Callback qui lit la sortie de la commande. """
|
||||
def kernel_process_cb(data, command, rc, out, err):
|
||||
global kernel_txt
|
||||
if stdout != "":
|
||||
kernel_txt += stdout
|
||||
if out != "":
|
||||
kernel_txt += out
|
||||
if int(rc) >= 0:
|
||||
weechat.prnt("", kernel_txt)
|
||||
return weechat.WEECHAT_RC_OK
|
||||
|
||||
weechat.hook_process("python -c \"import urllib; "
|
||||
"print urllib.urlopen('http://www.kernel.org/kdist/finger_banner').read()\"",
|
||||
10 * 1000, "kernel_process_cb", "")
|
||||
weechat.hook_process("url:http://www.kernel.org/kdist/finger_banner",
|
||||
30 * 1000, "kernel_process_cb", "")
|
||||
----------------------------------------
|
||||
|
||||
Exemple de transfert d'URL avec une option : télécharger le dernier paquet de
|
||||
développement WeeChat dans le fichier '/tmp/weechat-devel.tar.gz' :
|
||||
|
||||
[source,python]
|
||||
----------------------------------------
|
||||
def my_process_cb(data, command, rc, out, err):
|
||||
if int(rc) >= 0:
|
||||
weechat.prnt("", "Fin du transfert (rc=%s)" % rc)
|
||||
return weechat.WEECHAT_RC_OK
|
||||
|
||||
weechat.hook_process_hashtable("url:http://weechat.org/files/src/weechat-devel.tar.gz",
|
||||
{ "file_out": "/tmp/weechat-devel.tar.gz" },
|
||||
30 * 1000, "my_process_cb", "")
|
||||
----------------------------------------
|
||||
|
||||
Pour plus d'information sur le transfert d'URL et les options disponibles, voir
|
||||
les fonctions `hook_process` et `hook_process_hashtable` dans la
|
||||
'Référence API Extension WeeChat'.
|
||||
|
||||
[[config_options]]
|
||||
Config / options
|
||||
~~~~~~~~~~~~~~~~
|
||||
|
@ -679,7 +724,7 @@ SCRIPT_NAME = "monscript"
|
|||
# ...
|
||||
|
||||
def config_cb(data, option, value):
|
||||
""" Callback appelé lorsqu'une option du script est modifiée. """
|
||||
"""Callback appelé lorsqu'une option du script est modifiée."""
|
||||
# par exemple, relire toutes les options du script dans des variables du script...
|
||||
# ...
|
||||
return weechat.WEECHAT_RC_OK
|
||||
|
|
|
@ -617,25 +617,69 @@ valore positivo, è il codice restituito dal comando.
|
|||
|
||||
Esempio:
|
||||
|
||||
[source,python]
|
||||
----------------------------------------
|
||||
process_output = ""
|
||||
|
||||
def my_process_cb(data, command, rc, out, err):
|
||||
global process_output
|
||||
if out != "":
|
||||
process_output += out
|
||||
if int(rc) >= 0:
|
||||
weechat.prnt("", process_output)
|
||||
return weechat.WEECHAT_RC_OK
|
||||
|
||||
weechat.hook_process("/bin/ls -l /etc", 10 * 1000, "my_process_cb", "")
|
||||
----------------------------------------
|
||||
|
||||
// TRANSLATION MISSING
|
||||
[[url_transfer]]
|
||||
URL transfer
|
||||
^^^^^^^^^^^^
|
||||
|
||||
_Novità nella versione 0.3.7._
|
||||
|
||||
To download URL (or post to URL), you have to use function `hook_process`, or
|
||||
`hook_process_hashtable` if you need to set options for URL transfer.
|
||||
|
||||
Example of URL transfer without option: the HTML page will be received as "out"
|
||||
in callback (standard output of process):
|
||||
|
||||
[source,python]
|
||||
----------------------------------------
|
||||
# Visualizza le versioni dei kernel di Linux.
|
||||
kernel_txt = ""
|
||||
|
||||
def kernel_process_cb(data, command, rc, stdout, stderr):
|
||||
""" Callback reading command output. """
|
||||
def kernel_process_cb(data, command, rc, out, err):
|
||||
global kernel_txt
|
||||
if stdout != "":
|
||||
kernel_txt += stdout
|
||||
if out != "":
|
||||
kernel_txt += out
|
||||
if int(rc) >= 0:
|
||||
weechat.prnt("", kernel_txt)
|
||||
return weechat.WEECHAT_RC_OK
|
||||
|
||||
weechat.hook_process("python -c \"import urllib; "
|
||||
"print urllib.urlopen('http://www.kernel.org/kdist/finger_banner').read()\"",
|
||||
10 * 1000, "kernel_process_cb", "")
|
||||
weechat.hook_process("url:http://www.kernel.org/kdist/finger_banner",
|
||||
30 * 1000, "kernel_process_cb", "")
|
||||
----------------------------------------
|
||||
|
||||
Example of URL transfer with an option: download latest WeeChat development
|
||||
package in file '/tmp/weechat-devel.tar.gz':
|
||||
|
||||
[source,python]
|
||||
----------------------------------------
|
||||
def my_process_cb(data, command, rc, out, err):
|
||||
if int(rc) >= 0:
|
||||
weechat.prnt("", "End of transfer (rc=%s)" % rc)
|
||||
return weechat.WEECHAT_RC_OK
|
||||
|
||||
weechat.hook_process_hashtable("url:http://weechat.org/files/src/weechat-devel.tar.gz",
|
||||
{ "file_out": "/tmp/weechat-devel.tar.gz" },
|
||||
30 * 1000, "my_process_cb", "")
|
||||
----------------------------------------
|
||||
|
||||
For more information about URL transfer and available options, see functions
|
||||
`hook_process` and `hook_process_hashtable` in 'WeeChat Plugin API Reference'.
|
||||
|
||||
[[config_options]]
|
||||
Configurazione / opzioni
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
@ -677,7 +721,7 @@ SCRIPT_NAME = "myscript"
|
|||
# ...
|
||||
|
||||
def config_cb(data, option, value):
|
||||
""" Callback called when a script option is changed. """
|
||||
"""Callback called when a script option is changed."""
|
||||
# for example, read all script options to script variables...
|
||||
# ...
|
||||
return weechat.WEECHAT_RC_OK
|
||||
|
|
|
@ -605,25 +605,69 @@ dodatnią, jest to kod zwracany przez komendę.
|
|||
|
||||
Przykład:
|
||||
|
||||
[source,python]
|
||||
----------------------------------------
|
||||
process_output = ""
|
||||
|
||||
def my_process_cb(data, command, rc, out, err):
|
||||
global process_output
|
||||
if out != "":
|
||||
process_output += out
|
||||
if int(rc) >= 0:
|
||||
weechat.prnt("", process_output)
|
||||
return weechat.WEECHAT_RC_OK
|
||||
|
||||
weechat.hook_process("/bin/ls -l /etc", 10 * 1000, "my_process_cb", "")
|
||||
----------------------------------------
|
||||
|
||||
// TRANSLATION MISSING
|
||||
[[url_transfer]]
|
||||
URL transfer
|
||||
^^^^^^^^^^^^
|
||||
|
||||
_Nowe w wersji 0.3.7._
|
||||
|
||||
To download URL (or post to URL), you have to use function `hook_process`, or
|
||||
`hook_process_hashtable` if you need to set options for URL transfer.
|
||||
|
||||
Example of URL transfer without option: the HTML page will be received as "out"
|
||||
in callback (standard output of process):
|
||||
|
||||
[source,python]
|
||||
----------------------------------------
|
||||
# Wyświetla wersje Linuksowych kerneli.
|
||||
kernel_txt = ""
|
||||
|
||||
def kernel_process_cb(data, command, rc, stdout, stderr):
|
||||
""" Callback reading command output. """
|
||||
def kernel_process_cb(data, command, rc, out, err):
|
||||
global kernel_txt
|
||||
if stdout != "":
|
||||
kernel_txt += stdout
|
||||
if out != "":
|
||||
kernel_txt += out
|
||||
if int(rc) >= 0:
|
||||
weechat.prnt("", kernel_txt)
|
||||
return weechat.WEECHAT_RC_OK
|
||||
|
||||
weechat.hook_process("python -c \"import urllib; "
|
||||
"print urllib.urlopen('http://www.kernel.org/kdist/finger_banner').read()\"",
|
||||
10 * 1000, "kernel_process_cb", "")
|
||||
weechat.hook_process("url:http://www.kernel.org/kdist/finger_banner",
|
||||
30 * 1000, "kernel_process_cb", "")
|
||||
----------------------------------------
|
||||
|
||||
Example of URL transfer with an option: download latest WeeChat development
|
||||
package in file '/tmp/weechat-devel.tar.gz':
|
||||
|
||||
[source,python]
|
||||
----------------------------------------
|
||||
def my_process_cb(data, command, rc, out, err):
|
||||
if int(rc) >= 0:
|
||||
weechat.prnt("", "End of transfer (rc=%s)" % rc)
|
||||
return weechat.WEECHAT_RC_OK
|
||||
|
||||
weechat.hook_process_hashtable("url:http://weechat.org/files/src/weechat-devel.tar.gz",
|
||||
{ "file_out": "/tmp/weechat-devel.tar.gz" },
|
||||
30 * 1000, "my_process_cb", "")
|
||||
----------------------------------------
|
||||
|
||||
For more information about URL transfer and available options, see functions
|
||||
`hook_process` and `hook_process_hashtable` in 'WeeChat Plugin API Reference'.
|
||||
|
||||
[[config_options]]
|
||||
Konfiguracja / opcje
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
|
@ -664,7 +708,7 @@ SCRIPT_NAME = "myscript"
|
|||
# ...
|
||||
|
||||
def config_cb(data, option, value):
|
||||
""" Callback called when a script option is changed. """
|
||||
"""Callback called when a script option is changed."""
|
||||
# na przykład, odczyt wszystkich opcji skryptu...
|
||||
# ...
|
||||
return weechat.WEECHAT_RC_OK
|
||||
|
|
Loading…
Reference in New Issue