Index: searchattachments/searchattachments.py
===================================================================
--- searchattachments/searchattachments.py	(revision 15179)
+++ searchattachments/searchattachments.py	(working copy)
@@ -1,6 +1,7 @@
 import codecs
 import os
 import commands
+import subprocess
 import re
 import urllib
 import dircache
@@ -19,7 +20,7 @@
     implements( ISearchSource, IAttachmentChangeListener )
 
     def _absolute_index_dir( self ):
-        return os.path.join( self.env.path , 'attachments' , 'index' )
+    return os.path.join( self.env.path , 'files', 'attachments' , 'index' )
 
     absolute_index_dir = property(_absolute_index_dir)
 
@@ -82,9 +83,10 @@
             return
         index_dir  = self.absolute_index_dir
 
-        cmd = 'cd %s && %s -f %s -w %s' % ( index_dir , self.swish , index_file , query )
-        self.env.log.debug ( 'command % s =' %  cmd)
-        error , output = commands.getstatusoutput( cmd )
+        cmd = '%s -f %s -w %s' % (self.swish , index_file , query )
+        self.env.log.debug ( 'command: %s =' %  cmd)
+        p = subprocess.Popen(cmd.split(), cwd=index_dir, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False)
+        output, error = p.communicate() 
         if error :
             # TODO:Just return or raise exception here?
             self.env.log.error ( output )
@@ -91,13 +93,14 @@
             raise Exception( output )
             return
 
+        self.env.log.debug('result of search: %s' % output )
         # Parse output of the command
-        for line in output.split('\n'):
+        for line in output.splitlines():
             line = line.strip(' ')
             if line and line[0] != '#' :
-                #sel.env.log.debug ( 'line = %s ' % line )
+
                 # This is not a comment... let's parse the line
-                pattern  = re.compile ('^(\d*) (.*)/(.*)\.meta "(.*)" (\d*)$')
+                pattern  = re.compile (r'^(\d*) (.*)/(.*)\.meta "(.*)" (\d*)$')
                 hit      = pattern.match ( line )
                 if hit:
                     sw_rank      = hit.group(1)
@@ -106,16 +109,17 @@
                     sw_title     = hit.group(4)
                     sw_end       = hit.group(5)
 
-                    regexp = '^' + self.env.path + '/attachments/(.*)$'
+                    regexp = '^(.*)/files/attachments/(.*)$'
                     p = re.compile(regexp)
                     m = p.match ( sw_abs_dir )
                     if m :
-                        sw_dir = m.group(1)
+                        self.env.log.debug ('found a hit in the resultset : %s' % m)
+                        sw_dir = m.group(2)
                         file = os.path.join( sw_abs_dir , sw_filename )
 
                     else:
                         sw_dir = sw_abs_dir
-                        file = os.path.join( self.env.path , 'attachments' , sw_dir , sw_filename )
+                        file = os.path.join( self.env.path , 'files', 'attachments' , sw_dir , sw_filename )
 
                     # Build variables that we'll return for this hit
                     relative_url  = 'attachment/%s/%s'  % ( sw_dir , sw_filename )
@@ -199,7 +203,7 @@
 
         # Do we have indexes in the 'all' dictionary?
         if not all:
-            self.env.log.warning ('attachments/index does not contain any index file')
+            self.env.log.warning ('%s does not contain any index file' % self.absolute_index_dir)
             return None
 
         # Sort the indexes dictionary by increasing value
@@ -213,15 +217,23 @@
     def _build_index( self , conf_file = 'swish.config' ):
         """Build a new index by lauching the build_index script as a background process"""
 
+        cmd = 'python %s %s index -s %s -c' % (  self.seat , self.env.path , self.swish )
         self.env.log.info ('Starting index update')
-        cmd = '%s "%s" index -s "%s" -c' % (  self.seat , self.env.path , self.swish )
-        self.env.log.debug ( cmd  )
+        self.env.log.debug ('Starting index update : %s' % cmd.split())
         # Script is launched as a background process
         # ... so we'll return immediately
-        os.system( cmd + ' &' )
+        p = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False)
+        output, error = p.communicate() 
+        if error :
+            # TODO:Just return or raise exception here?
+            self.env.log.error ( output )
+            raise Exception( output )
         return
+        self.env.log.debug('result of index-update: %s' % output )
 
+        return
 
+
     def _create_metafile ( self , attachment ) :
         """Create a metafile (ie. a text version) for the attachement."""
         """Only extensions with a filter.* command defined in trac.ini will be processed."""
@@ -255,14 +267,16 @@
 
             cmd = filters[extension] % ( attachment.path , meta_file )
             self.env.log.debug( "Converting to text: %s" % cmd )
-            error , output = commands.getstatusoutput ( cmd )
+            self.env.log.debug( "Converted command: %s" % cmd.split() )            
+            p = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False)
+            output, error = p.communicate()             
 
             # Command sucessful?
             if error:
