def select(): if request.method == 'POST': fields = dict() for field,value in request.form.iteritems(): fields[field] = value # Retrieve experiment folders valid_plugins = get_plugins("%s/plugins" %(app.tmpdir),load=True) plugins = [x[0]["tag"] for x in valid_plugins] selected_plugins = [x for x in fields.values() if x in plugins] plugin_folders = ["%s/plugins/%s" %(app.tmpdir,x) for x in selected_plugins] # Add to the application app_dest = "%s/app" %(app.tmpdir) generate_app(app_dest,app_repo="%s/python"%app.tmpdir, plugin_repo="%s/plugins"%app.tmpdir, plugins=selected_plugins) # Clean up clean_up("%s/plugins"%(app.tmpdir)) # Zip up application zipped = make_zip(app_dest,"%s/wordfish.zip" %(os.getcwd())) return send_file(zipped, attachment_filename='wordfish.zip', as_attachment=True) return render_template('index.html')
def make_plugin_folders(analysis_dir): ''' Makes output directories for all plugins defined in the package for which a corpus, terms, or relationships extraction is defined. ''' installdir = get_installdir() installed_plugins = get_plugins("%s/plugins" %(installdir),load=True) folders = ["corpus","terms","relations"] for installed_plugin in installed_plugins: tag = installed_plugin[0]["tag"] for folder in folders: make_plugin_folder(analysis_dir,folder,tag,installed_plugin[0][folder],"True")
def make_plugin_folders(analysis_dir): ''' Makes output directories for all plugins defined in the package for which a corpus, terms, or relationships extraction is defined. ''' installdir = get_installdir() installed_plugins = get_plugins("%s/plugins" % (installdir), load=True) folders = ["corpus", "terms", "relations"] for installed_plugin in installed_plugins: tag = installed_plugin[0]["tag"] for folder in folders: make_plugin_folder(analysis_dir, folder, tag, installed_plugin[0][folder], "True")
def generate_app(app_dest, app_repo=None, plugin_repo=None, plugins=None): '''generate create an app (python module) from a template and list of plugins Parameters ========== app_dest: path folder to generate the app (python module) in app_repo: path full path to wordfish-python (template) repo plugins: list full paths to plugin folders for inclusion ''' # We can only generate an in a folder that does not exist, to be safe if not os.path.exists(app_dest): if app_repo == None or plugin_repo == None: tmpdir = custom_app_download() if app_repo == None: app_repo = "%s/python" % (tmpdir) if plugin_repo == None: plugin_repo = "%s/plugins" % (tmpdir) # Copy app skeleton to destination copy_directory(app_repo, app_dest) valid_plugins = get_plugins(plugin_repo) # If the user wants to select a subset if plugins != None: subset_plugins = [ x for x in valid_plugins if os.path.basename(x) in plugins ] valid_plugins = subset_plugins # Generate the requirements.txt from template to include all python dependencies for plugins generate_requirements(valid_plugins, app_dest) # Copy valid plugins into app_repo move_plugins(valid_plugins, app_dest) # Generate run commands setup_extraction(valid_plugins, app_dest) else: print("Folder exists at %s, cannot generate." % (battery_dest))
def generate_app(app_dest,app_repo=None,plugin_repo=None,plugins=None): '''generate create an app (python module) from a template and list of plugins Parameters ========== app_dest: path folder to generate the app (python module) in app_repo: path full path to wordfish-python (template) repo plugins: list full paths to plugin folders for inclusion ''' # We can only generate an in a folder that does not exist, to be safe if not os.path.exists(app_dest): if app_repo == None or plugin_repo == None: tmpdir = custom_app_download() if app_repo == None: app_repo = "%s/python" %(tmpdir) if plugin_repo == None: plugin_repo = "%s/plugins" %(tmpdir) # Copy app skeleton to destination copy_directory(app_repo,app_dest) valid_plugins = get_plugins(plugin_repo) # If the user wants to select a subset if plugins != None: subset_plugins = [x for x in valid_plugins if os.path.basename(x) in plugins] valid_plugins = subset_plugins # Generate the requirements.txt from template to include all python dependencies for plugins generate_requirements(valid_plugins,app_dest) # Copy valid plugins into app_repo move_plugins(valid_plugins,app_dest) # Generate run commands setup_extraction(valid_plugins,app_dest) else: print("Folder exists at %s, cannot generate." %(battery_dest))
def validate(): logo = None if request.method == 'POST': fields = dict() for field,value in request.form.iteritems(): fields[field] = value # Prepare temp folder with cloned wordfish-python and wordfish-plugins custom_app_download(tmpdir=app.tmpdir) # Get valid plugins to present to user valid_plugins = get_plugins("%s/plugins/" %(app.tmpdir),load=True) corpus = get_corpus(valid_plugins) terms = get_terms(valid_plugins) return render_template('plugins.html', corpus=str(corpus), terms=str(terms), this_many_corpus = len(corpus), this_many_terms = len(terms)) return render_template('index.html')