source: deluge/ui/console/mapping.py@ 067f0c

2.0.x develop extjs4-port
Last change on this file since 067f0c was 067f0c, checked in by Andrew Resch <andrewresch@gmail.com>, 16 years ago

Start work on new Console UI .. Don't expect anything to work, cause most of it doesn't.

  • Property mode set to 100644
File size: 2.1 KB
Line 
1#!/usr/bin/env python
2#
3# mapping.py
4#
5# Copyright (C) 2008-2009 Ido Abramovich <ido.deluge@gmail.com>
6#
7# Deluge is free software.
8#
9# You may redistribute it and/or modify it under the terms of the
10# GNU General Public License, as published by the Free Software
11# Foundation; either version 3 of the License, or (at your option)
12# any later version.
13#
14# deluge is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17# See the GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with deluge. If not, write to:
21# The Free Software Foundation, Inc.,
22# 51 Franklin Street, Fifth Floor
23# Boston, MA 02110-1301, USA.
24#
25from deluge.ui.client import client
26from deluge.ui.console.main import match_torrents
27import re
28import logging
29from twisted.internet import defer
30
31_idregex = re.compile(r'^[0-9a-f]{40}$')
32
33_mapping = {}
34
35def _arg_is_id(arg):
36 return bool(_idregex.match(arg))
37
38def get_names(torrents):
39 d = defer.Deferred()
40 def _got_torrents_status(states):
41 try:
42 d.callback(list([ (tid, state['name']) for (tid, state) in states.items() ]))
43 except Exception, e:
44 print e
45 d.errback(e)
46
47 client.core.get_torrents_status({'id':torrents}, ['name']).addCallback(_got_torrents_status)
48 return d
49
50def rehash():
51 global _mapping
52 d = defer.Deferred()
53 def on_match_torrents(torrents):
54 def on_get_names(names):
55 _mapping = dict([(x[1],x[0]) for x in names])
56 d.callback()
57 get_names(torrents).addCallback(on_get_names)
58 match_torrents().addCallback(on_match_torrents)
59 return d
60
61def to_ids(args):
62 d = defer.Deferred()
63 def on_rehash(result):
64 res = []
65 for i in args:
66 if _arg_is_id(i):
67 res.append(i)
68 else:
69 if i in _mapping:
70 res.append(_mapping[i])
71 d.callback(res)
72 rehash().addCallback(on_rehash)
73
74 return d
75
76def names():
77 return _mapping.keys()
Note: See TracBrowser for help on using the repository browser.