コード例 #1
0
def get_line_objs(flags: ScreenFlags) -> Dict[int, LineBase]:
    input_lines = sys.stdin.readlines()
    return get_line_objs_from_lines(
        input_lines,
        validate_file_exists=not flags.get_disable_file_checks(),
        all_input=flags.get_all_input(),
    )
コード例 #2
0
def main(argv: List[str]) -> int:
    flags = ScreenFlags.init_from_args(argv[1:])
    if flags.get_is_clean_mode():
        print("Cleaning out state files...")
        for file_path in state_files.get_all_state_files():
            if os.path.isfile(file_path):
                os.remove(file_path)
        print(f"Done! Removed {len(state_files.get_all_state_files())} files ")
        return 0
    if sys.stdin.isatty():
        # don't keep the old selection if the --keep-open option is used;
        # otherwise you need to manually clear the old selection every
        # time fpp is reopened.
        if flags.get_keep_open():
            # delete the old selection
            selection_path = state_files.get_selection_file_path()
            if os.path.isfile(selection_path):
                os.remove(selection_path)
        if os.path.isfile(state_files.get_pickle_file_path()):
            print("Using previous input piped to fpp...")
        else:
            usage()
        # let the next stage parse the old version
    else:
        # delete the old selection
        selection_path = state_files.get_selection_file_path()
        if os.path.isfile(selection_path):
            os.remove(selection_path)
        do_program(flags)
    return 0
コード例 #3
0
def main(argv: List[str]) -> int:
    file_path = state_files.get_pickle_file_path()
    if not os.path.exists(file_path):
        print("Nothing to do!")
        output.write_to_file('echo ":D";')
        output.append_exit()
        return 0
    output.clear_file()
    # we initialize our args *before* we move into curses
    # so we can benefit from the default argparse
    # behavior:
    flags = ScreenFlags.init_from_args(argv[1:])
    curses.wrapper(lambda x: do_program(CursesScreen(x), flags))
    return 0
コード例 #4
0
def main(argv: List[str]) -> int:
    flags = ScreenFlags.init_from_args(argv[1:])
    if flags.get_is_clean_mode():
        print("Cleaning out state files...")
        for file_path in state_files.get_all_state_files():
            if os.path.isfile(file_path):
                os.remove(file_path)
        print(f"Done! Removed {len(state_files.get_all_state_files())} files ")
        return 0
    if sys.stdin.isatty():
        if os.path.isfile(state_files.get_pickle_file_path()):
            print("Using previous input piped to fpp...")
        else:
            usage()
        # let the next stage parse the old version
    else:
        # delete the old selection
        selection_path = state_files.get_selection_file_path()
        if os.path.isfile(selection_path):
            os.remove(selection_path)
        do_program(flags)
    return 0
コード例 #5
0
def get_rows_from_screen_run(
    input_file: str,
    char_inputs: List[str],
    screen_config: Dict[str, int],
    print_screen: bool,
    past_screen: Optional[int],
    past_screens: Optional[List[int]],
    args: List[str],
    validate_file_exists: bool,
    all_input: bool,
) -> Tuple[List[str], List[str]]:
    line_objs = get_line_objs_from_file(
        input_file, validate_file_exists=validate_file_exists, all_input=all_input
    )
    screen = ScreenForTest(
        char_inputs,
        max_x=screen_config.get("maxX", 80),
        max_y=screen_config.get("maxY", 30),
    )

    # mock our flags with the passed arg list
    flags = ScreenFlags.init_from_args(args)
    # we run our program and throw a StopIteration exception
    # instead of sys.exit-ing
    try:
        choose.do_program(
            screen, flags, KEY_BINDINGS_FOR_TEST, CursesForTest(), line_objs
        )
    except StopIteration:
        pass

    if print_screen:
        screen.print_old_screens()

    if past_screen:
        return screen.get_rows_with_attributes_for_past_screen(past_screen)
    if past_screens:
        return screen.get_rows_with_attributes_for_past_screens(past_screens)
    return screen.get_rows_with_attributes()
コード例 #6
0
def getRowsFromScreenRun(
    inputFile,
    charInputs,
    screenConfig={},
    printScreen=True,
    pastScreen=None,
    pastScreens=None,
    validateFileExists=False,
    allInput=False,
    args=[],
):

    lineObjs = getLineObjsFromFile(
        inputFile, validateFileExists=validateFileExists, allInput=allInput
    )
    screen = ScreenForTest(
        charInputs,
        maxX=screenConfig.get("maxX", 80),
        maxY=screenConfig.get("maxY", 30),
    )

    # mock our flags with the passed arg list
    flags = ScreenFlags.initFromArgs(args)
    # we run our program and throw a StopIteration exception
    # instead of sys.exit-ing
    try:
        choose.doProgram(screen, flags, KeyBindingsForTest(), CursesForTest(), lineObjs)
    except StopIteration:
        pass

    if printScreen:
        screen.printOldScreens()

    if pastScreen:
        return screen.getRowsWithAttributesForPastScreen(pastScreen)
    elif pastScreens:
        return screen.getRowsWithAttributesForPastScreens(pastScreens)

    return screen.getRowsWithAttributes()
コード例 #7
0
ファイル: usage_strings.py プロジェクト: Spread0x/PathPicker
USAGE_TAIL = """
That's a fairly in-depth overview of Facebook PathPicker.
We also provide help along the way as you
use the app, so don't worry and jump on in!
"""

USAGE_STR = (
    USAGE_INTRO
    + USAGE_PAGE_HEADER
    + USAGE_PAGE
    + USAGE_COMMAND_HEADER
    + USAGE_COMMAND
    + USAGE_CONFIGURATION
    + USAGE_COMMAND_LINE
    + ScreenFlags.get_arg_parser().format_help()
    + USAGE_TAIL
)

DECORATOR = "*" * 80
USAGE_STR = DECORATOR + "\n" + USAGE_STR + "\n" + DECORATOR


MANPAGE_STR = "\n\n".join(
    [
        MANPAGE_HEADER,
        MANPAGE_NAME_SECTION,
        MANPAGE_SYNOPSIS,
        # FIXME: asciidoc example block?
        # http://www.methods.co.nz/asciidoc/userguide.html#X48
        ScreenFlags.get_arg_parser().format_help(),
コード例 #8
0
== Command line arguments ==


PathPicker supports some command line arguments, as well.

"""

USAGE_TAIL = """
That's a fairly in-depth overview of Facebook PathPicker.
We also provide help along the way as you
use the app, so don't worry and jump on in!
"""

USAGE_STR = (USAGE_INTRO + USAGE_PAGE_HEADER + USAGE_PAGE +
             USAGE_COMMAND_HEADER + USAGE_COMMAND + USAGE_CONFIGURATION +
             USAGE_COMMAND_LINE + ScreenFlags.getArgParser().format_help() +
             USAGE_TAIL)

decorator = "*" * 80
USAGE_STR = decorator + "\n" + USAGE_STR + "\n" + decorator

MANPAGE_STR = "\n\n".join([
    MANPAGE_HEADER,
    MANPAGE_NAME_SECTION,
    MANPAGE_SYNOPSIS,
    # FIXME: asciidoc example block?
    # http://www.methods.co.nz/asciidoc/userguide.html#X48
    ScreenFlags.getArgParser().format_help(),
    MANPAGE_INTRO_PRE,
    INTRO,
    USAGE_PAGE_HEADER,
コード例 #9
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 = state_files.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))