# Goes to the file location os.chdir(FILE_LOCATION) #hti: how to install hti_OS = mdr.install_OS('README.txt') hti_langs =[mdr.install_language(y, mdr.valid_OS('README.txt')) for y in mdr.valid_language('README.txt')] hti_setup = mdr.user_guided_setup('README.txt') hti_libs = mdr.install_libraries('README.txt') # Obtains the commands to run ALL_COMS = mdr.present_input_files('.') FINAL_COMMANDS = [] for acom in ALL_COMS: # Other languages FINAL_COMMANDS.append(mdr.execute_command(acom)) # All dockerfiles are named the same way {TOKEN}:{10 char hash} namran = hashlib.sha256(str(datetime.datetime.now()).encode('UTF-8')).hexdigest()[:10:] DTAG = (user_tok+':'+namran).lower() # Composes the dockerfile duck = hti_OS+"\n\n\n"+"\n".join(mdr.copy_files_to_image('.')) duck += "\nRUN "+" && ".join(hti_langs) for inst_set in [hti_setup, hti_libs]: if inst_set == []: continue duck += " &&\\\n "+" && ".join(inst_set)
def midas(toktok, Username): if pp.token_test(toktok) == False: return 'Invalid token' if request.method != 'POST': return 'Invalid, no file submitted' file = request.files['file'] try: ALL_USER_DATA = os.listdir( '/home/boincadm/project/api/sandbox_files/DIR_' + str(toktok)) except: return 'User sandbox is not set-up, create a sandbox first' # If no app is provided, it will assume BOINC try: boapp = request.form["app"].lower() if (boapp != "boinc2docker") and (boapp != "volcon"): return "INVALID app" except: boapp = "boinc2docker" # No user can submit jobs with a full allocation assigned_allocation = float(r.get(toktok).decode('UTF-8')) if pp.user_sandbox_size(str(toktok)) > (assigned_allocation * 1073741824): return 'User has exceded asssigned allocation. Current available allocation is ' + str( assigned_allocation) + ' GB' if file.filename == '': return 'Invalid, no file uploaded' if ',' in file.filename: return "ERROR: No ',' allowed in filenames" if ('.tar.gz' not in file.filename) and ('.tgz' not in file.filename): return 'ERROR: Compression file not accepted, file must be .tgz or .tar.gz' new_name = secure_filename(file.filename) file.save(os.path.join(UPLOAD_FOLDER + '/DIR_' + str(toktok), new_name)) try: TAR = tarfile.open(UPLOAD_FOLDER + '/DIR_' + str(toktok) + '/' + new_name) except: return 'ERROR: python cannot open tar file' if not any('README.txt' in str(f) for f in TAR.getmembers()): os.remove(os.path.join(UPLOAD_FOLDER + '/DIR_' + str(toktok), new_name)) return 'ERROR: tar file does not contain mandatory README.txt' # Creates a new MIDAS directory with a new name while True: new_MID = 'MID_' + pp.random_dir_name() if new_MID not in ALL_USER_DATA: break # Checks the README for all necessary inputs TAR_PATH = UPLOAD_FOLDER + '/DIR_' + str(toktok) + '/' + new_MID os.makedirs(TAR_PATH) TAR.extractall(TAR_PATH) if not mdr.valid_README(TAR_PATH + '/README.txt'): shutil.rmtree('/home/boincadm/project/api/sandbox_files/DIR_' + str(toktok) + '/' + new_MID) return 'ERROR: README is not valid' if not mdr.valid_OS(TAR_PATH + '/README.txt'): shutil.rmtree('/home/boincadm/project/api/sandbox_files/DIR_' + str(toktok) + '/' + new_MID) return 'ERROR: OS is not accepted' if not mdr.present_input_files(TAR_PATH): shutil.rmtree('/home/boincadm/project/api/sandbox_files/DIR_' + str(toktok) + '/' + new_MID) return 'ERROR: Not all input files for commands are present' if not mdr.valid_language(TAR_PATH + '/README.txt'): shutil.rmtree('/home/boincadm/project/api/sandbox_files/DIR_' + str(toktok) + '/' + new_MID) return 'ERROR: Language is not accepted' # Avoids cases where no libraries are needed at all if (not mdr.install_libraries(TAR_PATH + '/README.txt')) and ( mdr.install_libraries(TAR_PATH + '/README.txt') != []): shutil.rmtree('/home/boincadm/project/api/sandbox_files/DIR_' + str(toktok) + '/' + new_MID) return 'ERROR: Language does not support libraries' # Creates a redis database with syntax {TOKEN;MID_DIRECTORY:boapp} r.set(toktok + ';' + new_MID, boapp) # Obtains the commands to run ALL_COMS = mdr.present_input_files(TAR_PATH) FINAL_COMMANDS = [] for acom in ALL_COMS: # Other languages FINAL_COMMANDS.append(mdr.execute_command(acom)) complete_command = ";".join(FINAL_COMMANDS) # Adds tags to database # STEM is always assumed cus.complete_tag_work(Username, toktok, "STEM", "CUSTOM", complete_command, boapp, "terminal") return 'File submitted for processing'