Exemplo n.º 1
0
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
Exemplo n.º 2
0
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
Exemplo n.º 3
0
def outputSelection(lineObjs):
    filePath = stateFiles.getSelectionFilePath()
    indices = [l.index for l in lineObjs]
    file = open(filePath, 'wb')
    pickle.dump(indices, file)
    file.close()
Exemplo n.º 4
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 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)
Exemplo n.º 5
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)