Пример #1
0
def parse_file():
    '''Parses the selector file.'''
    lines = extract_data(file_name)
    try:
        if len(lines) != 10:
            raise Invalid("selector length")
    except Invalid:
        print(sys.exc_info()[1].message.format(
            "end of file", file_name))
        terminate()
    try:
        for i, string in enumerate([
                "USERNAME:"******"PASSWORD:"******"DIRECTORY:", "TRIAL_ID:",
                "MAX_ERRORS:"]):
            if string != lines[2*i]:
                raise Invalid("selector", string)
    except Invalid:
        print(sys.exc_info()[1].message.format(
            "line {}".format(2*i+1), file_name))
        terminate()
    try:
        max_err = int_at_least(lines[9], 1, "Maximum errors allowable")
    except Invalid:
        print(sys.exc_info()[1].message.format("line 10", file_name))
        terminate()
    return lines[5], {
        "username": lines[1], "password": lines[3],
        "trial_id": lines[7]
    }, max_err
Пример #2
0
def parse_file():
    '''Parses the selector file.'''
    lines = extract_data(file_name)
    try:
        if len(lines) != 10:
            raise Invalid("selector length")
    except Invalid:
        print(sys.exc_info()[1].message.format(
            "end of file", file_name))
        terminate()
    try:
        for i, string in enumerate([
                "USERNAME:"******"PASSWORD:"******"DIRECTORY:", "TRIAL_ID:",
                "MAX_ERRORS:"]):
            if string != lines[2*i]:
                raise Invalid("selector", string)
    except Invalid:
        print(sys.exc_info()[1].message.format(
            "line {}".format(2*i+1), file_name))
        terminate()
    try:
        max_err = int_at_least(lines[9], 1, "Maximum errors allowable")
    except Invalid:
        print(sys.exc_info()[1].message.format("line 10", file_name))
        terminate()
    return lines[5], {
        "username": lines[1], "password": lines[3],
        "trial_id": lines[7]
    }, max_err
Пример #3
0
def parse_file(directory, macro_test):
    """Open the file, for-loop over the lines, feed them to the parser,
    validate, and return the macros, configuration, and automation."""
    # Careful! If macro_test == "", we stick with that.
    lines = extract_data(directory + file_name) if macro_test is False else (macro_test.splitlines())
    parser = ObjectParser()
    for i, line in enumerate(lines, start=1):
        # Escape stylized quotes with ASCII quotes if set to do so.
        line = line.strip()
        if not line:
            continue
        if parser.config_dict["autoquote"]:
            line = re.sub("‘|’|“|”", quote_replace, line)
        if line.startswith("/*") and parser.next_method != parser.in_comment:
            parser.return_to = parser.in_macro
            return parser.in_comment(line)
        elif line.startswith("//"):
            pass
        else:
            try:
                parser.next_method = parser.next_method(line)
            except Invalid:
                print sys.exc_info()[1].message.format("line {}".format(i), file_name)
                terminate()
    try:
        if lines:
            parser.cleanup()
    except Invalid:
        print sys.exc_info()[1].message.format("end of file", file_name)
        terminate()
    parser.config_dict["…"] = parser.config_dict.pop("...")
    return parser.macro_dict, parser.config_dict, parser.automate_dict
Пример #4
0
def parse_file(directory, macro_test):
    '''Open the file, for-loop over the lines, feed them to the parser,
    validate, and return the macros, configuration, and automation.'''
    # Careful! If macro_test == "", we stick with that.
    lines = extract_data(directory + file_name) if macro_test is False else (
        macro_test.splitlines())
    parser = ObjectParser()
    for i, line in enumerate(lines, start=1):
        # Escape stylized quotes with ASCII quotes if set to do so.
        line = line.strip()
        if not line:
            continue
        if parser.config_dict["autoquote"]:
            line = re.sub("‘|’|“|”", quote_replace, line)
        if line.startswith("/*") and parser.next_method != parser.in_comment:
            parser.return_to = parser.in_macro
            return parser.in_comment(line)
        elif line.startswith("//"):
            pass
        else:
            try:
                parser.next_method = parser.next_method(line)
            except Invalid:
                print sys.exc_info()[1].message.format("line {}".format(i),
                                                       file_name)
                terminate()
    try:
        if lines:
            parser.cleanup()
    except Invalid:
        print sys.exc_info()[1].message.format("end of file", file_name)
        terminate()
    parser.config_dict["…"] = parser.config_dict.pop("...")
    return parser.macro_dict, parser.config_dict, parser.automate_dict
