5 | | This plugin allows text integral search in attachments. |
6 | | * adds a new '''Attachments''' source to the search page |
7 | | * presents an excerpt of the documents in the result page |
8 | | * supports any format with a command line tool for plain text conversion (filter command) |
| 5 | This plugin allows text integral search in wiki and ticket attachments (.pdf, .doc,.ppt,...). |
| 6 | The SEAT plugin has the following features: |
| 7 | * new '''Attachments''' source to the search page |
| 8 | * an excerpt of the matching documents is presented in the result page |
| 9 | * any format is supported as long as there is a command line tool for plain text conversion (filter command) |
26 | | == Example == |
| 27 | == How to install? == |
| 28 | |
| 29 | * Install swish-e, http://swish-e.org/ |
| 30 | |
| 31 | * Install filter tools for the formats you want to index, for instance |
| 32 | * `catdoc` and `catppt`, http://www.45.free.net/~vitus/software/catdoc/ |
| 33 | * `pdftotext`, http://www.foolabs.com/xpdf/ |
| 34 | |
| 35 | * Download the plugin from xxxx |
| 36 | |
| 37 | * Install the plugin |
| 38 | {{{ |
| 39 | python set-up bdist_egg |
| 40 | cp searchattachmpents.egg YOUR_TRAC_ENV/plugins |
| 41 | }}} |
| 42 | |
| 43 | * Configure the [attachment] section of trac.ini |
| 61 | There is no need to declare a filter command for .txt or .text. Text files are handled |
| 62 | natively. To index a new non-text format, just add a filter.* entry using the appropriate |
| 63 | command line tool for this format. |
| 64 | {{{ |
| 65 | filter.myEXT = my_command -infile "%s" -outfile "%s" |
| 66 | }}} |
| 67 | |
| 68 | * Trac 10.x and 11.x source code must be manually modified for SEAT plugin to work. |
| 69 | The file to modify is '''attachment.py'''. On a Linux Fedora system, it is located in |
| 70 | /usr/lib/python2.4/site-packages/trac |
| 71 | |
| 72 | {{{ |
| 73 | |
| 74 | 162 def insert(self, filename, fileobj, size, t=None, db=None): |
| 75 | ... |
| 76 | ... |
| 77 | 184 try: |
| 78 | 185 # Note: `path` is an unicode string because `self.path` was one. |
| 79 | 186 # As it contains only quoted chars and numbers, we can use `ascii` |
| 80 | 187 basename = os.path.basename(path).encode('ascii') |
| 81 | 188 filename = unicode_unquote(basename) |
| 82 | 189 |
| 83 | 190 cursor = db.cursor() |
| 84 | 191 cursor.execute("INSERT INTO attachment " |
| 85 | 192 "VALUES (%s,%s,%s,%s,%s,%s,%s,%s)", |
| 86 | 193 (self.parent_type, self.parent_id, filename, |
| 87 | 194 self.size, self.time, self.description, self.author, |
| 88 | 195 self.ipnr)) |
| 89 | 196 shutil.copyfileobj(fileobj, targetfile) |
| 90 | 197 self.filename = filename |
| 91 | 198 |
| 92 | 199 self.env.log.info('New attachment: %s by %s', self.title, |
| 93 | 200 self.author) |
| 94 | 201 |
| 95 | 202 if handle_ta: |
| 96 | 203 db.commit() |
| 97 | 204 |
| 98 | 205 targetfile.close() # << Line to add for SEAT plugin |
| 99 | 206 |
| 100 | 207 for listener in AttachmentModule(self.env).change_listeners: |
| 101 | 208 listener.attachment_added(self) |
| 102 | 209 finally: |
| 103 | 210 targetfile.close() |
| 104 | |
| 105 | }}} |
| 106 | |
| 107 | |
| 108 | * Add the trac-seat utility to your path. For instance, copy trac-seat to /usr/local/bin. |
| 109 | * Use trac-seat to convert existing attachments to text files and index these. |
| 110 | {{{ |
| 111 | trac-seat /path/to/your/env meta |
| 112 | trac-seat /path/to/your/env index -c |
| 113 | }}} |
| 114 | |
| 115 | * '''restart''' the trac server ( /etc/init.d/httpd restart) |
| 116 | |
| 117 | |