Ejemplo n.º 1
0
 def gdv_create(self,ex):
     from bbcflib import gdv
     project = gdv.get_project(mail=self.globals['gdv']['email'],
                               key=self.globals['gdv']['key'],
                               project_key=self.job.options['gdv_key'])
     if 'error' in project:
         self.log_write("Creating GDV project.")
         project = gdv.new_project( self.globals['gdv']['email'],
                                    self.globals['gdv']['key'],
                                    self.job.description,
                                    self.job.assembly.id,
                                    self.globals['gdv']['url'] )
         self.debug_write("\nGDV project: "+json.dumps(project))
         add_pickle( ex, project, description=set_file_descr("gdv_json",step='gdv',type='py',view='admin') )
     self.job.options['gdv_project'] = project
     return True
Ejemplo n.º 2
0
def main(argv=None):
    parser = None
    try:
        parser = optparse.OptionParser(usage=usage, description=description)
        for opt in opts:
            parser.add_option(opt[0],opt[1],help=opt[2],**opt[3])
        (options, args) = parser.parse_args()
        if options.minilims in module_list:
            M = MiniLIMS(os.path.join(options.basepath,options.minilims+"_minilims"))
        elif os.path.exists(options.minilims):
            M = MiniLIMS(options.minilims)
        else:
            raise Usage("Minilims not found, please specify a path or a module with -m.")
        tags = options.tag
        if tags:
            tags = tags.split(",")
            if tags[0].count("="):
                tags = dict(x.split("=") for x in tags)
            elif tags[0].count(":"):
                tags = dict(x.split(":") for x in tags)
        if options.gdv:
            if tags: tags['type'] = 'sql'
            else: tags = {'type': 'sql'}
        if options.programs:
            if isinstance(options.execution, basestring):
                exlist = M.search_executions(with_description=options.execution)
                if len(exlist) == 0:
                    exlist = M.search_executions(with_text=options.execution)
                if len(exlist) == 0:
                    raise Usage("Execution with key %s not found in %s." %(options.execution,options.minilims))
                exid = max(exlist)
            else:
                exid = int(options.execution or 0)
            exec_data = M.fetch_execution(exid)['programs']
            outfile = options.output and open(options.output,"w") or sys.stdout
            for prog in exec_data:
                pargs = prog['arguments']
                if tags and all([t not in x for x in pargs for t in tags]):
                    continue
                stout = prog['stdout'].encode('ascii','ignore')
                sterr = prog['stderr'].encode('ascii','ignore')
                if pargs[0] == 'bsub': pargs = str(pargs[-1])
                else: pargs = str(" ".join(pargs))
                outfile.write("\n".join([pargs,stout,'',sterr,'','-'*40,'']))
            outfile.close()
            return 0
        files = get_files(options.execution,M,select_param=tags)
        fprefix = ''
        if options.list:
            if options.output and os.path.isdir(options.output):
                options.output = os.path.join(options.output,options.execution+".txt")
            outfile = options.output and open(options.output,"w") or sys.stdout
            outfile.write("\t".join(["type","group","name","path","comment"])+"\n")
        else:
            if not(options.output): options.output = "./"
            if not(os.path.isdir(options.output)):
                options.output, fprefix = os.path.split(options.output)
        if options.gdv:
            gdvpaths = []
            gdvnames = []
        for t in sorted(files.keys()):
            for k,v in files[t].iteritems():
                fpath = os.path.join(M.file_path,k)
                vv = v.split("[")
                fname = fprefix+vv.pop(0)
                comment = ''
                par_dict = {}
                if vv:
                    vv = vv[0].split("]")
                    par_dict = dict(x.split(":") for x in vv.pop(0).split(","))
                    if vv: comment = vv[0].strip().strip("()")
                if not(options.admin) and par_dict.get('view') == 'admin': continue
                if options.list: outfile.write("\t".join([t,par_dict.get('groupId',''),fname,fpath,comment])+"\n")
                if options.copy: shutil.copy(fpath, os.path.join(options.output,fname))
                if options.symlink: os.symlink(fpath, os.path.join(options.output,fname))
                if options.gdv:
                    gdvpaths.append(fpath)
                    gdvnames.append(re.sub('\.sql.*','',str(fname)))
        if options.list and options.output: outfile.close()
        if options.gdv:
            from bbcflib import gdv
            gdvurl = options.gdvurl or gdv.default_url
            gdvproject = gdv.get_project(mail=options.email, key=options.key,
                                         project_key=options.gdv)
            if gdvproject.get('project',{}).get('id',0)>0:
                try:
                    tr = gdv.multiple_tracks( mail=options.email, key=options.key,
                                              project_id=gdvproject['project']['id'],
                                              urls=gdvpaths, names=gdvnames, extensions=['sql']*len(gdvpaths),
                                              force=True, serv_url=gdvurl )
                except Exception, err:
                    raise Usage("GDV Tracks Failed: %s\n" %err)
                print """
*********** GDV project at: ***********
%s/public/project?k=%s&id=%s
***************************************
""" %(gdvurl,gdvproject['project']['download_key'],gdvproject['project']['id'])
        return 0