Exemplo n.º 1
0
def execute(limit=1):
    """
    Executes a job
    """

    # no locking here for now, TODO
    jobs = models.Job.objects.filter(status=status.WAITING).order_by('id')[0:limit]
    for job in jobs:
        #logger.info( 'executing %s' % job)
        set_status(job, status=status.RUNNING)
    else:
        logger.info('no jobs are waiting')

    # run the selected jobs        
    for job in jobs:
        logger.info( 'executing %s' % job)
        jobtype = job.json.get('type')
        data = get_data(job)
        try:
            if jobtype == status.INDEXING_JOB:
                jobdefs.indexing_job(data=data)
            else:
                raise Exception ("unknown jobtype")
            job.delete()
        except Exception, exc:
            logger.error(exc)
            set_error(exc, (data, job))
Exemplo n.º 2
0
def result_save_trigger(sender, instance, signal, *args, **kwargs):
    """
    Post save hook for results, creates the thumbnails
    """
    if instance.image:
        try:
            # requires PIL
            size = 300, 300
            import Image  
            img = Image.open(instance.image.path)
            img.thumbnail(size, Image.ANTIALIAS)
            img.save(instance.thumbpath)
        except Exception, exc:
            logger.error(exc)
Exemplo n.º 3
0
def load_users(fname, options):
    "Loads users into the database"

    if not os.path.isfile(fname):
        logger.error('file not found %s' % fname)
        return

    if options.flush:
        "Resets the database with fresh values"
        flush_database()

    # alters site settings
    fix_site_settings()

    # this will be the admin password
    passwd = settings.SECRET_KEY

    # check the lenght of secret key in non debug modes
    if not settings.DEBUG and len(passwd) < 5:
        msg = 'The value of the SECRET_KEY setting is too short. Please make it longer!'
        logger.error(msg)
        sys.exit()
    
    # shorcut to user creatgion
    user_get = User.objects.get_or_create

    # read the file and create the users based on the data in it
    stream = file(fname)
    for row in csv.DictReader( stream ):
        username, email, first_name, last_name = row['username'], row['email'], row['first_name'], row['last_name']
        is_superuser = (row['is_superuser'] == 'yes')
        user, flag = user_get(username=username, email=email, first_name=first_name, last_name=last_name, is_superuser=is_superuser, is_staff=is_superuser)
        if flag:
            logger.debug( 'created user: %s' % user.get_full_name() )
            if username in ('admin', 'demo', 'public'):
                # admin user will get the secret key as password
                user.set_password(passwd)
            else:
                if options.test_mode:
                    # in testmode we will set known passwords
                    # used during functional testing
                    user.set_password( passwd + 'X')
                else:
                    # all other users will need to reset their passwords 
                    user.set_unusable_password()
            user.save()
Exemplo n.º 4
0
def stop(text):
    "Unrecoverable error"
    error(text)
    sys.exit()
Exemplo n.º 5
0
def transform(inpname, outname, format, shift=0, index=False, options=None):
    """
    Transforms reads stored in bedfile to a genetrack input file.
    Requires at least 6 bed columns to access the strand.
    """

    # detect file formats
    if format == "BED":
        CHROM, START, END, STRAND = 0, 1, 2, 5
    elif format == "GFF":
        CHROM, START, END, STRAND = 0, 3, 4, 6
    else:
        raise Exception('Invalid file format' % format)

    # two sanity checks, one day someone will thank me
    if format == 'BED' and inpname.endswith('gff'):
        raise Exception('BED format on a gff file?')
    if format == 'GFF' and inpname.endswith('bed'):
        raise Exception('GFF format on a bed file?')

    # find the basename of the outputname
    basename = os.path.basename(outname)
   
    # two files store intermediate results
    flat = conf.tempdata( '%s.flat' % basename )
    sorted  = conf.tempdata( '%s.sorted' % basename )

    # check for track information on first line, 
    # much faster this way than conditional checking on each line
    fp = file(inpname, 'rU')
    first = fp.readline()
    fp.close()

    # create the reader
    reader = csv.reader(file(inpname, 'rU'), delimiter='\t')

    # skip if trackline exists
    if first.startswith == 'track':
        reader.next()

    # unwind the comments
    list(takewhile(lambda x: x[0].startswith('#'), reader))

    # copious timing info for those who enjoy these
    timer, full = util.Timer(), util.Timer()

    logger.debug("parsing '%s'" % inpname)
    logger.debug("output to '%s'" % outname)

    # create the unsorted output file and apply corrections
    logger.debug("unsorted flat file '%s'" % flat)

    fp = file(flat, 'wt')
    for linec, row in enumerate(reader):
        try:
            chrom, start, end, strand = row[CHROM], row[START], row[END], row[STRAND]
        except Exception, exc:
            first = row[0][0]
            # may be hitting the end of the file with other comments
            if  first == '>':
                break # hit the sequence content of the gff file
            elif first == '#':
                continue # hit upon some comments
            else:
                logger.error(row)
                raise Exception(exc) 

        if strand == '+':
            # on forward strand, 5' is at start
            idx = int(start) + shift
            fwd, rev, val = 1, 0, 1
        elif strand == '-':
            # on reverse strand, 5' is at end
            idx = int(end) - shift
            fwd, rev, val = 0, 1, 1
        else:
            # no strand specified, generate interval centers
            idx = (int(start)+int(end))/2
            fwd, rev, val = 0, 0, 1

        # it is essential be able to sort the index as a string! 
        fp.write('%s\t%012d\t%s\t%s\t%s\n' % (chrom, idx, fwd, rev, val))
Exemplo n.º 6
0
def error500(request):
    "Server error page when debug flag is False"
    context = RequestContext(request)
    exc_type, exc_value, tb = sys.exc_info()
    logger.error(exc_value)
    return html.template( request, name='500.html', debug=exc_value )
Exemplo n.º 7
0
def stop( text ):
    "Unrecoverable error"
    error ( text )
    sys.exit()