diff options
Diffstat (limited to 'src/command')
-rw-r--r-- | src/command/cmd_defs.c | 10 | ||||
-rw-r--r-- | src/command/cmd_funcs.c | 89 | ||||
-rw-r--r-- | src/command/cmd_funcs.h | 2 |
3 files changed, 97 insertions, 4 deletions
diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index 418155c4..ee320e84 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -424,7 +424,7 @@ static struct cmd_t command_defs[] = "View, add to, and remove from roster groups. " "Passing no argument will list all roster groups.") CMD_ARGS( - { "show <group>", "List all roster items a group." }, + { "show <group>", "List all roster items in a group." }, { "add <group> <contact>", "Add a contact to a group." }, { "remove <group> <contact>", "Remove a contact from a group." }) CMD_EXAMPLES( @@ -2084,6 +2084,8 @@ static struct cmd_t command_defs[] = CMD_SUBFUNCS( { "sourcepath", cmd_plugins_sourcepath }, { "install", cmd_plugins_install }, + { "uninstall", cmd_plugins_uninstall }, + { "update", cmd_plugins_update }, { "load", cmd_plugins_load }, { "unload", cmd_plugins_unload }, { "reload", cmd_plugins_reload }, @@ -2095,6 +2097,8 @@ static struct cmd_t command_defs[] = "/plugins sourcepath set <path>", "/plugins sourcepath clear", "/plugins install [<path>]", + "/plugins uninstall [<plugin>]", + "/plugins update [<path>]", "/plugins unload [<plugin>]", "/plugins load [<plugin>]", "/plugins reload [<plugin>]", @@ -2105,6 +2109,8 @@ static struct cmd_t command_defs[] = { "sourcepath set <path>", "Set the default path to install plugins from, will be used if no arg is passed to /plugins install." }, { "sourcepath clear", "Clear the default plugins source path." }, { "install [<path>]", "Install a plugin, or all plugins found in a directory (recursive). Passing no argument will use the sourcepath if one is set." }, + { "uninstall [<plugin>]", "Uninstall a plugin." }, + { "update [<path>]", "Updates an installed plugin" }, { "load [<plugin>]", "Load a plugin that already exists in the plugin directory, passing no argument loads all found plugins." }, { "unload [<plugin>]", "Unload a loaded plugin, passing no argument will unload all plugins." }, { "reload [<plugin>]", "Reload a plugin, passing no argument will reload all plugins." }, @@ -2113,6 +2119,8 @@ static struct cmd_t command_defs[] = "/plugins sourcepath set /home/meee/projects/profanity-plugins", "/plugins install", "/plugins install /home/steveharris/Downloads/metal.py", + "/plugins update /home/steveharris/Downloads/metal.py", + "/plugins uninstall browser.py", "/plugins load browser.py", "/plugins unload say.py", "/plugins reload wikipedia.py") diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index c8aa22b4..9cc7b881 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -6616,15 +6616,16 @@ cmd_plugins_install(ProfWin *window, const char *const command, gchar **args) return TRUE; } + GString* error_message = g_string_new(NULL); gchar *plugin_name = g_path_get_basename(path); - gboolean result = plugins_install(plugin_name, path); + gboolean result = plugins_install(plugin_name, path, error_message); if (result) { cons_show("Plugin installed: %s", plugin_name); } else { - cons_show("Failed to install plugin: %s", plugin_name); + cons_show("Failed to install plugin: %s. %s", plugin_name, error_message->str); } g_free(plugin_name); - + g_string_free(error_message, TRUE); free(path); return TRUE; } @@ -6663,6 +6664,88 @@ cmd_plugins_install(ProfWin *window, const char *const command, gchar **args) } gboolean +cmd_plugins_update(ProfWin *window, const char *const command, gchar **args) +{ + char *path = args[1]; + if (path == NULL) { + char* sourcepath = prefs_get_string(PREF_PLUGINS_SOURCEPATH); + if (sourcepath) { + path = strdup(sourcepath); + prefs_free_string(sourcepath); + } else { + cons_show("Either a path must be provided or the sourcepath property must be set, see /help plugins"); + return TRUE; + } + } else if (path[0] == '~' && path[1] == '/') { + if (asprintf(&path, "%s/%s", getenv("HOME"), path+2) == -1) { + return TRUE; + } + } else { + path = strdup(path); + } + + if (access(path, R_OK) != 0) { + cons_show("File not found: %s", path); + free(path); + return TRUE; + } + + if (is_regular_file(path)) { + if (!g_str_has_suffix(path, ".py") && !g_str_has_suffix(path, ".so")) { + cons_show("Plugins must have one of the following extensions: '.py' '.so'"); + free(path); + return TRUE; + } + + GString* error_message = g_string_new(NULL); + gchar *plugin_name = g_path_get_basename(path); + if (plugins_unload(plugin_name)) { + if (plugins_uninstall(plugin_name)) { + if (plugins_install(plugin_name, path, error_message)) { + cons_show("Plugin installed: %s", plugin_name); + } else { + cons_show("Failed to install plugin: %s. %s", plugin_name, error_message->str); + } + } else { + cons_show("Failed to uninstall plugin: %s.", plugin_name); + } + } else { + cons_show("Failed to unload plugin: %s.", plugin_name); + } + g_free(plugin_name); + g_string_free(error_message, TRUE); + free(path); + return TRUE; + } + + if (is_dir(path)) { + free(path); + return FALSE; + } + + free(path); + cons_show("Argument must be a file or directory."); + return TRUE; +} + +gboolean +cmd_plugins_uninstall(ProfWin *window, const char *const command, gchar **args) +{ + if (args[1] == NULL) { + return FALSE; + } + + gboolean res = plugins_uninstall(args[1]); + if (res) { + cons_show("Uninstalled plugin: %s", args[1]); + } else { + cons_show("Failed to uninstall plugin: %s", args[1]); + } + + return TRUE; +} + +gboolean cmd_plugins_load(ProfWin *window, const char *const command, gchar **args) { if (args[1] == NULL) { diff --git a/src/command/cmd_funcs.h b/src/command/cmd_funcs.h index 0bbf338e..f4933d44 100644 --- a/src/command/cmd_funcs.h +++ b/src/command/cmd_funcs.h @@ -162,6 +162,8 @@ gboolean cmd_console(ProfWin *window, const char *const command, gchar **args); gboolean cmd_plugins(ProfWin *window, const char *const command, gchar **args); gboolean cmd_plugins_sourcepath(ProfWin *window, const char *const command, gchar **args); gboolean cmd_plugins_install(ProfWin *window, const char *const command, gchar **args); +gboolean cmd_plugins_update(ProfWin *window, const char *const command, gchar **args); +gboolean cmd_plugins_uninstall(ProfWin *window, const char *const command, gchar **args); gboolean cmd_plugins_load(ProfWin *window, const char *const command, gchar **args); gboolean cmd_plugins_unload(ProfWin *window, const char *const command, gchar **args); gboolean cmd_plugins_reload(ProfWin *window, const char *const command, gchar **args); |