def reduce(student, reference): differences = None contents = None differ = None status = None line = None r = None s = None if not ((env.path(reference, env.OPTION_EXIST)) and \ (env.path(reference, env.OPTION_FILE))): return # load the reference and student files. r = env.pull(reference, env.OPTION_NONE).split("\n") s = env.pull(student, env.OPTION_NONE).split("\n") # build an differ object. differ = difflib.Differ() # look for the differences. differences = differ.compare(r, s) # only keep the added lines. status = STATUS_EQUAL contents = "" # for each line. for line in differences: if line[len(line) - 1] == "\n": line = line[:len(line) - 1] # we insert a CTC-GATE token so that the CTC tool does not match code # regions including such a token. # this is done because code has been removed. therefore, a match has # no sense here. if (line[0] == STATUS_INSERT) and (line[0] != status): contents += "_____ctc_gate_____\n" status = line[0] # add the line to the final file since we only keep added stuff. if line[0] == STATUS_INSERT: contents += line[2:] + "\n" # save the contents in the student file. env.push(student, contents, env.OPTION_NONE)
def reduce(student, reference): differences = None contents = None differ = None status = None line = None r = None s = None if not ((env.path(reference, env.OPTION_EXIST)) and \ (env.path(reference, env.OPTION_FILE))): return # load the reference and student files. r = env.pull(reference, env.OPTION_NONE).split("\n") s = env.pull(student, env.OPTION_NONE).split("\n") # build an differ object. differ = difflib.Differ() # look for the differences. differences = differ.compare(r, s) # only keep the added lines. status = STATUS_EQUAL contents="" # for each line. for line in differences: if line[len(line) - 1] == "\n": line = line[:len(line) - 1] # we insert a CTC-GATE token so that the CTC tool does not match code # regions including such a token. # this is done because code has been removed. therefore, a match has # no sense here. if (line[0] == STATUS_INSERT) and (line[0] != status): contents += "_____ctc_gate_____\n"; status = line[0] # add the line to the final file since we only keep added stuff. if line[0] == STATUS_INSERT: contents += line[2:] + "\n" # save the contents in the student file. env.push(student, contents, env.OPTION_NONE)
def modify(variable, assignment): content = None matches = None object = None match = None # update the database for object in g_database: if variable == object.variable: # if the value is the same, just ignore the call if object.assignment == assignment: return object.assignment = assignment break # load the user profile configuration file. content = env.pull(env._PROFILE_USER_DIR_ + "/" + env._USER_ + ".conf", env.OPTION_NONE) + "\n" # find the assignments related to the given variable matches = re.findall("(" + \ "^" + \ "(" + \ "[ \t]*" + \ variable + \ "[ \t]*" + \ "\+?=" + \ "[ \t]*" + \ ")" + \ "((?:(?:\\\\\n)|[^\n])+)" + \ "\n" + \ ")", content, re.MULTILINE); if not matches: # add a new entry to the file. content = content + \ variable + " = " + assignment + "\n" else: # replace the value part with the given value. for match in matches: content = content.replace(match[0], match[1] + assignment + "\n") # finally, write back the content. env.push(env._PROFILE_USER_DIR_ + "/" + env._USER_ + ".conf", content, env.OPTION_NONE)
def menu(): global g_components global g_menu content = None component = None # initialize the file content. content = "timeout 0\n" + \ "title kaneton\n" # add information about how to boot. if (env._BOOT_MODE_ == "peripheral") or (env._BOOT_MODE_ == "image"): if env._BOOT_DEVICE_ == "floppy": content += "root (fd0)\n" elif env._BOOT_DEVICE_ == "hard-drive": content += "root (hd0)\n" else: env.display(env.HEADER_ERROR, "unknown boot device '" + env._BOOT_DEVICE_ + "'", env.OPTION_NONE) sys.exit(42) elif env._BOOT_MODE_ == "network": content += "ifconfig --address=" + env._ADDRESS_ + " --server=" + \ env._TFTP_ADDRESS_ + "\n" + \ "root (nd)\n" else: env.display(env.HEADER_ERROR, "unknown boot mode '" + env._BOOT_MODE_ + "'", env.OPTION_NONE) sys.exit(42) # retrieve the grub modules from the _COMPONENTS_ environment variables. g_components = re.split("[ \t]+", env._COMPONENTS_.strip()) # set the first component as the grub kernel. content += re.sub("^.*\/", "kernel /modules/", g_components[0]) + "\n" # set the other components as grub modules. for component in g_components[1:]: content += re.sub("^.*\/", "module /modules/", component) + "\n" # create the temporary file and fill it. g_menu = env.temporary(env.OPTION_FILE) env.push(g_menu, content, env.OPTION_NONE)
def build(): # warn the user before performing any action. warning() # display some stuff. env.display(env.HEADER_NONE, "", env.OPTION_NONE) env.display(env.HEADER_OK, "initializing the boot device", env.OPTION_NONE) # for each boot mode, initialize the boot device. if (env._BOOT_MODE_ == "peripheral") or (env._BOOT_MODE_ == "network"): env.push(env._UDEVICE_, env.pull(g_image, env.OPTION_NONE), env.OPTION_NONE) elif env._BOOT_MODE_ == "image": env.copy(g_image, env._IMAGE_, env.OPTION_NONE) else: env.display(env.HEADER_ERROR, "unknown boot mode '" + env._BOOT_MODE_ + "'", env.OPTION_NONE) sys.exit(42)
def build(): handle = None header_file = None # warn the user before performing any action. warning() # creates the mips_bios.bin and the modules files env.push(g_qemu_mips_bios, "", None) env.push(g_components_file, "", None) # creates the flag file header_file = open(g_header_file, "wb"); # write the flag header_file.write(struct.pack("<l", 0x07070707)) header_file.close() # display some stuff. env.display(env.HEADER_OK, "header, components and mipsel_bios.bin files created", env.OPTION_NONE)
def generate(functions, inventory): prototypes = [] tests = [] content = None # display. env.display(env.HEADER_OK, "generating the inventory file", env.OPTION_NONE) # build the array content. for function in functions: prototypes += ["void %s(void);" % function] tests += [ ' { "%(symbol)s", %(function)s },' % { "symbol": function, "function": function } ] # generate the fil content. content = """ /* * note that should the kaneton bundle be used through the test system, * the bundle must be generated with the _test_ module activated, in addition * to the _bundle_ module. * * the following prevents the generation of the array of tests so that * the test system fails to compile a kaneton snapshot with a bundle * which has not been generated with the _test_ module. * * therefore, using such an invalid bundle should result with an error * similar to the following: * * [EXECUTABLE] /home/user/kaneton/kaneton/kaneton * kaneton/modules/modules.lo: In function `module_test_locate': * (.text+0x55a1f): undefined reference to `_module_test_functions' * kaneton/kaneton/modules/modules.lo: In function `module_test_locate': * (.text+0x55a3c): undefined reference to `_module_test_functions' * kaneton/kaneton/modules/modules.lo: In function `module_test_locate': * (.text+0x55a58): undefined reference to `_module_test_functions' * kaneton/kaneton/modules/modules.lo: In function `module_test_dump': * (.text+0x55b1c): undefined reference to `_module_test_functions' * kaneton/kaneton/modules/modules.lo: In function `module_test_dump': * (.text+0x55b26): undefined reference to `_module_test_functions' * kaneton/kaneton/modules/modules.lo:(.text+0x55b50): more undefined references to `_module_test_functions' follow * collect2: ld returned 1 exit status * make[3]: *** [/home/user/kaneton/kaneton/kaneton] Error 1 * make[2]: *** [_] Error 42 * make[1]: *** [main] Error 42 * make: *** [_] Error 42 * * these errors show that the test system has not been able to link the * kaneton snapshot to test with the bundle because a specific definition * is missing: _module_test_functions. this is the test array definied * in this file! */ #ifdef MODULE_test # include <kaneton.h> %(prototypes)s ms_test_function _module_test_functions[] = { %(tests)s { NULL, NULL } }; #endif """ % { "prototypes": "\n".join(prototypes), "tests": "\n".join(tests) } # finally, write the file env.push(inventory, content, env.OPTION_NONE)