Changes between Version 15 and Version 16 of Development/Plugins/Demo1


Ignore:
Timestamp:
07/25/2008 04:24:05 PM (13 years ago)
Author:
mvoncken
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Development/Plugins/Demo1

    v15 v16  
    1 ['Development/Plugins'] 
    2  
    3 = Plugins Demo1 =  
    4  
    5  
    6 ''I'm writing these docs while trying to create my first plugin. 
    7 And it's easiest to write docs the when you've never done something before. 
    8 these docs will not follow best practices because of lack of experience'' 
    9  
    10 = Purpose = 
    11  
    12 Creating a basic plugin. 
    13  
    14 This plugin adds a status-field and a setter to the core. 
    15  
    16 It does not save the state,and all information is lost after a restart of the daemon. 
    17  
    18 Test code: 
    19 {{{ 
    20 from deluge.ui.client import sclient 
    21 sclient.set_core_uri() 
    22 id = sclient.get_session_state()[0] #1st torrent 
    23  
    24 print "before:",id, sclient.get_torrent_status(id, ['name','label']) 
    25  
    26 sclient.label_set_label(id,'') 
    27 print "after reset:",sclient.get_torrent_status(id, ['name','label']) 
    28  
    29 sclient.label_set_label(id,'movie') 
    30 print "after set:",sclient.get_torrent_status(id, ['name','label']) 
    31 }}} 
    32  
    33 Result: 
    34 {{{ 
    35 before: f2b609578473f6a29d3123ba0897213b3c1bbcda {'name': 'aesmsclient_0.2.1.jar', 'label': ''} 
    36 after reset: {'name': 'aesmsclient_0.2.1.jar', 'label': ''} 
    37 after set: {'name': 'aesmsclient_0.2.1.jar', 'label': 'movie'} 
    38 }}} 
    39  
    40 = Plugin Core Code =  
    41 core.py: 
    42 {{{ 
    43 # 
    44 # a simple plugin with memory-loss 
    45 # adds a status-field,does not remember settings after restart of daemon. 
    46  
    47 from deluge.log import LOG as log 
    48 from deluge.plugins.corepluginbase import CorePluginBase 
    49  
    50 class Core(CorePluginBase):     
    51     def enable(self): 
    52         log.debug("*** START , HI!!!***") 
    53         self.labels = {} 
    54         # Register the 'label' status field 
    55         self.plugin.register_status_field("label", self._get_label)         
    56         log.debug("Label plugin enabled..") 
    57      
    58     def disable(self): 
    59         # De-register the label field 
    60         self.plugin.deregister_status_field("label") 
    61  
    62     def update(self): 
    63         pass 
    64              
    65     ## Status field function ## 
    66     def _get_label(self, torrent_id): 
    67         #return label or empty string. 
    68         return self.labels.get(torrent_id, '') 
    69          
    70     ## Setter ## 
    71     def export_set_label(self, torrent_id, label): 
    72         log.debug("set label %s=%s" % (torrent_id, label)) 
    73         self.labels[torrent_id] = str(label) 
    74 }}} 
    75  
    76 = Notes = 
    77  
    78  * all methods starting with export_ are available in s/aclient prefixed by the plugin-name (export_set_label-->sclient.label_set_label).  
    79  * self.plugin.register_status_field/self.plugin.register_status_field add fields to s/aclient.get_torrent_status. 
    80  * the enable, disable and update methods are called by the core. 
    81  
    82  
    83 = eggs = 
    84  
    85 The good and bad news about deluge 0.6 plugins is that it uses eggs.  
    86 Deployment of eggs is easy, but they do need some meta-data. 
    87  
    88 We're not addressing deployment now, python-eggs allow directory based development too. And IMHO it's easier to develop with directory's than with zipped eggs. 
    89  
    90  
    91 ''an example is linked at the bottom of this page. 
    92  
    93 Minimal structure of a deluge plugin directory: 
    94  
    95 '''Place name.egg in ~/.config/deluge/plugins'' 
    96 {{{ 
    97 name.egg/ 
    98 name.egg/EGG-INFO 
    99 name.egg/EGG-INFO/PKG_INFO 
    100 name.egg/EGG-INFO/entry_points.txt 
    101 name.egg/name/ 
    102 name.egg/name/__init__.py 
    103 name.egg/name/core.py 
    104 }}} 
    105  
    106 = Meta data = 
    107 PKG_INFO: 
    108 {{{ 
    109 Metadata-Version: 1.0 
    110 Name: label 
    111 Version: 0.1 
    112 Summary: Deluge Label Plugin 
    113 Home-page: http://deluge-torrent.org 
    114 Author: Your Name 
    115 Author-email: your@email.com 
    116 License: GPLv2 
    117 Description: UNKNOWN 
    118 Platform: UNKNOWN 
    119 }}} 
    120 entry_points.txt: 
    121 {{{ 
    122 [deluge.plugin.core] 
    123 Label = label:CorePlugin 
    124 }}} 
    125 _ _init_ _.py: 
    126 {{{ 
    127 from deluge.log import LOG as log 
    128  
    129 from deluge.plugins.init import PluginBase 
    130  
    131 class CorePlugin(PluginBase): 
    132     def __init__(self, plugin_api, plugin_name): 
    133         # Load the Core portion of the plugin 
    134         try: 
    135             from core import Core 
    136             self.plugin = Core(plugin_api, plugin_name) 
    137         except Exception, e: 
    138             log.debug("Did not load a Core plugin: %s", e) 
    139 }}} 
    140  
    141