From 3159824789472db8e235340b74bdab3b3cb735c9 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 1 Sep 2013 16:57:40 +0100 Subject: [PATCH] Use XDG_DATA for plugins location Removed plugins, now kept in separate reposutory profanity-plugins --- plugins/ChatStart.rb | 14 ---- plugins/RubyTest.rb | 53 --------------- plugins/ascii.py | 12 ---- plugins/browser.py | 60 ----------------- plugins/connect.py | 9 --- plugins/cricket-score.py | 97 --------------------------- plugins/platform-info.py | 9 --- plugins/python-test.py | 40 ----------- plugins/test-c-plugin/Makefile | 11 --- plugins/test-c-plugin/test-c-plugin.c | 91 ------------------------- plugins/whoami.py | 9 --- src/plugins/c_plugins.c | 6 +- src/plugins/plugins.c | 14 ++++ src/plugins/plugins.h | 1 + src/plugins/python_plugins.c | 6 +- src/plugins/ruby_plugins.c | 5 +- src/profanity.c | 6 ++ 17 files changed, 34 insertions(+), 409 deletions(-) delete mode 100644 plugins/ChatStart.rb delete mode 100644 plugins/RubyTest.rb delete mode 100644 plugins/ascii.py delete mode 100644 plugins/browser.py delete mode 100644 plugins/connect.py delete mode 100644 plugins/cricket-score.py delete mode 100644 plugins/platform-info.py delete mode 100644 plugins/python-test.py delete mode 100644 plugins/test-c-plugin/Makefile delete mode 100644 plugins/test-c-plugin/test-c-plugin.c delete mode 100644 plugins/whoami.py diff --git a/plugins/ChatStart.rb b/plugins/ChatStart.rb deleted file mode 100644 index 3d77270f..00000000 --- a/plugins/ChatStart.rb +++ /dev/null @@ -1,14 +0,0 @@ -module ChatStart - - @@contacts = [ - "\"Prof 2\"", - "prof3@panesar" - ] - - def self.prof_on_connect() - @@contacts.each { | contact | - Prof::send_line("/msg " + contact) - } - Prof::send_line("/win 1") - end -end diff --git a/plugins/RubyTest.rb b/plugins/RubyTest.rb deleted file mode 100644 index 0444af47..00000000 --- a/plugins/RubyTest.rb +++ /dev/null @@ -1,53 +0,0 @@ -module RubyTest - - def self.prof_init(version, status) - Prof::cons_show("RubyTest: init, " + version + ", " + status) - Prof::register_command("/ruby", 0, 1, "/ruby", "RubyTest", "RubyTest", cmd_ruby) - Prof::register_timed(timer_test, 10) - end - - def self.prof_on_start() - Prof::cons_show("RubyTest: on_start") - end - - def self.prof_on_connect(account_name, fulljid) - Prof::cons_show("RubyTest: on_connect, " + account_name + ", " + fulljid) - end - - def self.prof_on_message_received(jid, message) - Prof::cons_show("RubyTest: on_message_received, " + jid + ", " + message) - Prof::cons_alert - return message + "[RUBY]" - end - - def self.prof_on_message_send(jid, message) - Prof::cons_show("RubyTest: on_message_send, " + jid + ", " + message) - Prof::cons_alert - return message + "[RUBY]" - end - - def self.cmd_ruby() - return Proc.new { | msg | - if msg - Prof::cons_show("RubyTest: /ruby command called, arg = " + msg) - else - Prof::cons_show("RubyTest: /ruby command called with no arg") - end - Prof::cons_alert - Prof::notify("RubyTest: notify", 2000, "Plugins") - Prof::send_line("/help") - Prof::cons_show("RubyTest: sent \"/help\" command") - } - end - - def self.timer_test() - return Proc.new { - Prof::cons_show("RubyTest: timer fired.") - recipient = Prof::get_current_recipient - if recipient - Prof::cons_show(" current recipient = " + recipient) - end - Prof::cons_alert - } - end -end diff --git a/plugins/ascii.py b/plugins/ascii.py deleted file mode 100644 index e37ed106..00000000 --- a/plugins/ascii.py +++ /dev/null @@ -1,12 +0,0 @@ -import prof -import subprocess - -def prof_init(version, status): - prof.register_command("/ascii", 1, 1, "/ascii", "ASCIIfy a message", "ASCIIfy a message.", cmd_ascii) - -def cmd_ascii(text): - recipient = prof.get_current_recipient() - if recipient: - proc = subprocess.Popen(['figlet', '--', text], stdout=subprocess.PIPE) - ascii_out = proc.communicate()[0].decode('utf-8') - prof.send_line(u'\u000A' + ascii_out) diff --git a/plugins/browser.py b/plugins/browser.py deleted file mode 100644 index 5dab73d2..00000000 --- a/plugins/browser.py +++ /dev/null @@ -1,60 +0,0 @@ -import prof -import os -import webbrowser -import re - -lastlink = {} - -def prof_init(version, status): - prof.register_command("/browser", 0, 1, - "/browser [url]", - "View a URL in the browser.", - "View a URL in the browser, if no argument is supplied, " + - "the last received URL will be used.", - cmd_browser) - -def prof_on_message_received(jid, message): - global lastlink - links = re.findall(r'(https?://\S+)', message) - if (len(links) > 0): - lastlink[jid] = links[len(links)-1] - -def cmd_browser(url): - global lastlink - link = None - - # use arg if supplied - if (url != None): - link = url - else: - jid = prof.get_current_recipient(); - - # check if in chat window - if (jid != None): - - # check for link from recipient - if jid in lastlink.keys(): - link = lastlink[jid] - else: - prof.cons_show("No links found from " + jid); - - # not in chat window - else: - prof.cons_show("You must supply a URL to the /browser command") - - # open the browser if link found - if (link != None): - prof.cons_show("Opening " + link + " in browser") - open_browser(link) - -def open_browser(url): - savout = os.dup(1) - saverr = os.dup(2) - os.close(1) - os.close(2) - os.open(os.devnull, os.O_RDWR) - try: - webbrowser.open(url, new=2) - finally: - os.dup2(savout, 1) - os.dup2(saverr, 2) diff --git a/plugins/connect.py b/plugins/connect.py deleted file mode 100644 index 2741cb9d..00000000 --- a/plugins/connect.py +++ /dev/null @@ -1,9 +0,0 @@ -import prof - -user = "prof1@panesar" - -def prof_on_start(): - global user - prof.cons_show("") - prof.cons_show("Enter password for " + user) - prof.send_line("/connect " + user) diff --git a/plugins/cricket-score.py b/plugins/cricket-score.py deleted file mode 100644 index 125af838..00000000 --- a/plugins/cricket-score.py +++ /dev/null @@ -1,97 +0,0 @@ -import prof -import urllib2 -import json - -#score_url = "http://api.scorescard.com/?type=score&teamone=Australia&teamtwo=England" -score_url = None - -summary = None - -def prof_init(version, status): - if score_url: - prof.register_timed(get_scores, 60) - prof.register_command("/cricket", 0, 0, - "/cricket", - "Get latest cricket score.", - "Get latest cricket score.", - cmd_cricket) - -def prof_on_start(): - if score_url: - get_scores() - -def cmd_cricket(): - global score_url - global summary - new_summary = None - - result_json = retrieve_scores_json() - - if 'ms' in result_json.keys(): - new_summary = result_json['ms'] - - prof.cons_show("") - prof.cons_show("Cricket score:") - if 't1FI' in result_json.keys(): - prof.cons_show(" " + result_json['t1FI']) - - if 't2FI' in result_json.keys(): - prof.cons_show(" " + result_json['t2FI']) - - if 't1SI' in result_json.keys(): - prof.cons_show(" " + result_json['t1SI']) - - if 't2SI' in result_json.keys(): - prof.cons_show(" " + result_json['t2SI']) - - summary = new_summary - prof.cons_show("") - prof.cons_show(" " + summary) - prof.cons_alert() - -def get_scores(): - global score_url - global summary - notify = None - new_summary = None - change = False - - result_json = retrieve_scores_json() - - if 'ms' in result_json.keys(): - new_summary = result_json['ms'] - if new_summary != summary: - change = True - - if change: - prof.cons_show("") - prof.cons_show("Cricket score:") - if 't1FI' in result_json.keys(): - notify = result_json['t1FI'] - prof.cons_show(" " + result_json['t1FI']) - - if 't2FI' in result_json.keys(): - notify += "\n" + result_json['t2FI'] - prof.cons_show(" " + result_json['t2FI']) - - if 't1SI' in result_json.keys(): - notify += "\n" + result_json['t1SI'] - prof.cons_show(" " + result_json['t1SI']) - - if 't2SI' in result_json.keys(): - notify += "\n" + result_json['t2SI'] - prof.cons_show(" " + result_json['t2SI']) - - summary = new_summary - notify += "\n\n" + summary - prof.cons_show("") - prof.cons_show(" " + summary) - prof.cons_alert() - prof.notify(notify, 5000, "Cricket score") - -def retrieve_scores_json(): - req = urllib2.Request(score_url, None, {'Content-Type': 'application/json'}) - f = urllib2.urlopen(req) - response = f.read() - f.close() - return json.loads(response); diff --git a/plugins/platform-info.py b/plugins/platform-info.py deleted file mode 100644 index 8132c39f..00000000 --- a/plugins/platform-info.py +++ /dev/null @@ -1,9 +0,0 @@ -import prof -import platform - -def prof_init(version, status): - prof.register_command("/platform", 0, 0, "/platform", "Output system information.", "Output system information", cmd_platform) - -def cmd_platform(): - result_summary = platform.platform() - prof.cons_show(result_summary) diff --git a/plugins/python-test.py b/plugins/python-test.py deleted file mode 100644 index 97fd9792..00000000 --- a/plugins/python-test.py +++ /dev/null @@ -1,40 +0,0 @@ -import prof - -def prof_init(version, status): - prof.cons_show("python-test: init, " + version + ", " + status) - prof.register_command("/python", 0, 1, "/python", "python-test", "python-test", cmd_python) - prof.register_timed(timer_test, 10) - -def prof_on_start(): - prof.cons_show("python-test: on_start") - -def prof_on_connect(account_name, fulljid): - prof.cons_show("python-test: on_connect, " + account_name + ", " + fulljid) - -def prof_on_message_received(jid, message): - prof.cons_show("python-test: on_message_received, " + jid + ", " + message) - prof.cons_alert() - return message + "[PYTHON]" - -def prof_on_message_send(jid, message): - prof.cons_show("python-test: on_message_send, " + jid + ", " + message) - prof.cons_alert() - return message + "[PYTHON]" - -def cmd_python(msg): - if msg: - prof.cons_show("python-test: /python command called, arg = " + msg) - else: - prof.cons_show("python-test: /python command called with no arg") - prof.cons_alert() - prof.notify("python-test: notify", 2000, "Plugins") - prof.send_line("/vercheck") - prof.cons_show("python-test: sent \"/vercheck\" command") - -def timer_test(): - prof.cons_show("python-test: timer fired.") - recipient = prof.get_current_recipient() - if recipient: - prof.cons_show(" current recipient = " + recipient) - prof.cons_alert() - diff --git a/plugins/test-c-plugin/Makefile b/plugins/test-c-plugin/Makefile deleted file mode 100644 index 66ae3e66..00000000 --- a/plugins/test-c-plugin/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -all: test-c-plugin.so - -%.so:%.o - $(CC) -shared -fpic -lprofanity -o $@ $^ - -%.o:%.c - $(CC) $(INCLUDE) -D_GNU_SOURCE -D_BSD_SOURCE -fpic -O3 -std=c99 \ - -Wall -Wextra -lprofanity -pedantic -c -o $@ $< - -clean: - $(RM) test-c-plugin.so diff --git a/plugins/test-c-plugin/test-c-plugin.c b/plugins/test-c-plugin/test-c-plugin.c deleted file mode 100644 index 852fcb3f..00000000 --- a/plugins/test-c-plugin/test-c-plugin.c +++ /dev/null @@ -1,91 +0,0 @@ -#include -#include -#include -#include - -#include - -void -cmd_c(char **args) -{ - if (args[0] != NULL) { - char *start = "c-test: /c command called, arg = "; - char buf[strlen(start) + strlen(args[0]) + 1]; - sprintf(buf, "%s%s", start, args[0]); - prof_cons_show(buf); - } else { - prof_cons_show("c-test: /c command called with no arg"); - } - prof_cons_alert(); - prof_notify("c-test: notify", 2000, "Plugins"); - prof_send_line("/about"); - prof_cons_show("c-test: sent \"/about\" command"); -} - -void -timer_test(void) -{ - prof_cons_show("c-test: timer fired."); - char *recipient = prof_get_current_recipient(); - if (recipient != NULL) { - char *start = " current recipient = "; - char buf[strlen(start) + strlen(recipient) + 1]; - sprintf(buf, "%s%s", start, recipient); - prof_cons_show(buf); - } - prof_cons_alert(); -} - -void -prof_init(const char * const version, const char * const status) -{ - char *start = "c-test: init. "; - char buf[strlen(start) + strlen(version) + 2 + strlen(status) + 1]; - sprintf(buf, "%s%s, %s", start, version, status); - prof_cons_show(buf); - prof_register_command("/c", 0, 1, "/c", "c test", "c test", cmd_c); - prof_register_timed(timer_test, 10); -} - -void -prof_on_start(void) -{ - prof_cons_show("c-test: on_start"); -} - -void -prof_on_connect(const char * const account_name, const char * const fulljid) -{ - char *start = "c-test: on_connect, "; - char buf[strlen(start) + strlen(account_name) + 2 + strlen(fulljid) + 1]; - sprintf(buf, "%s%s, %s", start, account_name, fulljid); - prof_cons_show(buf); -} - -char * -prof_on_message_received(const char * const jid, const char *message) -{ - char *start = "c-test: on_message_received, "; - char buf[strlen(start) + strlen(jid) + 2 + strlen(message) + 1]; - sprintf(buf, "%s%s, %s", start, jid, message); - prof_cons_show(buf); - prof_cons_alert(); - char *result = malloc(strlen(message) + 4); - sprintf(result, "%s%s", message, "[C]"); - - return result; -} - -char * -prof_on_message_send(const char * const jid, const char *message) -{ - char *start = "c-test: on_message_send, "; - char buf[strlen(start) + strlen(jid) + 2 + strlen(message) + 1]; - sprintf(buf, "%s%s, %s", start, jid, message); - prof_cons_show(buf); - prof_cons_alert(); - char *result = malloc(strlen(message) + 4); - sprintf(result, "%s%s", message, "[C]"); - - return result; -} diff --git a/plugins/whoami.py b/plugins/whoami.py deleted file mode 100644 index 9d1b8aa4..00000000 --- a/plugins/whoami.py +++ /dev/null @@ -1,9 +0,0 @@ -import prof -import getpass - -def prof_init(version, status): - prof.register_command("/whoami", 0, 0, "/whoami", "Call shell whoami command.", "Call shell whoami command.", cmd_whoami) - -def cmd_whoami(): - me = getpass.getuser() - prof.cons_show(me) diff --git a/src/plugins/c_plugins.c b/src/plugins/c_plugins.c index e6a8ee59..f998582c 100644 --- a/src/plugins/c_plugins.c +++ b/src/plugins/c_plugins.c @@ -26,8 +26,10 @@ c_plugin_create(const char * const filename) ProfPlugin *plugin; void *handle = NULL; - // TODO use XDG for path - GString *path = g_string_new("./plugins/"); + gchar *plugins_dir = plugins_get_dir(); + GString *path = g_string_new(plugins_dir); + g_free(plugins_dir); + g_string_append(path, "/"); g_string_append(path, filename); handle = dlopen (path->str, RTLD_NOW | RTLD_GLOBAL); diff --git a/src/plugins/plugins.c b/src/plugins/plugins.c index 429ed406..1364f24a 100644 --- a/src/plugins/plugins.c +++ b/src/plugins/plugins.c @@ -23,6 +23,7 @@ #include #include +#include "common.h" #include "config/preferences.h" #include "log.h" #include "plugins/callbacks.h" @@ -173,3 +174,16 @@ plugins_shutdown(void) curr = g_slist_next(curr); } } + +gchar * +plugins_get_dir(void) +{ + gchar *xdg_data = xdg_get_data_home(); + GString *plugins_dir = g_string_new(xdg_data); + g_string_append(plugins_dir, "/profanity/plugins"); + gchar *result = strdup(plugins_dir->str); + g_free(xdg_data); + g_string_free(plugins_dir, TRUE); + + return result; +} diff --git a/src/plugins/plugins.h b/src/plugins/plugins.h index 09959817..1a0b3857 100644 --- a/src/plugins/plugins.h +++ b/src/plugins/plugins.h @@ -52,5 +52,6 @@ char * plugins_on_message_send(const char * const jid, const char *message); void plugins_shutdown(void); gboolean plugins_run_command(const char * const cmd); void plugins_run_timed(void); +gchar * plugins_get_dir(void); #endif diff --git a/src/plugins/python_plugins.c b/src/plugins/python_plugins.c index f807255b..f6c49903 100644 --- a/src/plugins/python_plugins.c +++ b/src/plugins/python_plugins.c @@ -39,7 +39,11 @@ python_env_init(void) python_check_error(); // TODO change to use XDG spec GString *path = g_string_new(Py_GetPath()); - g_string_append(path, ":./plugins/"); + g_string_append(path, ":"); + gchar *plugins_dir = plugins_get_dir(); + g_string_append(path, plugins_dir); + g_string_append(path, "/"); + g_free(plugins_dir); PySys_SetPath(path->str); python_check_error(); g_string_free(path, TRUE); diff --git a/src/plugins/ruby_plugins.c b/src/plugins/ruby_plugins.c index d9dd1780..82230f99 100644 --- a/src/plugins/ruby_plugins.c +++ b/src/plugins/ruby_plugins.c @@ -44,7 +44,10 @@ ruby_env_init(void) ProfPlugin * ruby_plugin_create(const char * const filename) { - GString *path = g_string_new("./plugins/"); + gchar *plugins_dir = plugins_get_dir(); + GString *path = g_string_new(plugins_dir); + g_free(plugins_dir); + g_string_append(path, "/"); g_string_append(path, filename); rb_require(path->str); gchar *module_name = g_strndup(filename, strlen(filename) - 3); diff --git a/src/profanity.c b/src/profanity.c index 9f5b9497..41466db3 100644 --- a/src/profanity.c +++ b/src/profanity.c @@ -680,6 +680,8 @@ _create_directories(void) g_string_append(chatlogs_dir, "/profanity/chatlogs"); GString *logs_dir = g_string_new(xdg_data); g_string_append(logs_dir, "/profanity/logs"); + GString *plugins_dir = g_string_new(xdg_data); + g_string_append(plugins_dir, "/profanity/plugins"); if (!mkdir_recursive(themes_dir->str)) { log_error("Error while creating directory %s", themes_dir->str); @@ -690,10 +692,14 @@ _create_directories(void) if (!mkdir_recursive(logs_dir->str)) { log_error("Error while creating directory %s", logs_dir->str); } + if (!mkdir_recursive(plugins_dir->str)) { + log_error("Error while creating directory %s", plugins_dir->str); + } g_string_free(themes_dir, TRUE); g_string_free(chatlogs_dir, TRUE); g_string_free(logs_dir, TRUE); + g_string_free(plugins_dir, TRUE); g_free(xdg_config); g_free(xdg_data);