コード例 #1
0
def setInfo(frameid, **kwdargs):

    locks.frame.acquire()
    rb = False
    try:
        try:
            #session.begin(subtransactions=True)
            rb = True

            fr_rec = getFrame(frameid)

            # NOTE: No type check on values!
            for name, val in kwdargs.items():
                setattr(fr_rec, name, val)

            # Commit!
            session.commit()
            rb = False

            # TODO: "expunge" temp records from session?

        except dbError, e:
            raise g2dbError(e)

    finally:
        try:
            if rb:
                try:
                    session.rollback()
                except Exception, e:
                    # TODO: log exception
                    print str(e)

        finally:
            locks.frame.release()
コード例 #2
0
def resetCount(insname, frtype, prefix, count):
    """Reset a frame counter.  Returns the frame id corresponding to the reset.
    Parameters:
    insname -- instrument name, short form (e.g. 'MOIRCS', 'SPCAM', etc.)
    frtype  -- frame type (e.g. 'A' or 'Q')
    prefix  -- prefix for frame following the frametype
                should be '0'==normal, '7'==engineering, '8'==simulator,
                '9'==summit (defaults to '0')
    count   -- desired count

    USE WITH CAUTION!!!
    """

    locks.frame.acquire()
    rb = False
    try:
        #session.begin(subtransactions=True)
        rb = True

        # Get FrameMap entry
        (ins_rec, frmap_rec) = _get_framemap_name(insname,
                                                  frtype,
                                                  prefix=prefix)

        # Reset count in FrameMap table
        frmap_rec.count = count

        d = {'code': ins_rec.code, 'type': frtype, 'pfx': prefix, 'num': count}

        frameid = str(frame_template % d)

        # Commit!
        session.commit()
        rb = False

        # TODO: "expunge" temp records from session?

        return frameid

    finally:
        try:
            if rb:
                try:
                    session.rollback()
                except Exception, e:
                    # TODO: log exception
                    print str(e)

        finally:
            locks.frame.release()
コード例 #3
0
def getInfo(frameid, **kwdargs):

    locks.frame.acquire()
    rb = False
    try:
        try:
            #session.begin(subtransactions=True)
            #rb = True

            fr_rec = getFrame(frameid)

            # There ought to be a way to get only the attributes that
            # were defined in the schema...
            frameid = str(fr_rec)
            #            res = Bunch.Bunch(frameid=frameid, time_alloc=fr_rec.time_alloc,
            #                              handling=fr_rec.handling, memo=fr_rec.memo)

            res = Bunch.Bunch(frameid=frameid,
                              time_alloc=fr_rec.time_alloc,
                              handling=fr_rec.handling,
                              meta=fr_rec.meta)

            # Commit!

            #session.commit()
            rb = False

            # TODO: "expunge" temp records from session?

            return res

        except dbError, e:
            raise g2dbError(e)

    finally:
        try:
            if rb:
                try:
                    session.rollback()
                except Exception, e:
                    # TODO: log exception
                    print str(e)

        finally:
            locks.frame.release()
コード例 #4
0
def addTransfer(frameid, **paramDict):

    locks.frame.acquire()

    rb = False
    try:
        try:
            #session.begin(subtransactions=True)
            rb = True

            # Get Frame entry
            fr_rec = getFrame(frameid)

            # Add entry to FrameTransfer table
            xfer_rec = FrameTransfer(frame=fr_rec, **paramDict)

            # save to session
            #xfer_rec.save()

            # Commit!
            session.commit()
            rb = False

            # TODO: "expunge" temp records from session?
            return xfer_rec

        except dbError, e:
            raise g2dbError(e)

    finally:
        try:
            if rb:
                try:
                    session.rollback()
                except Exception, e:
                    # TODO: log exception
                    print str(e)

        finally:
            locks.frame.release()
コード例 #5
0
def alloc(insname,
          frtype,
          count=1,
          prefix='0',
          propid=None,
          handling=0,
          memo=None):
    """Get one or more frames.  Returns a list of the frame ids.
    Parameters:
    insname -- instrument name, short form (e.g. 'MOIRCS', 'SPCAM', etc.)
    frtype  -- frame type (e.g. 'A' or 'Q')
    count   -- number of desired frames (defaults to 1)
    prefix  -- prefix for frame following the frametype
                should be '0'==normal, '7'==engineering, '8'==simulator,
                '9'==summit (defaults to '0')
    propid  -- proposal id this frame was allocated under
    """
    locks.frame.acquire()

    rb = False
    try:
        try:
            #session.begin(subtransactions=True)
            rb = True

            # Get FrameMap entry
            (ins_rec, frmap_rec) = _get_framemap_name(insname,
                                                      frtype,
                                                      prefix=prefix)

            fr_num = frmap_rec.count

            d = {'code': ins_rec.code, 'type': frtype, 'pfx': prefix, 'num': 0}

            # This is the time the frames were allocated
            alloc_time = datetime.datetime.now()

            # Construct frame list
            frames = []
            for i in xrange(fr_num, fr_num + count):
                d['num'] = i
                frameid = str(frame_template % d)
                frames.append(frameid)

                # Add frame to Frames table
                frame = Frame(framemap=frmap_rec,
                              number=i,
                              time_alloc=alloc_time,
                              propid=propid,
                              handling=handling,
                              memo=memo)
                # save to session
                #frame.save()

            # Update count in FrameMap table
            frmap_rec.count += count

            # Commit!
            session.commit()
            rb = False

            # TODO: "expunge" temp records from session?
            return frames

        except dbError, e:
            raise g2dbError(e)

    finally:
        try:
            if rb:
                try:
                    session.rollback()
                except Exception, e:
                    # TODO: log exception
                    print str(e)

        finally:
            locks.frame.release()