css = '' html = html_base html = html.replace('$QUESTION',question_html) if mark: html = html.replace('$FONTCOLOR','green') html = html.replace('$MESSAGE','Correct') else: html = html.replace('$FONTCOLOR','darkred') html = html.replace('$MESSAGE','Incorrect') html = html.replace('$MARKS',str(mark)) html = html.replace('$Q_NUM',str(i+1)) html = html.replace('$CSS',css) file_util.write_string(os.path.join(html_dir,'question_%i.html'%i), html) # generate index HTML file index_html = ''' <html> <head> </head> <body> $INDEX </body> </html> ''' index = '' for i in sorted(questions.keys()): index += "<a href='question_%i.html'>Question %i</a> " % (i,i+1) if questions[i][1]: # if mark is != 0
product_family = 'caesar' question_type = 'caesar' plaintext = '{plaintext}' key = {key} hotspots = {hotspots} ''' if len(sys.argv) != 3: print 'Usage: caesar_generate.py template question_directory' sys.exit(1) try: template = file_util.dynamic_import(sys.argv[1]) except ImportError: print 'Failure while importing', sys.argv[1] sys.exit(2) for group in template.group_list: prefix = group[0] for question_id, (plaintext, key, hotspots) in enumerate(group[1:]): path = os.path.join(sys.argv[2], prefix + str(question_id)) if not os.path.exists(path): os.mkdir(path) config_string = template_string.format(**locals()) file_util.write_string(os.path.join(path, 'cqg_config.py'), config_string)
''' if len(sys.argv) != 3: print 'Usage: caesar_generate.py template question_directory' sys.exit(1) try: template = file_util.dynamic_import(sys.argv[1]) except ImportError: print 'Failure while importing',sys.argv[1] sys.exit(2) for group in template.question_groups: prefix = group[0] question_id = 0 #We should generate the cipher using the alg not load it in... later... for (plaintext, key, hotspots) in group[1:]: path = os.path.join(sys.argv[2], prefix + str(question_id)) if not os.path.exists(path): os.mkdir(path) config_string = template_string config_string = config_string.replace('$p', "'" + plaintext + "'") config_string = config_string.replace('$k', str(key)) config_string = config_string.replace('$h', str(hotspots)) file_util.write_string(os.path.join(path,'cqg_config.py'), config_string) question_id += 1