Beispiel #1
0
             if inp_format == 'relaxedphyliptree':
                 invoc.extend(['-X', '-x'])
             if idPrefix:
                 invoc.append('-t{u}'.format(u=idPrefix))
             else:
                 invoc.append('-g')
                 for k, v in fa_dict.items():
                     if v > 0:
                         f = fa_flag[k]
                         invoc.append('-p{f}{v:d}'.format(f=f, v=v))
             # Use new NCL option to emit only trees and taxa (not character data)
             invoc.append('-etreenexml')
             invoc.append('in.nex')
             do_ext_proc_launch(request,
                                working_dir,
                                invoc,
                                NEXML_FILENAME,
                                ERR_FILENAME,
                                wait=block)
             if not block:
                 time.sleep(timeout_duration)
             status = invoc_status(request, working_dir)
             assert (status != ExternalProcStatus.NOT_FOUND)
             launched_this_call = True
 if status == ExternalProcStatus.RUNNING:
     if not launched_this_call:
         time.sleep(timeout_duration)
         status = invoc_status(request, working_dir)
     if status == ExternalProcStatus.RUNNING:
         return HTTP(102, "Process still running")
 if status == ExternalProcStatus.FAILED:
     try:
Beispiel #2
0
def to_nexml():
    if len(request.args) == 1:
        _LOG = get_logger(request, 'study')
        try:
            field = db['study_file']['file']
        except Error:
            sys.stderr.write('odd\n')
            raise HTTP(404)
        name = request.args[-1]
        sys.stderr.write('looking for file "' + name + '"\n')
        try:
            ext_proc_dir = get_external_proc_dir_for_upload(request, db, name)
        except ValueError:
            raise HTTP(404)
        if ext_proc_dir is None:
            raise HTTP(404)

        #@TEMPORARY could be refactored into a create_ext_proc_subdir() call
        to_nexml_dir = os.path.join(ext_proc_dir, '2nexml')
        if not os.path.exists(to_nexml_dir):
            os.makedirs(to_nexml_dir)
            _LOG.info('Created directory "%s"' % to_nexml_dir)
        block = True
        timeout_duration = 0.1  #@TEMPORARY should not be hard coded

        out_filename = 'out.xml'
        err_filename = 'err.txt'

        #@TEMPORARY could be refactored into a launch_or_get_status() call
        status = invoc_status(request, to_nexml_dir)
        launched_this_call = False
        if status == ExternalProcStatus.NOT_FOUND:
            try:
                try:
                    exe_path = get_conf(request).get("external", "2nexml")
                except:
                    _LOG.warn("Config does not have external/2nexml setting")
                    raise
                assert (os.path.exists(exe_path))
            except:
                _LOG.warn("Could not find the 2nexml executable")
                raise HTTP(
                    501,
                    T("Server is not configured to allow 2nexml conversion"))
            try:
                (filename, upload_stream) = field.retrieve(name)
            except IOError:
                sys.stderr.write('not found\n')
                raise HTTP(404)
            do_ext_proc_launch(request,
                               to_nexml_dir, [exe_path, 'in.nex'],
                               out_filename,
                               err_filename, [('in.nex', upload_stream)],
                               wait=block)
            if not block:
                time.sleep(timeout_duration)
            status = invoc_status(request, to_nexml_dir)
            assert (status != ExternalProcStatus.NOT_FOUND)
            launched_this_call = True
        if status == ExternalProcStatus.RUNNING:
            if not launched_this_call:
                time.sleep(timeout_duration)
                status = invoc_status(request, to_nexml_dir)
            if status == ExternalProcStatus.RUNNING:
                return HTTP(102, T("Process still running"))
        #@TEMPORARY /end of potential launch_or_get_status call...

        if status == ExternalProcStatus.FAILED:
            try:
                err_file = os.path.join(to_nexml_dir, err_filename)
                err_content = 'Error message:\n ' + open(err_file, 'rU').read()
            except:
                err_content = ''
            response.headers['Content-Type'] = 'text/xml'
            raise HTTP(501, T("Conversion to NeXML failed.\n" + err_content))
        output = os.path.join(to_nexml_dir, 'out.xml')
        response.headers['Content-Type'] = 'text/xml'
        return open(output, 'rU').read()

    else:
        raise HTTP(301)
    return response.download(request, db)
