| 1 | |
|---|
| 2 | from trac.WikiFormatter import wiki_to_html, WikiProcessor |
|---|
| 3 | from trac import util |
|---|
| 4 | import os |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | def execute(hdf, file, env): |
|---|
| 8 | # Currently hdf is set only when the macro is called |
|---|
| 9 | # From a wiki page |
|---|
| 10 | args = file or '' |
|---|
| 11 | |
|---|
| 12 | if args: |
|---|
| 13 | import urllib |
|---|
| 14 | try: |
|---|
| 15 | f = urllib.urlopen(args) |
|---|
| 16 | except: |
|---|
| 17 | raise util.TracError('The "%s" argument doesnt seem to be a valid link' % (args)) |
|---|
| 18 | txt = f.read() |
|---|
| 19 | (path, suffix) = os.path.splitext(args) |
|---|
| 20 | suffix = suffix[1:] |
|---|
| 21 | try: |
|---|
| 22 | Format = WikiProcessor(env,suffix) |
|---|
| 23 | html = Format.process(hdf, txt) |
|---|
| 24 | return html |
|---|
| 25 | except: |
|---|
| 26 | raise util.TracError('The "%s" argument doesnt seem to be a valid link' % (suffix)) |
|---|
| 27 | return wiki_to_html(txt, hdf, env, env.get_db_cnx) |
|---|
| 28 | else: |
|---|
| 29 | raise util.TracError('The include macro requires an url as argument') |
|---|