#!/usr/bin/python import os, string, glob def replace_var_with_arg(file, var, arg): X = open(file,'r').readlines() for i in range(len(X)): if X[i][0:len(var)] == var: splitted = X[i].split('=') splitted[1] = arg.strip()+'\n' X[i] = string.join(splitted,'=') break open(file,'w').write(string.join(X,'')) def update_corpus(sphinxdir, sphinxfile): prevdir = os.getcwd() os.chdir(sphinxdir) c = glob.glob('*.dic') m = 0 for file in c: n = os.path.getmtime(file) if n > m: n = m id = file.split('.')[0] replace_var_with_arg(sphinxfile, 'ID', id) os.chdir(prevdir) ################################################################################ if __name__ == '__main__': cwd = os.getcwd() sphinxfile = cwd+'/sphinx/sphinx2-simple' rcfile = cwd+'/psycherc' replace_var_with_arg(rcfile, 'PSYCHEPATH', cwd) replace_var_with_arg(sphinxfile, 'PSYCHEPATH', cwd) replace_var_with_arg(rcfile, 'sphinx', sphinxfile) update_corpus(cwd+'/sphinx', sphinxfile)