Пример #5
0
def parse_file(config_dict, obj_test):
    '''Open the file, for-loop over the lines, feed them to the parser,
    validate, and return the trial, suffixes, and objects with a handle.'''
    # Careful! If macro_test == "", we stick with that.
    lines = extract_data(file_name) if obj_test is False else (
        obj_test.splitlines())
    parser = ObjectParser(config_dict)
    # Escape stylized quotes with ASCII quotes if set to do so.
    if parser.config_dict["autoquote"]:
        lines = [re.sub("‘|’|“|”", quote_replace, line) for line in lines]
    for i, line in enumerate(lines, start=1):
        line = line.strip()
        if not line:
            continue
        if line.startswith("/*") and parser.next_method != parser.in_comment:
            parser.return_to = parser.next_method
            parser.next_method = parser.in_comment(line)
        elif line.startswith("//"):
            pass
        else:
            try:
                parser.next_method = parser.next_method(line)
            except Invalid:
                print(sys.exc_info()[1].message.format("line {}".format(i),
                                                       file_name))
                Invalid.err_count += 1
                if Invalid.err_count >= Invalid.max_err:
                    terminate()
    try:
        if lines:
            parser.cleanup()
    except Invalid:
        print(sys.exc_info()[1].message.format("end of file", file_name))
        terminate()

    if Invalid.err_count:
        terminate()

    template = {
        "profiles": [0],
        "evidence": [0],
        "places": [0],
        "sounds": [0],
        "music": [0],
        "popups": [0],
        "cross_examinations": [0],
        "scenes": [0],
        "scenes_aai": [0],
        "frames": [0],
        "ui": {
            "base": "classic",
            "elements": []
        }
    }
    for row in {"Popup", "Sound", "Music", "Place", "Evidence", "Profile"}:
        active_obj = getattr(object_classes, row)
        template[active_obj.attribute] = active_obj.chain
    return template, object_classes.Profile.suffix_dicts, parser.using_objects
Пример #6
0
def parse_file(template, suffix_dicts, object_dict, macro_dict, config_dict,
               frame_test):
    '''Open the file, for-loop over the lines, feed them to the parser,
    validate, and return the trial.'''
    lines = extract_data(file_name) if frame_test is False else (
        frame_test.splitlines())
    parser = FrameParser(template, suffix_dicts, object_dict, macro_dict,
                         config_dict)
    # Replace stylized quotes with ASCII quotes if set to do so.
    if parser.config_dict["autoquote"]:
        lines = [re.sub("‘|’|“|”", quote_replace, line) for line in lines]
    for i, line in enumerate(lines, start=1):
        try:
            if not line:
                # A blank line means to expect a new frame.
                parser.next_method = parser.blank()
            elif line.startswith(
                    "//") and parser.next_method == parser.init_frame:
                # Ignore single-line comments.
                pass
            elif line.startswith(
                    "/*") and parser.next_method == parser.init_frame:
                # Mutliline comments trigger the comment state, but in case it's
                # a one-line multiline comment, call to comment.
                parser.next_method = parser.comment(line)
            else:
                # If all else fails, go with whatever the current state is.
                parser.next_method = parser.next_method(line)
        except Invalid:
            print(sys.exc_info()[1].message.format("line {}".format(i),
                                                   file_name))
            # The error skipping system means that when a function runs, we miss
            # the ability to get the next function returned. Either error skipping
            # or the "next_method" idea needs to be rewritten. Probably both.
            if parser.next_method == parser.dialogue:
                parser.next_method = parser.init_frame
                # Reset the line queue, so we don't try to rewrap words that...
                #...already are giving us problems.
                parser.line_queue = [""]
            Invalid.err_count += 1
            if Invalid.err_count >= Invalid.max_err:
                parser.terminate()

    try:
        if lines:
            parser.cleanup()
    except Invalid:
        print(sys.exc_info()[1].message.format("end of file", file_name))
        parser.terminate()

    if Invalid.err_count:
        parser.terminate()

    # Clear tkinter, even if the frame_data is blank.
    parser.root.after_idle(parser.root.destroy)
    parser.root.mainloop()
    return parser.executor.trial
Пример #7
0
def parse_file(config_dict, obj_test):
    '''Open the file, for-loop over the lines, feed them to the parser,
    validate, and return the trial, suffixes, and objects with a handle.'''
    # Careful! If macro_test == "", we stick with that.
    lines = extract_data(file_name) if obj_test is False else (
        obj_test.splitlines())
    parser = ObjectParser(config_dict)
    # Escape stylized quotes with ASCII quotes if set to do so.
    if parser.config_dict["autoquote"]:
        lines = [re.sub("‘|’|“|”", quote_replace, line) for line in lines]
    for i, line in enumerate(lines, start=1):
        line = line.strip()
        if not line:
            continue
        if line.startswith("/*") and parser.next_method != parser.in_comment:
            parser.return_to = parser.next_method
            parser.next_method = parser.in_comment(line)
        elif line.startswith("//"):
            pass
        else:
            try:
                parser.next_method = parser.next_method(line)
            except Invalid:
                print(sys.exc_info()[1].message.format(
                    "line {}".format(i), file_name))
                Invalid.err_count += 1
                if Invalid.err_count >= Invalid.max_err:
                    terminate()
    try:
        if lines:
            parser.cleanup()
    except Invalid:
        print(sys.exc_info()[1].message.format("end of file", file_name))
        terminate()

    if Invalid.err_count:
        terminate()

    template = {
        "profiles": [0], "evidence": [0], "places": [0], "sounds": [0],
        "music": [0], "popups": [0], "cross_examinations": [0], "scenes": [0],
        "scenes_aai": [0], "frames": [0],
        "ui": {"base": "classic", "elements": []}
    }
    for row in {"Popup", "Sound", "Music", "Place", "Evidence", "Profile"}:
        active_obj = getattr(object_classes, row)
        template[active_obj.attribute] = active_obj.chain
    return template, object_classes.Profile.suffix_dicts, parser.using_objects
