def setSelectionsFromPickle(selectionPath, lineObjs): try: selectedIndices = pickle.load(open(selectionPath, 'rb')) except: output.appendError(LOAD_SELECTION_WARNING) output.appendExit() sys.exit(1) for index in selectedIndices: if index >= len(lineObjs.items()): error = 'Found index %d more than total matches' % index output.appendError(error) continue toSelect = lineObjs[index] if isinstance(toSelect, format.LineMatch): lineObjs[index].setSelect(True) else: error = 'Line %d was selected but is not LineMatch' % index output.appendError(error)
def getLineObjs(): filePath = stateFiles.getPickleFilePath() try: lineObjs = pickle.load(open(filePath, 'rb')) except: output.appendError(LOAD_SELECTION_WARNING) output.appendExit() sys.exit(1) logger.addEvent('total_num_files', len(lineObjs)) selectionPath = stateFiles.getSelectionFilePath() if os.path.isfile(selectionPath): setSelectionsFromPickle(selectionPath, lineObjs) matches = [lineObj for lineObj in lineObjs.values() if not lineObj.isSimple()] if not len(matches): output.writeToFile('echo "No lines matched!!";') output.appendExit() sys.exit(0) return lineObjs
except: output.appendError(LOAD_SELECTION_WARNING) output.appendExit() sys.exit(1) for index in selectedIndices: if index >= len(lineObjs.items()): error = 'Found index %d more than total matches' % index output.appendError(error) continue toSelect = lineObjs[index] if isinstance(toSelect, format.LineMatch): lineObjs[index].setSelect(True) else: error = 'Line %d was selected but is not LineMatch' % index output.appendError(error) if __name__ == '__main__': filePath = stateFiles.getPickleFilePath() if not os.path.exists(filePath): print('Nothing to do!') output.writeToFile('echo ":D";') output.appendExit() sys.exit(0) output.clearFile() # we initialize our args *before* we move into curses # so we can benefit from the default argparse # behavior: flags = ScreenFlags.initFromArgs(sys.argv[1:]) curses.wrapper(lambda x: doProgram(x, flags))