mirror of
https://github.com/weechat/weechat.git
synced 2026-06-28 05:46:38 +02:00
script: display error when installing/removing/loading script if plugin for language is not loaded
This commit is contained in:
@@ -61,7 +61,7 @@ script_action_list ()
|
||||
|
||||
scripts_loaded = 0;
|
||||
|
||||
for (i = 0; script_language[i]; i++)
|
||||
for (i = 0; i < SCRIPT_NUM_LANGUAGES; i++)
|
||||
{
|
||||
snprintf (hdata_name, sizeof (hdata_name),
|
||||
"%s_script", script_language[i]);
|
||||
@@ -114,7 +114,7 @@ script_action_list_input (int send_to_buffer)
|
||||
buf[0] = '\0';
|
||||
length = 0;
|
||||
|
||||
for (i = 0; script_language[i]; i++)
|
||||
for (i = 0; i < SCRIPT_NUM_LANGUAGES; i++)
|
||||
{
|
||||
snprintf (hdata_name, sizeof (hdata_name),
|
||||
"%s_script", script_language[i]);
|
||||
@@ -178,6 +178,15 @@ script_action_load (const char *name, int quiet)
|
||||
return;
|
||||
}
|
||||
|
||||
/* check that plugin for this language is loaded */
|
||||
if (!script_plugin_loaded[language])
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
_("%s: plugin \"%s\" is not loaded"),
|
||||
SCRIPT_PLUGIN_NAME, script_language[language]);
|
||||
return;
|
||||
}
|
||||
|
||||
/* execute command (for example: "/perl load iset.pl") */
|
||||
snprintf (str_command, sizeof (str_command),
|
||||
"/%s load %s%s",
|
||||
@@ -260,7 +269,7 @@ script_action_unload (const char *name, int quiet)
|
||||
else
|
||||
{
|
||||
/* unload script by using name (example: "iset") */
|
||||
for (i = 0; script_language[i]; i++)
|
||||
for (i = 0; i < SCRIPT_NUM_LANGUAGES; i++)
|
||||
{
|
||||
snprintf (hdata_name, sizeof (hdata_name),
|
||||
"%s_script", script_language[i]);
|
||||
@@ -366,7 +375,7 @@ script_action_reload (const char *name, int quiet)
|
||||
else
|
||||
{
|
||||
/* reload script by using name (example: "iset") */
|
||||
for (i = 0; script_language[i]; i++)
|
||||
for (i = 0; i < SCRIPT_NUM_LANGUAGES; i++)
|
||||
{
|
||||
snprintf (hdata_name, sizeof (hdata_name),
|
||||
"%s_script", script_language[i]);
|
||||
@@ -426,7 +435,7 @@ script_action_install_process_cb (void *data, const char *command,
|
||||
{
|
||||
char *pos, *filename, *filename2, str_signal[256];
|
||||
int quiet, length;
|
||||
struct t_repo_script *ptr_script;
|
||||
struct t_script_repo *ptr_script;
|
||||
|
||||
quiet = (data) ? 1 : 0;
|
||||
|
||||
@@ -485,20 +494,19 @@ script_action_install_process_cb (void *data, const char *command,
|
||||
}
|
||||
|
||||
/*
|
||||
* script_action_install: install script(s) marked for install
|
||||
* script_action_get_next_script_to_install: get next script to install
|
||||
* according to "install_order" in
|
||||
* script
|
||||
*/
|
||||
|
||||
void
|
||||
script_action_install (int quiet)
|
||||
struct t_script_repo *
|
||||
script_action_get_next_script_to_install ()
|
||||
{
|
||||
struct t_repo_script *ptr_script, *ptr_script_to_install;
|
||||
char *filename, *url;
|
||||
int length;
|
||||
struct t_hashtable *options;
|
||||
struct t_script_repo *ptr_script, *ptr_script_to_install;
|
||||
|
||||
ptr_script_to_install = NULL;
|
||||
|
||||
for (ptr_script = repo_scripts; ptr_script;
|
||||
for (ptr_script = scripts_repo; ptr_script;
|
||||
ptr_script = ptr_script->next_script)
|
||||
{
|
||||
if (ptr_script->install_order > 0)
|
||||
@@ -509,43 +517,79 @@ script_action_install (int quiet)
|
||||
}
|
||||
}
|
||||
|
||||
if (ptr_script_to_install)
|
||||
{
|
||||
filename = script_config_get_script_download_filename (ptr_script_to_install,
|
||||
NULL);
|
||||
if (filename)
|
||||
{
|
||||
options = weechat_hashtable_new (8,
|
||||
WEECHAT_HASHTABLE_STRING,
|
||||
WEECHAT_HASHTABLE_STRING,
|
||||
NULL,
|
||||
NULL);
|
||||
if (options)
|
||||
{
|
||||
length = 4 + strlen (ptr_script_to_install->url) + 1;
|
||||
url = malloc (length);
|
||||
if (url)
|
||||
{
|
||||
if (!weechat_config_boolean (script_config_look_quiet_actions))
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
_("%s: downloading script \"%s\"..."),
|
||||
SCRIPT_PLUGIN_NAME,
|
||||
ptr_script_to_install->name_with_extension);
|
||||
}
|
||||
return ptr_script_to_install;
|
||||
}
|
||||
|
||||
snprintf (url, length, "url:%s",
|
||||
ptr_script_to_install->url);
|
||||
weechat_hashtable_set (options, "file_out", filename);
|
||||
weechat_hook_process_hashtable (url, options, 30000,
|
||||
&script_action_install_process_cb,
|
||||
(quiet) ? (void *)1 : (void *)0);
|
||||
free (url);
|
||||
/*
|
||||
* script_action_install: install script(s) marked for install
|
||||
*/
|
||||
|
||||
void
|
||||
script_action_install (int quiet)
|
||||
{
|
||||
struct t_script_repo *ptr_script_to_install;
|
||||
char *filename, *url;
|
||||
int length;
|
||||
struct t_hashtable *options;
|
||||
|
||||
while (1)
|
||||
{
|
||||
ptr_script_to_install = script_action_get_next_script_to_install ();
|
||||
|
||||
/* no more script to install? just exit function */
|
||||
if (!ptr_script_to_install)
|
||||
return;
|
||||
|
||||
/*
|
||||
* script to install and plugin is loaded: exit loop and go on with
|
||||
* install
|
||||
*/
|
||||
if (script_plugin_loaded[ptr_script_to_install->language])
|
||||
break;
|
||||
|
||||
/* plugin not loaded for language of script: display error */
|
||||
weechat_printf (NULL,
|
||||
_("%s: script \"%s\" can not be installed because "
|
||||
"plugin \"%s\" is not loaded"),
|
||||
SCRIPT_PLUGIN_NAME,
|
||||
ptr_script_to_install->name_with_extension,
|
||||
script_language[ptr_script_to_install->language]);
|
||||
}
|
||||
|
||||
filename = script_config_get_script_download_filename (ptr_script_to_install,
|
||||
NULL);
|
||||
if (filename)
|
||||
{
|
||||
options = weechat_hashtable_new (8,
|
||||
WEECHAT_HASHTABLE_STRING,
|
||||
WEECHAT_HASHTABLE_STRING,
|
||||
NULL,
|
||||
NULL);
|
||||
if (options)
|
||||
{
|
||||
length = 4 + strlen (ptr_script_to_install->url) + 1;
|
||||
url = malloc (length);
|
||||
if (url)
|
||||
{
|
||||
if (!weechat_config_boolean (script_config_look_quiet_actions))
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
_("%s: downloading script \"%s\"..."),
|
||||
SCRIPT_PLUGIN_NAME,
|
||||
ptr_script_to_install->name_with_extension);
|
||||
}
|
||||
weechat_hashtable_free (options);
|
||||
|
||||
snprintf (url, length, "url:%s",
|
||||
ptr_script_to_install->url);
|
||||
weechat_hashtable_set (options, "file_out", filename);
|
||||
weechat_hook_process_hashtable (url, options, 30000,
|
||||
&script_action_install_process_cb,
|
||||
(quiet) ? (void *)1 : (void *)0);
|
||||
free (url);
|
||||
}
|
||||
free (filename);
|
||||
weechat_hashtable_free (options);
|
||||
}
|
||||
free (filename);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -556,52 +600,12 @@ script_action_install (int quiet)
|
||||
void
|
||||
script_action_remove (const char *name, int quiet)
|
||||
{
|
||||
struct t_repo_script *ptr_script;
|
||||
struct t_script_repo *ptr_script;
|
||||
char str_signal[256], *filename;
|
||||
int length;
|
||||
|
||||
ptr_script = script_repo_search_by_name_ext (name);
|
||||
if (ptr_script)
|
||||
{
|
||||
if (!(ptr_script->status & SCRIPT_STATUS_INSTALLED))
|
||||
{
|
||||
if (!quiet)
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
_("%s: script \"%s\" is not installed"),
|
||||
SCRIPT_PLUGIN_NAME, name);
|
||||
}
|
||||
}
|
||||
else if (ptr_script->status & SCRIPT_STATUS_HELD)
|
||||
{
|
||||
if (!quiet)
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
_("%s: script \"%s\" is held"),
|
||||
SCRIPT_PLUGIN_NAME, name);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
length = 3 + strlen (ptr_script->name_with_extension) + 1;
|
||||
filename = malloc (length);
|
||||
if (filename)
|
||||
{
|
||||
snprintf (filename, length,
|
||||
"%s%s",
|
||||
(quiet && weechat_config_boolean (script_config_look_quiet_actions)) ? "-q " : "",
|
||||
ptr_script->name_with_extension);
|
||||
snprintf (str_signal, sizeof (str_signal),
|
||||
"%s_script_remove",
|
||||
script_language[ptr_script->language]);
|
||||
weechat_hook_signal_send (str_signal,
|
||||
WEECHAT_HOOK_SIGNAL_STRING,
|
||||
filename);
|
||||
free (filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
if (!ptr_script)
|
||||
{
|
||||
if (!quiet)
|
||||
{
|
||||
@@ -609,6 +613,61 @@ script_action_remove (const char *name, int quiet)
|
||||
_("%s: script \"%s\" not found"),
|
||||
SCRIPT_PLUGIN_NAME, name);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/* check that script is installed */
|
||||
if (!(ptr_script->status & SCRIPT_STATUS_INSTALLED))
|
||||
{
|
||||
if (!quiet)
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
_("%s: script \"%s\" is not installed"),
|
||||
SCRIPT_PLUGIN_NAME, name);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/* check that script is not held */
|
||||
if (ptr_script->status & SCRIPT_STATUS_HELD)
|
||||
{
|
||||
if (!quiet)
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
_("%s: script \"%s\" is held"),
|
||||
SCRIPT_PLUGIN_NAME, name);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/* check that plugin for this language is loaded */
|
||||
if (!script_plugin_loaded[ptr_script->language])
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
_("%s: script \"%s\" can not be removed "
|
||||
"because plugin \"%s\" is not loaded"),
|
||||
SCRIPT_PLUGIN_NAME,
|
||||
ptr_script->name_with_extension,
|
||||
script_language[ptr_script->language]);
|
||||
return;
|
||||
}
|
||||
|
||||
/* ask plugin to remove script */
|
||||
length = 3 + strlen (ptr_script->name_with_extension) + 1;
|
||||
filename = malloc (length);
|
||||
if (filename)
|
||||
{
|
||||
snprintf (filename, length,
|
||||
"%s%s",
|
||||
(quiet && weechat_config_boolean (script_config_look_quiet_actions)) ? "-q " : "",
|
||||
ptr_script->name_with_extension);
|
||||
snprintf (str_signal, sizeof (str_signal),
|
||||
"%s_script_remove",
|
||||
script_language[ptr_script->language]);
|
||||
weechat_hook_signal_send (str_signal,
|
||||
WEECHAT_HOOK_SIGNAL_STRING,
|
||||
filename);
|
||||
free (filename);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -620,7 +679,7 @@ script_action_remove (const char *name, int quiet)
|
||||
int
|
||||
script_action_hold (const char *name, int quiet)
|
||||
{
|
||||
struct t_repo_script *ptr_script;
|
||||
struct t_script_repo *ptr_script;
|
||||
|
||||
ptr_script = script_repo_search_by_name_ext (name);
|
||||
if (ptr_script)
|
||||
@@ -768,7 +827,7 @@ script_action_show_source_process_cb (void *data, const char *command,
|
||||
char *pos, *filename, *filename_loaded, line[4096], *ptr_line;
|
||||
char *diff_command;
|
||||
const char *ptr_diff_command;
|
||||
struct t_repo_script *ptr_script;
|
||||
struct t_script_repo *ptr_script;
|
||||
FILE *file;
|
||||
int length, diff_made;
|
||||
|
||||
@@ -898,7 +957,7 @@ script_action_show_source_process_cb (void *data, const char *command,
|
||||
void
|
||||
script_action_show (const char *name, int quiet)
|
||||
{
|
||||
struct t_repo_script *ptr_script;
|
||||
struct t_script_repo *ptr_script;
|
||||
char *filename, *url;
|
||||
int length;
|
||||
struct t_hashtable *options;
|
||||
@@ -1016,7 +1075,7 @@ script_action_run ()
|
||||
{
|
||||
char **actions, **argv, **argv_eol, *ptr_action;
|
||||
int num_actions, argc, i, j, quiet, script_found;
|
||||
struct t_repo_script *ptr_script;
|
||||
struct t_script_repo *ptr_script;
|
||||
|
||||
if (!script_actions)
|
||||
return 0;
|
||||
@@ -1204,7 +1263,7 @@ script_action_run ()
|
||||
else if (weechat_strcasecmp (argv[0], "upgrade") == 0)
|
||||
{
|
||||
script_found = 0;
|
||||
for (ptr_script = repo_scripts; ptr_script;
|
||||
for (ptr_script = scripts_repo; ptr_script;
|
||||
ptr_script = ptr_script->next_script)
|
||||
{
|
||||
/*
|
||||
@@ -1287,7 +1346,7 @@ script_action_schedule (const char *action, int need_repository, int quiet)
|
||||
{
|
||||
if (script_repo_file_is_uptodate ())
|
||||
{
|
||||
if (!repo_scripts)
|
||||
if (!scripts_repo)
|
||||
script_repo_file_read (quiet);
|
||||
script_action_run ();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user