Beispiel #3
0
def to_nexml():
    if len(request.args) == 1:
        _LOG = get_logger(request, 'study')
        try:
            field = db['study_file']['file']
        except Error:
            sys.stderr.write('odd\n')
            raise HTTP(404)
        name = request.args[-1]
        sys.stderr.write('looking for file "' + name + '"\n')
        try:
            ext_proc_dir = get_external_proc_dir_for_upload(request, db, name)
        except ValueError:
            raise HTTP(404)
        if ext_proc_dir is None:
            raise HTTP(404)

        #@TEMPORARY could be refactored into a create_ext_proc_subdir() call
        to_nexml_dir = os.path.join(ext_proc_dir, '2nexml')
        if not os.path.exists(to_nexml_dir):
            os.makedirs(to_nexml_dir)
            _LOG.info('Created directory "%s"' % to_nexml_dir)
        block = True
        timeout_duration = 0.1 #@TEMPORARY should not be hard coded

        out_filename = 'out.xml'
        err_filename = 'err.txt'

        #@TEMPORARY could be refactored into a launch_or_get_status() call
        status = invoc_status(request, to_nexml_dir)
        launched_this_call = False
        if status == ExternalProcStatus.NOT_FOUND:
            try:
                try:
                    exe_path = get_conf(request).get("external", "2nexml")
                except:
                    _LOG.warn("Config does not have external/2nexml setting")
                    raise
                assert(os.path.exists(exe_path))
            except:
                _LOG.warn("Could not find the 2nexml executable")
                raise HTTP(501, T("Server is not configured to allow 2nexml conversion"))
            try:
                (filename, upload_stream) = field.retrieve(name)
            except IOError:
                sys.stderr.write('not found\n')
                raise HTTP(404)
            do_ext_proc_launch(request,
                               to_nexml_dir,
                               [exe_path, 'in.nex'],
                               out_filename,
                               err_filename,
                               [('in.nex', upload_stream)],
                               wait=block)
            if not block:
                time.sleep(timeout_duration)
            status = invoc_status(request, to_nexml_dir)
            assert(status != ExternalProcStatus.NOT_FOUND)
            launched_this_call = True
        if status == ExternalProcStatus.RUNNING:
            if not launched_this_call:
                time.sleep(timeout_duration)
                status = invoc_status(request, to_nexml_dir)
            if status == ExternalProcStatus.RUNNING:
                return HTTP(102, T("Process still running"))
        #@TEMPORARY /end of potential launch_or_get_status call...
        
        if status == ExternalProcStatus.FAILED:
            try:
                err_file = os.path.join(to_nexml_dir, err_filename)
                err_content = 'Error message:\n ' + open(err_file, 'rU').read()
            except:
                err_content = ''
            response.headers['Content-Type'] = 'text/xml'
            raise HTTP(501, T("Conversion to NeXML failed.\n" + err_content))
        output = os.path.join(to_nexml_dir, 'out.xml')
        response.headers['Content-Type'] = 'text/xml'
        return open(output, 'rU').read()
        
    else:
        raise HTTP(301)
    return response.download(request, db)
                 raise HTTP(501, T("Server is not configured to allow 2nexml conversion"))
             invoc = [exe_path, '-f{f}'.format(f=inp_format), ]
             if inp_format == 'relaxedphyliptree':
                 invoc.extend(['-X', '-x'])
             if idPrefix:
                 invoc.append('-t{u}'.format(u=idPrefix))
             else:
                 invoc.append('-g')
                 for k, v in fa_dict.items():
                     if v > 0:
                         f = fa_flag[k]
                         invoc.append('-p{f}{v:d}'.format(f=f, v=v))
             invoc.append('in.nex')
             do_ext_proc_launch(request,
                                working_dir,
                                invoc,
                                NEXML_FILENAME,
                                ERR_FILENAME,
                                wait=block)
             if not block:
                 time.sleep(timeout_duration)
             status = invoc_status(request, working_dir)
             assert(status != ExternalProcStatus.NOT_FOUND)
             launched_this_call = True
 if status == ExternalProcStatus.RUNNING:
     if not launched_this_call:
         time.sleep(timeout_duration)
         status = invoc_status(request, working_dir)
     if status == ExternalProcStatus.RUNNING:
         return HTTP(102, "Process still running")
 if status == ExternalProcStatus.FAILED:
     try: