def getLineObjs(): filePath = stateFiles.getPickleFilePath() try: lineObjs = pickle.load(open(filePath, 'rb')) except: output.appendError(LOAD_SELECTION_WARNING) sys.exit(1) logger.addEvent('total_num_files', len(lineObjs.items())) selectionPath = stateFiles.getSelectionFilePath() if os.path.isfile(selectionPath): setSelectionsFromPickle(selectionPath, lineObjs) matches = [lineObj for i, lineObj in lineObjs.items() if not lineObj.isSimple()] if not len(matches): output.writeToFile('echo "No lines matched!!"') sys.exit(0) return lineObjs
def doProgram(flags): filePath = stateFiles.getPickleFilePath() lineObjs = getLineObjs(flags) # pickle it so the next program can parse it pickle.dump(lineObjs, open(filePath, 'wb'))
def usage(): print(USAGE_STR) if __name__ == '__main__': flags = ScreenFlags.initFromArgs(sys.argv[1:]) if (flags.getIsCleanMode()): print('Cleaning out state files...') for filePath in stateFiles.getAllStateFiles(): if os.path.isfile(filePath): os.remove(filePath) print('Done! Removed %d files ' % len(stateFiles.getAllStateFiles())) sys.exit(0) if sys.stdin.isatty(): if os.path.isfile(stateFiles.getPickleFilePath()): print('Using old result...') else: usage() # let the next stage parse the old version sys.exit(0) else: # delete the old selection selectionPath = stateFiles.getSelectionFilePath() if os.path.isfile(selectionPath): os.remove(selectionPath) doProgram(flags) sys.exit(0)
def usage(): print(USAGE_STR) if __name__ == '__main__': flags = ScreenFlags.initFromArgs(sys.argv[1:]) if (flags.getIsCleanMode()): print('Cleaning out state files...') for filePath in stateFiles.getAllStateFiles(): if os.path.isfile(filePath): os.remove(filePath) print('Done! Removed %d files ' % len(stateFiles.getAllStateFiles())) sys.exit(0) if sys.stdin.isatty(): if os.path.isfile(stateFiles.getPickleFilePath()): print('Using previous input piped to fpp...') else: usage() # let the next stage parse the old version else: # delete the old selection selectionPath = stateFiles.getSelectionFilePath() if os.path.isfile(selectionPath): os.remove(selectionPath) doProgram(flags) sys.exit(0)
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))
def doProgram(customRegex=None): filePath = stateFiles.getPickleFilePath() lineObjs = getLineObjs(customRegex) # pickle it so the next program can parse it pickle.dump(lineObjs, open(filePath, 'wb'))