Esempio n. 1
0
def clear_library():
    logger.debug("Deleting %d from %s",
                 len(path(library_root()).files()), library_root())
    for f in path(library_root()).files():
        f.unlink()
    for d in path(library_root()).dirs():
        d.rmtree()
Esempio n. 2
0
def efetch(req, id):
    logger.info("Asked to fetch Id: %s", id)
    session = entrez.EntrezSession(library_root())
    abspath = session.fetch_id(id)
    path = getrelpath(abspath)
    try:
        parsing.initial(abspath)
    except:
        messages.error(req,
                       "There was a problem loading file '%s', "
                       "please try again or try a different record."
                       % path)
        return re_search(req)

    path = getrelpath(abspath)
    remaining_args = dict(req.REQUEST.items())
    action = remaining_args.pop('action', 'run')

    if action in ['run', 'config']:
        return HttpResponseRedirect(
            reverse(action, args=[path]) + dict_to_querystring(remaining_args))
    else:
        logger.error("Unknown action %r", action)
        messages.error(req, "Unknown action.")
        return re_search(req)
Esempio n. 3
0
    def clean_entrez_search_term(self):
        cleaned_data = self.cleaned_data
        if cleaned_data.get('entrez_search_term'):
            self.active = 'entrez_search_term'
            self.session = entrez.CachedEntrezSession(library_root())

            self.session.search(cleaned_data['entrez_search_term'])
            logger.debug(
                "Search finished, found %d matches",
                self.session.result_count)
            if self.session.result_count == 1:
                cleaned_data['path'] = getrelpath(self.session.fetch())
            elif self.session.result_count > 1:
                raise forms.ValidationError(
                    "Too many results (%d) found, need 1."
                    " Try refining the search or searching for a RefSeq id."
                    % (self.session.result_count))
            else:
                raise forms.ValidationError("No results found.")