def mksavefile(prefix): """Wrapper around creating the file to save uploaded files in. Returns the (fd, abspath, relpath) """ # we're using tempfile to ensure the file we get is unique and # aren't overwriting another. fd, abspath = tempfile.mkstemp(dir=app.config['UPLOADS'], prefix=prefix) relpath = getrelpath(abspath) return (fd, abspath, relpath)
def save_track(path): try: pathconfig = build_config(path) config = request.get_json() track = config.get('track') fn = track.get('filename') path = _new_track_file_name(pathconfig, fn) if not track: raise ValueError('Must have a track to save') # track = pyntrack.Track(**track) _pretty_save_track_json(track, path) return jsonify({'filename': getrelpath(path)}) except Exception as e: logger.exception('Error While Saving Track') return flask.make_response(repr(e), 500)
def efetch(id): logger.info("Asked to fetch Id: %s", id) searchsession = entrez.EntrezSession(app.config['UPLOADS']) abspath = searchsession.fetch_id(id) path = getrelpath(abspath) try: parsing.initial(abspath) except: flash("There was a problem loading file '%s', " "please try again or try a different record." % path) return re_search() args = dict(request.args.items()) return redirect(url_for('run_frame', path=path, **args))
def schedule_email(to, path, config): config = main.process('allplots', config, executor=gexec) try: target_file = config.get('allplots_result') assert target_file, \ "Configured for email but didn't get emailable file." # The direct download link for the PS or PDF file. result_link = url_for('raw', path=getrelpath(target_file), _external=True) # build path back to run screen. run_link = url_for('run_frame', path=path, _external=True, **dictforurl(config, exclude=['email'])) task = util.Task(send_email, to, path, config, result_link, run_link) eid = gexec.enqueue(task, after=[target_file]) logger.info("Scheduled email to %r with jobid: %s", to, eid) except: logger.exception("Error scheduling email to send")
def search(): args = dict(request.values.items()) search = args.pop('search', None) if not search: flash('Accession Number Required') return redirect(url_for('start', **args)) sess = entrez.CachedEntrezSession(app.config['UPLOADS']) sess.search(search) logger.debug( "Search finished, found %d matches", sess.result_count) if sess.result_count == 1: relpath = getrelpath(sess.fetch()) return redirect(url_for('run_frame', path=relpath, **args)) elif sess.result_count > 1: flash( "Too many results (%d) found, need 1." " Try refining the search or searching for a RefSeq id." % (sess.result_count)) return flask.render_template('start.html', sess=sess, search=search) else: flash("No results found.") return redirect(url_for('start', **args))