root/cherokee/trunk/admin/Wizard_rTorrent.py @ 3609

Revision 3609, 2.7 KB (checked in by aperez, 12 months ago)

Adds a new wizard to set up XMLRPC for rTorrent.

Line 
1import validations
2from config import *
3from util import *
4from Page import *
5from Wizard import *
6
7NOTE_CONNECTION = _("Where rTorrent XMLRPC is available. The host:port pair, or the Unix socket path.")
8NOTE_WEB_DIR    = _("Web directory where you want rTorrent XMLRPC to be accessible. (Example: /RPC2)")
9
10
11CONFIG_DIR = """
12%(rule_pre_1)s!match = request
13%(rule_pre_1)s!match!request = ^%(web_dir)s
14%(rule_pre_1)s!handler = scgi
15%(rule_pre_1)s!handler!balancer = round_robin
16%(rule_pre_1)s!handler!balancer!source!1 = %(src_num)d
17"""
18
19CONFIG_SOURCE = """
20%(source)s!nick = rTorrent XMLRPC
21%(source)s!type = host
22%(source)s!host = %(connection)s
23"""
24
25
26class Wizard_Rules_rTorrent (WizardPage):
27    ICON = "rtorrent.png"
28    DESC = "Configures rTorrent XMLRPC."
29
30    def __init__ (self, cfg, pre):
31        WizardPage.__init__ (self, cfg, pre, 
32                             submit = '/vserver/%s/wizard/rTorrent'%(pre.split('!')[1]),
33                             id     = "rTorrent_Page1",
34                             title  = _("rTorrent Wizard"),
35                             group  = WIZARD_GROUP_MISC )
36
37    def show (self):
38        return True
39
40    def _render_content (self, url_pre):
41        table = TableProps()
42        self.AddPropEntry (table, _('Web Directory'),   'tmp!wizard_rTorrent!web_dir', NOTE_WEB_DIR, value="/RPC2")
43        self.AddPropEntry (table, _('Connection'),'tmp!wizard_rTorrent!connection', NOTE_CONNECTION, value="localhost:5000")
44
45        txt  = '<h1>%s</h1>' % (self.title)
46        txt += self.Indent(table)
47        form = Form (url_pre, add_submit=True, auto=False)
48        return form.Render(txt, DEFAULT_SUBMIT_VALUE)
49
50    def _op_apply (self, post):
51        # Store tmp, validate and clean up tmp
52        self._cfg_store_post (post)
53
54        self._cfg_clean_values (post)
55
56        # Incoming info
57        connection = post.pop('tmp!wizard_rTorrent!connection')
58        web_dir    = post.pop('tmp!wizard_rTorrent!web_dir')
59
60        rule = cfg_vsrv_rule_find_regexp (self._cfg, self._pre, '^'+web_dir)
61        if rule:
62            return self.report_error ("Already configured: %s" % web_dir)
63
64        # Add source
65        source = cfg_source_find_interpreter (self._cfg, None, 'rTorrent XMLRPC')
66        if not source:
67            _, source = cfg_source_get_next (self._cfg)
68            config_source = CONFIG_SOURCE % (locals())
69            self._apply_cfg_chunk (config_source)
70
71        src_num = int(source.split('!')[-1])
72
73        rule_n, _ = cfg_vsrv_rule_get_next (self._cfg, self._pre)
74        if not rule_n:
75            return self.report_error ("Couldn't add a new rule.")
76
77        rule_pre_1   = '%s!rule!%d' % (self._pre, rule_n)
78
79        # Add the new rules
80        config_dir    = CONFIG_DIR % (locals())
81
82        self._apply_cfg_chunk (config_dir)
Note: See TracBrowser for help on using the browser.