@@ -176,96 +176,6 @@ def cap_ftp_sync(user_id=None):
176
176
177
177
tasks ["cap_ftp_sync" ] = cap_ftp_sync
178
178
179
- # -----------------------------------------------------------------------------
180
- if has_module ("doc" ):
181
-
182
- # -----------------------------------------------------------------------------
183
- def document_create_index (document , user_id = None ):
184
-
185
- import os
186
- from xlrd import open_workbook
187
- from pyth .plugins .rtf15 .reader import Rtf15Reader
188
- from pyth .plugins .plaintext .writer import PlaintextWriter
189
- import sunburnt
190
-
191
- document = json .loads (document )
192
- table = s3db .doc_document
193
- id = document ["id" ]
194
-
195
- name = document ["name" ]
196
- filename = document ["filename" ]
197
-
198
- filename = "%s/%s/uploads/%s" % (os .path .abspath ("applications" ), \
199
- request .application , filename )
200
-
201
- si = sunburnt .SolrInterface (settings .get_base_solr_url ())
202
-
203
- extension = os .path .splitext (filename )[1 ][1 :]
204
-
205
- if extension == "pdf" :
206
- data = os .popen ("pdf2txt.py " + filename ).read ()
207
- elif extension == "doc" :
208
- data = os .popen ("antiword " + filename ).read ()
209
- elif extension == "xls" :
210
- wb = open_workbook (filename )
211
- data = " "
212
- for s in wb .sheets ():
213
- for row in range (s .nrows ):
214
- values = []
215
- for col in range (s .ncols ):
216
- values .append (str (s .cell (row , col ).value ))
217
- data = data + "," .join (values ) + "\n "
218
- elif extension == "rtf" :
219
- doct = Rtf15Reader .read (open (filename ))
220
- data = PlaintextWriter .write (doct ).getvalue ()
221
- else :
222
- data = os .popen ("strings " + filename ).read ()
223
-
224
- # The text needs to be in unicode or ascii, with no contol characters
225
- data = str (unicode (data , errors = "ignore" ))
226
- data = "" .join (c if ord (c ) >= 32 else " " for c in data )
227
-
228
- # Put the data according to the Multiple Fields
229
- # @ToDo: Also, would change this according to requirement of Eden
230
- document = {"id" : str (id ), # doc_document.id
231
- "name" : data , # the data of the file
232
- "url" : filename , # the encoded file name stored in uploads/
233
- "filename" : name , # the filename actually uploaded by the user
234
- "filetype" : extension # x.pdf -> pdf is the extension of the file
235
- }
236
-
237
- # Add and commit Indices
238
- si .add (document )
239
- si .commit ()
240
- # After Indexing, set the value for has_been_indexed to True in the database
241
- db (table .id == id ).update (has_been_indexed = True )
242
-
243
- db .commit ()
244
-
245
- tasks ["document_create_index" ] = document_create_index
246
-
247
- # -----------------------------------------------------------------------------
248
- def document_delete_index (document , user_id = None ):
249
-
250
- import sunburnt
251
-
252
- document = json .loads (document )
253
- table = s3db .doc_document
254
- id = document ["id" ]
255
- filename = document ["filename" ]
256
-
257
- si = sunburnt .SolrInterface (settings .get_base_solr_url ())
258
-
259
- # Delete and Commit the indicies of the deleted document
260
- si .delete (id )
261
- si .commit ()
262
- # After removing the index, set has_been_indexed value to False in the database
263
- db (table .id == id ).update (has_been_indexed = False )
264
-
265
- db .commit ()
266
-
267
- tasks ["document_delete_index" ] = document_delete_index
268
-
269
179
# -----------------------------------------------------------------------------
270
180
if has_module ("msg" ):
271
181
0 commit comments