-                self.env.log.error( 'Error when converting .%s to ext :: %s' % ( extension , output) )
+                self.env.log.error( 'Error when converting .%s to text :: %s' % ( extension , error) )
                 return False
             else:
-                self.env.log.info('File %s succesfully converted ot text' % attachment.filename )
+                self.env.log.info('File %s succesfully converted to text :: %s' % (attachment.filename,output) )
                 return True
         # Unknown extension
         else:
Index: trac-seat
===================================================================
--- trac-seat	(revision 15179)
+++ trac-seat	(working copy)
@@ -4,9 +4,10 @@
 
 import os
 import re
-import md5
+import hashlib
 import time
 import random
+import subprocess
 import sys
 import string
 import commands
@@ -19,15 +20,18 @@
 	"""index files are stored in /path/to/env/attachments/index"""
 
 	# Check if index directory already exists or not
-	index_dir = os.path.join ( trac_env , 'attachments', 'index' )
+    index_dir = os.path.join ( trac_env , 'files', 'attachments', 'index' )
+    print( 'index_dir is %s' % index_dir)
 	if not os.path.exists( index_dir ):
+        print('index_dir does not exist')
 		os.mkdir ( index_dir )
 
 	os.chdir ( index_dir )
-
+    print('inside index_dir %s' % index_dir)
 	# Write config
 	key = generate_key()
 	conf_file = 'swish.config.' + key
+    print('looking for conf_file %s' % conf_file)
 	if os.path.exists( conf_file ):
 		os.remove ( conf_file )
 
@@ -34,24 +38,43 @@
 	# Crate config file
      	f = open( conf_file , 'w' )
 	for d in dirs:
+        print('writing %s' % ' IndexDir %s\n' % os.path.join ( trac_env , d ) )
 		f.write (' IndexDir %s\n' % os.path.join ( trac_env , d ) )
 	f.write( 'IndexOnly .meta          \n')
 	f.write( 'IndexContents TXT* .meta \n')
+    print('closing filewriter %s' % f)
 	f.close()
 
+
+
 	# Make sure index dir exists
 	index_file = 'index.swish-e.' + key
-	index_dir  = os.path.join ( trac_env , 'attachments' , 'index' )
+    index_dir  = os.path.join ( trac_env , 'files', 'attachments' , 'index' )
 
+    print('checking existence of index_dir %s' % index_dir)
+
 	if not os.path.exists ( index_dir ):
 		os.mkdir ( index_dir )
 
 	# Launch commmand
 	cmd  = '%s -c %s -v 2 -f %s' % ( options.swish , conf_file , index_file )
-	os.system( cmd + '&& echo "Writing index to index.swish-e.%s"' % key)
+    print('attempting to execute command %s' % cmd)
+    # os.system( cmd + '&& echo "Writing index to index.swish-e.%s"' % key)
 
+    p = subprocess.Popen(cmd.split(), cwd=index_dir,  stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False) 
+
+    output, error = p.communicate()
+
+    if error :
+        print( output )
+        raise Exception( output )
+        return
+
+    print('result of search: %s' % output )
+
 	# Remove config file	
         if os.path.exists( conf_file ):
+        print('remove conf_file %s' % conf_file)
                 os.remove ( conf_file )
 
 	if cleanold:	
@@ -61,7 +84,7 @@
 def clean ( key ):
 	"""Clean all indexes not matching key"""
 	
-	for file in os.listdir( os.path.join ( trac_env , 'attachments', 'index' ) ):
+    for file in os.listdir( os.path.join ( trac_env , 'files', 'attachments', 'index' ) ):
 
 		if file == 'index.swish-e':
 			robust_delete ( file )
@@ -184,7 +207,11 @@
 	random.seed()
 	n = random.random()*1000000000000
 	data = str(n) + 'jklsvjksldvjkjkl'
-	base = md5.new( data )
+    # base = md5.new( data )
+    #key = base.hexdigest()
+    
+    base = hashlib.md5()
+    base.update( data )
 	key = base.hexdigest()
 
 	return key
@@ -315,7 +342,7 @@
 
 # Default value for optiosn.dir
 if not options.dir:
-        options.dir = ('attachments/wiki', 'attachments/ticket')
+        options.dir = (os.path.join('files','attachments','wiki'), os.path.join('files','attachments','ticket'))
 
 
 # main switch
@@ -358,12 +385,12 @@
 			filters[ext] = trac.get('attachment', entry)
 	
 	for d in options.dir:
-		meta ( os.path.join( trac_env , d ) )
+        meta ( os.path.join( trac_env , 'files', d ) )
 
 elif command == 'deletemeta':
 	for d in options.dir:
                 print "in %s" % d
-		print "   %d .meta files deleted" % deletemeta ( os.path.join( trac_env , d ) )
+        print "   %d .meta files deleted" % deletemeta ( os.path.join( trac_env , 'files', d ) )
 
 else:
 	print 'Unkown command. Try %s --help' % os.path.basename(sys.argv[0])
