root/galaxy-central/eggs/twill-0.9-py2.6.egg/twill/extensions/mailman_sf.py

リビジョン 3, 1.4 KB (コミッタ: kohda, 14 年 前)

Install Unix tools  http://hannonlab.cshl.edu/galaxy_unix_tools/galaxy.html

行番号 
1"""
2Extension functions to discard all moderated messages in a SourceForge-based
3mailman queue.
4
5(Currently there is no way to do this without manually selecting 'discard'
6for each and every message.)
7"""
8
9import twill, twill.utils
10import re
11
12# export:
13__all__ = ['discard_all_messages',
14           'exit_if_empty'
15           ]
16
17def exit_if_empty():
18    """
19    >> exit_if_empty
20
21    Exit the script currently running, if there are no deferred messages
22    on the current page.
23    """
24    state = twill.get_browser()
25    form = state.get_form("1")
26    if not form:
27        print "No messages; exiting."
28        raise SystemExit
29   
30def discard_all_messages():
31    """
32    >> discard_all_messages
33
34    Set all buttons to "discard".
35    """
36    _formvalue_by_regexp_setall("1", "^\d+$", "3")
37
38### utility functions
39
40def _formvalue_by_regexp_setall(formname, fieldname, value):
41    state = twill.get_browser()
42   
43    form = state.get_form(formname)
44    if not form:
45        print 'no such form', formname
46        return
47
48    regexp = re.compile(fieldname)
49
50    matches = [ ctl for ctl in form.controls if regexp.search(str(ctl.name)) ]
51
52    if matches:
53        print '-- matches %d' % (len(matches),)
54
55        n = 0
56        for control in matches:
57            state.clicked(form, control)
58            if control.readonly:
59                continue
60
61            n += 1
62            twill.utils.set_form_control_value(control, value)
63
64        print 'set %d values total' % (n,)
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。