def import_script(script_name=None, level_name=None): # get name of script file if not script_name: #if script_file not defined while True: print "Please enter the name of the script file." print "The current working directory is " print print os.getcwd() script_name = raw_input("Path to .6vscript file: ") if not script_name: print "You must specify a script to import." continue else: try: with open(script_name): pass except IOError: print 'File not found.' else: break print # Checks whether level_name specified beforehand (for quiet execution) while not level_name: print "Please enter the filename of the level" print "(do not include .vvvvvv or else bad things will happen)" level_name = utils.get_level_name() if not level_name: print "You must enter a level name" # backup level file print "Backing up level file..." backup_file = utils.level_backup(level_name) print "Backup saved to " + backup_file # get raw level data from file level_data = utils.get_raw_data(utils.get_vvvvvv_dir(), level_name) # get raw script data from file raw_script_data = utils.get_script_filedata(script_name) # convert script data to raw data script_data = utils.script_to_raw(raw_script_data) if not script_data: raise IOError # Adding script data to level data in memory utils.import_script_data(level_data, script_data) # going hot! success = utils.write_level_data(utils.get_vvvvvv_dir(), level_name, level_data) if success: print "File successfully written." else: print "An error occurred when writing the file."
def extract(level_name=None, save_file=None): # Initializing variables filedata = "" script_data = None vvvvvv_dir = None # Get current opsys vvvvvv_dir = utils.get_vvvvvv_dir() # Checks whether level_name specified beforehand (for quiet execution) if not level_name: # request filename from user while True: level_name = None level_name = utils.get_level_name() if not level_name: print "You must enter a level name" continue # get level data raw_data = utils.get_raw_data(vvvvvv_dir, level_name) if not raw_data: print "Error: level does not exist" continue else: break else: raw_data = utils.get_raw_data(vvvvvv_dir, level_name) # get script data script_data = utils.get_script_data(raw_data) if not script_data: print "No script found" quit() final_data = utils.cleanup_data(script_data) print "Done!" # checks if save_file specified beforehand (for quiet execution) if not save_file: cwd = os.getcwd() print print "What file do you wish me to save the data to?" print "Current working directory is: " print print cwd print print "You may enter a filename to save in current directory," print "enter a relative path, or a full path." print print "Else, press return to accept the default, which is: " print print level_name + ".6vscript" print save_file = raw_input("Save file: ") if not save_file: save_file = level_name + ".6vscript" else: pass with open(save_file, 'w') as outfile: for line in final_data: outfile.write(line + '\n') print save_file + " written"