예제 #1
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
예제 #2
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
예제 #3
0
def parse_file(directory, 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(directory + 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)
                terminate()
    try:
        if lines:
            parser.cleanup()
    except Invalid:
        print sys.exc_info()[1].message.format("end of file", file_name)
        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
예제 #4
0
def parse_file(directory, 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(directory + 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)
                terminate()
    try:
        if lines:
            parser.cleanup()
    except Invalid:
        print sys.exc_info()[1].message.format("end of file", file_name)
        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
예제 #5
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
예제 #6
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
예제 #7
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]
    }
예제 #8
0
        directory, upload_dict = upload_parser.parse_file()
    else:
        directory = "test_lib"
    macro_dict, config_dict, auto_dict = macro_parser.parse_file(
        directory, macro_test)
    template, suffix_dicts, object_dict = (
        object_parser.parse_file(directory, config_dict, obj_test))
    json_data = frame_parser.parse_file(
        directory, template, suffix_dicts, object_dict, macro_dict,
        config_dict, frame_test)
    json_data = json.dumps(json_data, separators=(',', ':'))
except SystemExit:
    sys.exit()
except:
    print "Unknown error observed! Please send your documents to Enthalpy."
    catalysis_globals.terminate()

# Get file even when the program is .exe.
output_file = directory + "/testData.txt"
if getattr(sys, 'frozen', False):
    output_file = os.path.join(os.path.dirname(sys.executable), output_file)

# Write the full information to the file.
open(output_file, "w").write('//Definition//Def6\n' + json_data)

if not test_mode:
    try:
        upload_dict["trial_id"] = int(upload_dict["trial_id"])
    except ValueError:
        print "Choosing not to upload data..."
    else:
예제 #9
0
def catalysis_main():

    print("Beginning catalysis.\n")

    # Reset session-dependent globals.
    catalysis_globals.directory = ""
    catalysis_globals.Invalid.max_err = 1
    catalysis_globals.Invalid.err_count = 0

    # Reset session-dependent class variables.
    object_classes.Profile.suffix_dicts = {}
    for row in {"Popup", "Sound", "Music", "Place", "Evidence", "Profile"}:
        active_obj = getattr(object_classes, row)
        active_obj.chain = [0]

    try:
        if not catalysis_globals.test_mode:
            catalysis_globals.directory, upload_dict, max_err = (
                upload_parser.parse_file())
            catalysis_globals.Invalid.max_err = max_err
        else:
            catalysis_globals.directory = "test_lib"
        macro_dict, config_dict = macro_parser.parse_file(macro_test)
        template, suffix_dicts, object_dict = (
            object_parser.parse_file(config_dict, obj_test))
        json_data = frame_parser.parse_file(
            template, suffix_dicts, object_dict, macro_dict, config_dict,
            frame_test)
        json_data = json.dumps(json_data, separators=(',', ':'))
    except catalysis_globals.RestartSignal:
    	# A standard error has occurred. Send it up to the main loop.
    	raise
    except Exception:
        print(
            "Unknown error observed! Please send your documents to Enthalpy, "
            "especially err.txt, which has been automatically created."
        )
        error_file = catalysis_globals.get_file_name("err.txt")
        with open(error_file, "w") as f:
            traceback.print_exc(file=f)
        catalysis_globals.terminate()

    # Write data to file.
    output_file = catalysis_globals.get_file_name("testData.txt")
    open(output_file, "w").write('//Definition//Def6\n' + json_data)

    if not catalysis_globals.test_mode:
        try:
            upload_dict["trial_id"] = int(upload_dict["trial_id"])
        except ValueError:
            print("Choosing not to upload data...")
        else:
            print((
                "Choosing to upload data to trial {}. Press enter to " +
                "continue.").format(upload_dict["trial_id"]))
            print(
                "If this was not the trial ID you wanted, type other "
                "symbols and then hit enter."
            )
            # Due to the codec, you need a bytestring here.
            do_not_upload = input()
            if not do_not_upload:
                upload_manager = uploader.Uploader(upload_dict)

    print("Catalysis complete!")
    catalysis_globals.terminate()
예제 #10
0
 def terminate(self):
     '''Close out of Tkinter and then terminate.'''
     self.root.after_idle(self.root.destroy)
     self.root.mainloop()
     terminate()
예제 #11
0
 def terminate(self):
     """Close out of Tkinter and then terminate."""
     self.root.after_idle(self.root.destroy)
     self.root.mainloop()
     terminate()