Revision 1825,
1.4 KB
checked in by iwaim, 14 years ago
(diff) |
trac wiki macro: VineBTS: initial release
|
Line | |
---|
1 | import re |
---|
2 | from trac.wiki.macros import WikiMacroBase |
---|
3 | |
---|
4 | class VineBTSMacro(WikiMacroBase): |
---|
5 | |
---|
6 | def expand_macro(self, formatter, name, content): |
---|
7 | if not content: |
---|
8 | return '' |
---|
9 | |
---|
10 | base_url = 'http://bts.vinelinux.org/' |
---|
11 | default_cat = u'VineLinux' |
---|
12 | |
---|
13 | cat = '' |
---|
14 | |
---|
15 | args = content.split(',') |
---|
16 | if len(args) == 0: |
---|
17 | raise Exception("No argument.") |
---|
18 | |
---|
19 | bts_num = args[0] |
---|
20 | |
---|
21 | num_re = re.compile(r'[1-9]\d*') |
---|
22 | cat_vl_re = re.compile(r'^VineLinux$', re.IGNORECASE) |
---|
23 | cat_wish_re = re.compile(r'^wishes$', re.IGNORECASE) |
---|
24 | |
---|
25 | try: |
---|
26 | if args[1]: |
---|
27 | arg1 = args[1].strip() |
---|
28 | if arg1.startswith('cat='): |
---|
29 | user_cat = arg1.split('=', 1)[1] |
---|
30 | user_cat = user_cat.strip() |
---|
31 | if cat_vl_re.match(user_cat): |
---|
32 | cat = u'VineLinux' |
---|
33 | elif cat_wish_re.match(user_cat): |
---|
34 | cat = u'wishes' |
---|
35 | else: |
---|
36 | cat = default_cat |
---|
37 | else: |
---|
38 | cat = default_cat |
---|
39 | except: |
---|
40 | cat = default_cat |
---|
41 | |
---|
42 | if num_re.match(bts_num): |
---|
43 | |
---|
44 | full_text = '<a href="' + base_url + cat + '/' + bts_num + '"><BTS:' + cat + ':' + bts_num + '></a>' |
---|
45 | return full_text |
---|
46 | else: |
---|
47 | raise Exception("Wrong argument.") |
---|
48 | |
---|
49 | |
---|
50 | |
---|
51 | |
---|
52 | |
---|
Note: See
TracBrowser
for help on using the repository browser.