Пример #8
0
def parse_file(template, suffix_dicts, object_dict, macro_dict, config_dict, frame_test):
    """Open the file, for-loop over the lines, feed them to the parser,
    validate, and return the trial."""
    lines = extract_data(file_name) if frame_test is False else (frame_test.splitlines())
    parser = FrameParser(template, suffix_dicts, object_dict, macro_dict, config_dict)
    # Replace stylized quotes with ASCII quotes if set to do so.
    if parser.config_dict["autoquote"]:
        lines = [re.sub("‘|’|“|”", quote_replace, line) for line in lines]
    for i, line in enumerate(lines, start=1):
        if not line:
            # A blank line means to expect a new frame.
            parser.next_method = parser.blank()
        elif line.startswith("//") and parser.next_method == parser.init_frame:
            # Ignore single-line comments.
            pass
        elif line.startswith("/*") and parser.next_method == parser.init_frame:
            # Mutliline comments trigger the comment state, but in case it's
            # a one-line multiline comment, call to comment.
            parser.next_method = parser.comment(line)
        else:
            # If all else fails, go with whatever the current state is.
            try:
                parser.next_method = parser.next_method(line)
            except Invalid:
                print(sys.exc_info()[1].message.format("line {}".format(i), file_name))
                Invalid.err_count += 1
                if Invalid.err_count >= Invalid.max_err:
                    parser.terminate()

    try:
        if lines:
            parser.cleanup()
    except Invalid:
        print(sys.exc_info()[1].message.format("end of file", file_name))
        parser.terminate()

    if Invalid.err_count:
        parser.terminate()

    # Clear tkinter, even if the frame_data is blank.
    parser.root.after_idle(parser.root.destroy)
    parser.root.mainloop()
    return parser.executor.trial
Пример #9
0
def parse_file(directory, template, suffix_dicts, object_dict, macro_dict,
               config_dict, frame_test):
    '''Open the file, for-loop over the lines, feed them to the parser,
    validate, and return the trial.'''
    lines = extract_data(directory + file_name) if frame_test is False else (
        frame_test.splitlines())
    parser = FrameParser(template, suffix_dicts, object_dict, macro_dict,
                         config_dict)
    # Replace stylized quotes with ASCII quotes if set to do so.
    if parser.config_dict["autoquote"]:
        lines = [re.sub("‘|’|“|”", quote_replace, line) for line in lines]
    for i, line in enumerate(lines, start=1):
        if not line:
            # A blank line means to expect a new frame.
            parser.next_method = parser.blank()
        elif line.startswith("//") and parser.next_method == parser.init_frame:
            # Ignore single-line comments.
            pass
        elif line.startswith("/*") and parser.next_method == parser.init_frame:
            # Mutliline comments trigger the comment state, but in case it's
            # a one-line multiline comment, call to comment.
            parser.next_method = parser.comment(line)
        else:
            # If all else fails, go with whatever the current state is.
            try:
                parser.next_method = parser.next_method(line)
            except Invalid:
                print sys.exc_info()[1].message.format("line {}".format(i),
                                                       file_name)
                parser.terminate()
    try:
        if lines:
            parser.cleanup()
    except Invalid:
        print sys.exc_info()[1].message.format("end of file", file_name)
        parser.terminate()

    # Clear tkinter, even if the frame_data is blank.
    parser.root.after_idle(parser.root.destroy)
    parser.root.mainloop()
    return parser.executor.trial
Пример #10
0
def parse_file():
    '''Parses the selector file.'''
    lines = extract_data(file_name)
    try:
        if len(lines) != 8:
            raise Invalid("selector length")
    except Invalid:
        print sys.exc_info()[1].message.format(
            "end of file", file_name)
        terminate()
    try:
        for i, string in enumerate([
                "USERNAME:"******"PASSWORD:"******"DIRECTORY:", "TRIAL_ID:"]):
            if string != lines[2*i]:
                raise Invalid("selector", string)
    except Invalid:
        print sys.exc_info()[1].message.format(
                "line {}".format(2*i+1), file_name)
        terminate()
    return lines[5], {
        "username": lines[1], "password": lines[3],
        "trial_id": lines[7]
    }