def indexFile(tree, materialPath): """ Gives the user an option to choose which file to index to the tree """ fileList = File.getFileNames(materialPath) printPath = File.printFileList(materialPath, noPath='yes') input = prompt('Choose file:', limits = [0, len(fileList)]) print 'Indexing "' + printPath[input] + '" now...' tree.lukija.clear() tree.lukija.addFileName(fileList[input]) tree.lukija.readWords() tree.addFromReader()
# if limits given value must be in the given range if limits: if input < limits[0] or input > limits[1]: print 'Must give value between %d and %d' % (limits[0], limits[1]) input = prompt(request, limits=limits, type=type) except ValueError: print 'You must give an integer as an option here.' input = prompt(request, limits=limits, type=type) return input if __name__ == "__main__": lukija = WordReader() tree = Trie(lukija) materialPath = '../../Material/' if not File.getFileNames(materialPath): raise Exception('Empty file path, cannot find material') print '*' * 50, '\n', ' ' * ((50 - (len(name)))/2-1), name , '\n', '*' * 50 # cProfile.run('testRun()', 'testProf') # p = pstats.Stats('testProf') # p.sort_stats('cumulative').print_stats(10) status = 'empty' while(input): printOperationOptions(status) input = prompt('Choose option (0 to quit):', limits = [0, len(operationOptions)-1]) tree, status = operator(input, tree, materialPath, status)