def load(wb_id): wb = get_object_or_404(models.Workbench, id=wb_id) wbtmis = models.Workbenchtemplatemappingitem.objects.filter( workbenchtemplate=wb.workbenchtemplate).order_by('vieworder') if wbtmis.count() > 60: # mysql won't join more than 61 tables. # but the following is slower so only use in that case. return load_gt_61_cols(wb_id) select_fields = ["r.workbenchrowid"] for wbtmi in wbtmis: select_fields.append("cell%d.celldata" % wbtmi.vieworder) from_clause = ["workbenchrow r"] for wbtmi in wbtmis: from_clause.append("left join workbenchdataitem cell%(vieworder)d " "on cell%(vieworder)d.workbenchrowid = r.workbenchrowid " "and cell%(vieworder)d.workbenchtemplatemappingitemid = %(wbtmi_id)d" % {'vieworder': wbtmi.vieworder, 'wbtmi_id': wbtmi.id}) sql = '\n'.join([ "select", ",\n".join(select_fields), "from", "\n".join(from_clause), "where workbenchid = %s", "order by r.rownumber", ]) cursor = connection.cursor() cursor.execute(sql, [wb_id]) rows = cursor.fetchall() return http.HttpResponse(toJson(rows), content_type='application/json')
def rows(request, wb_id): wb = get_object_or_404(models.Workbench, id=wb_id) if (wb.specifyuser != request.specify_user): return http.HttpResponseForbidden() if request.method == "GET": return load(wb_id) elif request.method == "PUT": data = json.load(request) return save(wb_id, data)
def upload(request, wb_id, mul_match_action, no_commit, match): wb = get_object_or_404(models.Workbench, id=wb_id) if (wb.specifyuser != request.specify_user): return http.HttpResponseForbidden() args = [ settings.JAVA_PATH, "-Dfile.encoding=UTF-8", "-classpath", shellquote(":".join((os.path.join(settings.SPECIFY_THICK_CLIENT, jar) for jar in CLASSPATH))), "edu.ku.brc.specify.tasks.subpane.wb.wbuploader.UploadCmdLine", "-u", shellquote(request.specify_user.name), "-U", shellquote(settings.MASTER_NAME), "-P", shellquote(settings.MASTER_PASSWORD), "-d", shellquote(settings.DATABASE_NAME), "-b", wb_id, "-c", shellquote(request.specify_collection.collectionname), "-w", shellquote(settings.SPECIFY_THICK_CLIENT), "-x", "false" if no_commit else "true", "-k", "true" if match else "false", "-n", shellquote(mul_match_action) ] if settings.DATABASE_HOST != '': args.extend(["-h", shellquote(settings.DATABASE_HOST)]) output_file = "%s_%s_%s" % (settings.DATABASE_NAME, wb_id, uuid4()) with open(os.path.join(settings.WB_UPLOAD_LOG_DIR, output_file), "w") as f: # we use the shell to start the uploader process to achieve a double # fork so that we don't have to wait() on the child process cmdline = ' '.join( args ) + ' 2> >(egrep "(ERROR)|(UploaderException)|(UploaderMatchSkipException)" >&1) &' logger.debug('starting upload w/ cmdline: %s', cmdline) print cmdline subprocess.call(['/bin/bash', '-c', cmdline], stdout=f) log_fnames = glob( os.path.join(settings.WB_UPLOAD_LOG_DIR, '%s_%s_*' % ( settings.DATABASE_NAME, wb_id, ))) for fname in log_fnames: if os.path.join(settings.WB_UPLOAD_LOG_DIR, output_file) != fname: try: os.remove(fname) except: pass return http.HttpResponse(output_file, content_type="text_plain")
def upload(request, wb_id, no_commit, match): wb = get_object_or_404(models.Workbench, id=wb_id) if (wb.specifyuser != request.specify_user): return http.HttpResponseForbidden() args = [ settings.JAVA_PATH, "-Dfile.encoding=UTF-8", "-classpath", shellquote( ":".join((os.path.join(settings.SPECIFY_THICK_CLIENT, jar) for jar in CLASSPATH)) ), "edu.ku.brc.specify.tasks.subpane.wb.wbuploader.UploadCmdLine", "-u", shellquote(request.specify_user.name), "-U", shellquote(settings.MASTER_NAME), "-P", shellquote(settings.MASTER_PASSWORD), "-d", shellquote(settings.DATABASE_NAME), "-b", wb_id, "-c", shellquote(request.specify_collection.collectionname), "-w", shellquote(settings.SPECIFY_THICK_CLIENT), "-x", "false" if no_commit else "true", "-k", "true" if match else "false", ] if settings.DATABASE_HOST != '': args.extend(["-h", shellquote(settings.DATABASE_HOST)]) output_file = "%s_%s_%s" % (settings.DATABASE_NAME, wb_id, uuid4()) with open(os.path.join(settings.WB_UPLOAD_LOG_DIR, output_file), "w") as f: # we use the shell to start the uploader process to achieve a double # fork so that we don't have to wait() on the child process cmdline = ' '.join(args) + ' 2> >(egrep "(ERROR)|(UploaderException)|(UploaderMatchSkipException)" >&1) &' logger.debug('starting upload w/ cmdline: %s', cmdline) print cmdline subprocess.call(['/bin/bash', '-c', cmdline], stdout=f) log_fnames = glob(os.path.join(settings.WB_UPLOAD_LOG_DIR, '%s_%s_*' % (settings.DATABASE_NAME, wb_id,))) for fname in log_fnames: if os.path.join(settings.WB_UPLOAD_LOG_DIR, output_file) != fname: try: os.remove(fname) except: pass return http.HttpResponse(output_file, content_type="text_plain")