Example #1
0
        reread = True
    else:
        running = False


signal.signal(signal.SIGINT, handler)
signal.signal(signal.SIGTERM, handler)
if not agn.iswin:
    signal.signal(signal.SIGUSR1, handler)
    signal.signal(signal.SIGHUP, signal.SIG_IGN)
    signal.signal(signal.SIGPIPE, signal.SIG_IGN)

agn.log(agn.LV_INFO, 'main', 'Starting up')
agn.lock()
data = Data()
while running:
    forcedUpdate = reread
    reread = False
    data.update(forcedUpdate)
    n = delay
    while n > 0 and running and not reread:

        if agn.iswin and agn.winstop():
            running = False
            break
        time.sleep(1)
        n -= 1
data.done()
agn.unlock()
agn.log(agn.LV_INFO, 'main', 'Going down')
Example #2
0
def main ():
    global  term

    signal.signal (signal.SIGINT, handler)
    signal.signal (signal.SIGTERM, handler)

    if not agn.iswin:
        signal.signal (signal.SIGHUP, signal.SIG_IGN)
        signal.signal (signal.SIGPIPE, signal.SIG_IGN)
    #
    opts = getopt.getopt (sys.argv[1:], 'vso:')
    verbose = False
    single = False
    updparm = {}
    use = []
    for opt in opts[0]:
        if opt[0] == '-v':
            agn.outlevel = agn.LV_DEBUG
            agn.outstream = sys.stdout
            verbose = True
        elif opt[0] == '-s':
            single = True
        elif opt[0] == '-o':
            parm = opt[1].split (':', 1)
            if len (parm) == 2:
                v = parm[1].split ('=', 1)
                if len (v) == 1:
                    v.append ('true')
                if updparm.has_key (parm[0]):
                    updparm[parm[0]].append (v)
                else:
                    updparm[parm[0]] = [v]
                if not parm[0] in use:
                    use.append (parm[0])
    for u in opts[1]:
        if not u in use:
            use.append (u)
    updates = []
    for u in use:
        if u == 'bounce':
            nu = UpdateBounce ()
        elif u == 'account':
            nu = UpdateAccount ()
        else:
            nu = None
            agn.log (agn.LV_ERROR, 'main', 'Invalid update: %s' % u)
        if not nu is None:
            if updparm.has_key (u):
                nu.options (updparm[u])
            updates.append (nu)
    if len (updates) == 0:
        agn.die (agn.LV_ERROR, 'main', 'No update procedure found')
    agn.lock ()
    agn.log (agn.LV_INFO, 'main', 'Starting up')

    if True:
        while not term:
            db = None
            agn.mark(agn.LV_INFO, 'loop', 180)
            for upd in updates:
                if not term and upd.shouldRun() and upd.exists():
                    if db is None:
                        db = agn.DBaseID()
                        if db is None:
                            agn.log(agn.LV_ERROR, 'loop', 'Unable to connect to database')
                    if db:
                        if verbose:
                            db.log = lambda a: sys.stdout.write('%s\n' % a)
                        instance = db.cursor()
                        if instance:
                            if not upd.update(instance):
                                agn.log(agn.LV_ERROR, 'loop', 'Update for %s failed' % upd.name)
                            instance.close()
                        else:
                            agn.log(agn.LV_ERROR, 'loop', 'Unable to get database cursor')
            if db:
                db.close()
            if single:
                term = True
            #
            # Zzzzz....
            countDelay = delay
            while countDelay > 0 and not term:

                if agn.iswin and agn.winstop ():
                        term = True
                        break
                time.sleep(1)
                countDelay -= 1
        for upd in updates:
            upd.done()

    agn.log (agn.LV_INFO, 'main', 'Going down')
    agn.unlock ()
Example #3
0
pd = Pickdist()
while not term:
    time.sleep(1)
    agn.mark(agn.LV_INFO, "loop", 180)
    if pd.scanForData() == 0:
        delay = 30
        agn.log(agn.LV_VERBOSE, "loop", "No ready to send data file found")
    else:
        delay = 0
        while not term and pd.hasData():
            queue = pd.queueIsFree()
            if queue is None:
                agn.log(agn.LV_INFO, "loop", "Queue is already filled up")
                delay = 180
                break
            blk = pd.getNextBlock()
            if blk.unpack(queue):
                blk.moveTo(agn.mkArchiveDirectory(pd.archive))
            else:
                blk.moveTo(pd.recover)
    while not term and delay > 0:

        if agn.iswin and agn.winstop():
            term = True
            break
        time.sleep(1)
        delay -= 1
#
agn.log(agn.LV_INFO, "main", "Going down")
agn.unlock()
Example #4
0
def main():
    global term

    signal.signal(signal.SIGINT, handler)
    signal.signal(signal.SIGTERM, handler)

    if not agn.iswin:
        signal.signal(signal.SIGHUP, signal.SIG_IGN)
        signal.signal(signal.SIGPIPE, signal.SIG_IGN)
    #
    opts = getopt.getopt(sys.argv[1:], 'vso:')
    verbose = False
    single = False
    updparm = {}
    use = []
    for opt in opts[0]:
        if opt[0] == '-v':
            agn.outlevel = agn.LV_DEBUG
            agn.outstream = sys.stdout
            verbose = True
        elif opt[0] == '-s':
            single = True
        elif opt[0] == '-o':
            parm = opt[1].split(':', 1)
            if len(parm) == 2:
                v = parm[1].split('=', 1)
                if len(v) == 1:
                    v.append('true')
                if updparm.has_key(parm[0]):
                    updparm[parm[0]].append(v)
                else:
                    updparm[parm[0]] = [v]
                if not parm[0] in use:
                    use.append(parm[0])
    for u in opts[1]:
        if not u in use:
            use.append(u)
    updates = []
    for u in use:
        if u == 'bounce':
            nu = UpdateBounce()
        elif u == 'account':
            nu = UpdateAccount()
        else:
            nu = None
            agn.log(agn.LV_ERROR, 'main', 'Invalid update: %s' % u)
        if not nu is None:
            if updparm.has_key(u):
                nu.options(updparm[u])
            updates.append(nu)
    if len(updates) == 0:
        agn.die(agn.LV_ERROR, 'main', 'No update procedure found')
    agn.lock()
    agn.log(agn.LV_INFO, 'main', 'Starting up')

    if True:
        while not term:
            db = None
            agn.mark(agn.LV_INFO, 'loop', 180)
            for upd in updates:
                if not term and upd.shouldRun() and upd.exists():
                    if db is None:
                        db = agn.DBaseID()
                        if db is None:
                            agn.log(agn.LV_ERROR, 'loop',
                                    'Unable to connect to database')
                    if db:
                        if verbose:
                            db.log = lambda a: sys.stdout.write('%s\n' % a)
                        instance = db.cursor()
                        if instance:
                            if not upd.update(instance):
                                agn.log(agn.LV_ERROR, 'loop',
                                        'Update for %s failed' % upd.name)
                            instance.close()
                        else:
                            agn.log(agn.LV_ERROR, 'loop',
                                    'Unable to get database cursor')
            if db:
                db.close()
            if single:
                term = True
            #
            # Zzzzz....
            countDelay = delay
            while countDelay > 0 and not term:

                if agn.iswin and agn.winstop():
                    term = True
                    break
                time.sleep(1)
                countDelay -= 1
        for upd in updates:
            upd.done()

    agn.log(agn.LV_INFO, 'main', 'Going down')
    agn.unlock()