Example #1
0
def tool_debug(user, msg, sesn, ctx=None):
    from Bulu import tb_event, tb_message

    sesn = PrefixDict(rawdict=sesn, prefix="debug")
    if msg == "who":
        return str(user)
    elif msg == "stc":
        dbcon = ctx.con
        dba = SinDBAccess(dbcon, debug=False)
        count = dba.get_count(tb_event)
        sub = dba.get_count(tb_event, conditions={"eventid": 1, "type": "weixin"})
        unsub = dba.get_count(tb_event, conditions={"eventid": 2, "type": "weixin"})
        mcount = dba.get_count(tb_message, conditions={"dir": 1})
        if "sub" in sesn:
            pres = "新增\n---订阅:%s\n---退订:%s\n---消息:%s\n" % (
                sub - sesn["sub"],
                unsub - sesn["unsub"],
                mcount - sesn["mcount"],
            )
        else:
            pres = ""
        sesn["sub"] = int(sub)
        sesn["unsub"] = int(unsub)
        sesn["count"] = int(count)
        sesn["mcount"] = int(mcount)

        return "%s统计\n---订阅: %s\n---退订: %s\n---剩余: %s\n---总数: %s\n---消息:%s" % (
            pres,
            sub,
            unsub,
            sub - unsub,
            count,
            mcount,
        )
    elif msg == "last":
        from sinlibs.utils.timeutils import stamp2str

        dba = SinDBAccess(ctx.con, debug=False)
        return "\n".join(
            [
                "%s %s" % (stamp2str(int(o["time"]), "%m-%d %H:%M"), o["message"])
                for o in dba.get_objects(tb_message, conditions={"dir": 1}, order="id desc", limit=15)
            ]
        )
    return "unkown"
Example #2
0
def runtest(kvdb):
    if not 'reuslts' in kvdb:
        kvdb['reuslts'] = []
    if not 'testindex' in kvdb or kvdb['testindex'] == None:
        kvdb['testindex'] = 0
    if not 'premailtime' in kvdb:
        kvdb['premailtime'] = 0
    
    testindex = kvdb['testindex']
    if testindex >= len(testlist):
        keys = ['name', 'cost', 'result', 'start', 'message']
        mail = '\n----\n'.join(['\n'.join(['%s:%s' % (k, tr[k]) for k in keys]) for tr in kvdb['reuslts']])
        kvdb['reuslts'] = []
        kvdb['testindex'] = 0
        
        if (time.time() - kvdb['premailtime']) > (60 * 60 * 12) or (False in [r['result'] for r in kvdb['reuslts']] and (time.time() - kvdb['premailtime']) > (60 * 60)):
            web.sendmail(web.config.smtp_username, '*****@*****.**', 'AutoTest', mail)
            kvdb['premailtime'] = time.time()
            return mail 
        return 'unmail~'
    else:
        test = testlist[testindex]
        sttime = time.time()
        okflag = test.runtest()
        edtime = time.time()
        oftime = edtime - sttime
        tres = {
                 'name':test.name,
                 'cost':oftime,
                 'result':okflag,
                 'start':timeutils.stamp2str(sttime),
                 'message':okflag
                 }
        result = kvdb['reuslts']
        result.append(tres)
        kvdb['reuslts'] = result
        kvdb['testindex'] = testindex + 1
        print 't %s' % kvdb['testindex']
        return json.dumps(tres)