23 | | == todo: example plugin here== |
| 23 | == Example : a df page in webui == |
| 24 | This example assumes you have deluge svn checked out to "~/src/deluge" |
| 25 | And that your plugin-development-directory is "~/prj/deluge/plugins" |
| 26 | |
| 27 | This plugin will add a page to deluge that display the output of "df -h" to a page in the webui. |
| 28 | |
| 29 | |
| 30 | === Create a new plugin === |
| 31 | {{{ |
| 32 | cd ~/prj/deluge/plugins |
| 33 | python ~/src/deluge/deluge/scripts/create_plugin.py --name Df --basepath . --author-name "My Name" --author-email "deluge@example.com" |
| 34 | }}} |
| 35 | |
| 36 | === Restart deluge(d) and enable the plugin in the gtk-ui. === |
| 37 | |
| 38 | * Add a core method. |
| 39 | Add this method to ~/prj/deluge/plugins/Df/df/core.py |
| 40 | {{{ |
| 41 | #!python |
| 42 | def export_get_df(self): |
| 43 | "returns the result of 'df -h' as a string" |
| 44 | import subprocess |
| 45 | return subprocess.call(["df","-h"]) |
| 46 | }}} |
| 47 | |
| 48 | === Test the new method. === |
| 49 | create ~/prj/deluge/plugins/df/Df/test.py ; Contents: |
| 50 | {{{ |
| 51 | #!python |
| 52 | from deluge.ui.client import sclient |
| 53 | sclient.set_core_uri() |
| 54 | |
| 55 | print sclient.df_get_df() #export method is prefixed by plugin-name. |
| 56 | }}} |
| 57 | |
| 58 | === Execute test === |
| 59 | {{{ |
| 60 | cd ~/prj/deluge/plugins/Df/df |
| 61 | killall deluged & deluged && python test.py |
| 62 | }}} |
| 63 | Fix any errors until the test outputs the desired result. |