about summary refs log tree commit diff stats
path: root/src/command/cmd_funcs.c
diff options
context:
space:
mode:
authorPhilip Flohr <philip.flohr@student.kit.edu>2018-05-07 20:57:32 +0200
committerDmitry Podgorny <pasis.ua@gmail.com>2018-09-06 19:28:02 +0300
commita5a7db9e2b63c5748dea312d23aafbb89d660667 (patch)
tree798e5c4950753a4a5ebd2ce1c2531aa6501f66c9 /src/command/cmd_funcs.c
parentcd86f5bc288872ae8050c6f56515d4b8a5c77475 (diff)
downloadprofani-tty-a5a7db9e2b63c5748dea312d23aafbb89d660667.tar.gz
implemented plugin updates
Diffstat (limited to 'src/command/cmd_funcs.c')
-rw-r--r--src/command/cmd_funcs.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c
index 6aae8fb2..fa675309 100644
--- a/src/command/cmd_funcs.c
+++ b/src/command/cmd_funcs.c
@@ -6664,6 +6664,64 @@ 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);
+        gboolean result = plugins_unload(plugin_name);
+        result |= plugins_uninstall(plugin_name);
+        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. %s", plugin_name, error_message->str);
+        }
+        g_free(plugin_name);
+
+        free(path);
+        return TRUE;
+    }
+
+    if (is_dir(path)) {
+        return FALSE;
+    }
+
+    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) {