Esempio n. 1
0
def main():
    print 'listen run start'
    while True:
        while True:
            # 入库
            try:
                db = MySQLdb.connect(database_host, database_username,
                                     database_password, database1)
                dbc = db.cursor()
                # 编码问题
                db.set_character_set('utf8')
                dbc.execute('SET NAMES utf8;')
                dbc.execute('SET CHARACTER SET utf8;')
                dbc.execute('SET character_set_connection=utf8;')
                sql = 'select * from interface_task_list where is_settime_task = 1 and settime_task_status = 1'
                dbc.execute(sql)
                list = dbc.fetchall()
                dbc.close()
                db.close()
            except:
                common.logInfo("lost mysql connect!")
                time.sleep(60)
                continue
            task_data = []
            for obj in list:
                taskId = obj[0]
                start_time = obj[8]
                task_data.append([taskId, start_time])
            logtime = time.strftime('%H:%M', time.localtime(time.time()))
            print task_data, logtime
            for item in task_data:
                if item[1] == str(logtime):
                    doSth(item[0])
                    break
            time.sleep(60)
Esempio n. 2
0
def doSth(taskId):
    init_task_dir(taskId)
    # 开始生成脚本
    url = 'http://127.0.0.1:5000/build'
    values = {
        "entry": taskId,
    }
    responsedata = HttpUntil.post(url, values, '')
    if responsedata:
        if responsedata['code'] == 0:
            common.logInfo('run and build settime task:' + str(taskId))
    else:
        common.logInfo(
            'can not connect to the server , please check if it has been runned'
        )
    time.sleep(60)
Esempio n. 3
0
def init_task_dir(taskId):
    task_dir = 'app/static/interface_auto/test_src/' + str(taskId)
    if os.path.exists(task_dir):
        print 'test'
        delList = []
        delDir = task_dir
        delList = os.listdir(delDir)
        if len(delList) > 0:
            for f in delList:
                filePath = os.path.join(delDir, f)
                if os.path.isfile(filePath):
                    os.remove(filePath)
                    common.logInfo(filePath + " was removed!")
                elif os.path.isdir(filePath):
                    shutil.rmtree(filePath, True)
                common.logInfo("Directory: " + filePath + " was removed!")
        os.rmdir(task_dir)
        common.logInfo("Directory: " + task_dir + " was removed!")
    else:
        common.logInfo('have no dir:' + task_dir)
Esempio n. 4
0
entry = args.case_entry
task_id = args.task_id
base_host = args.base_host

# entry = '22'
# task_id = '14'
# base_host = 'http://app.xyz.cn'

#开始生成脚本
url = 'http://127.0.0.1:5000/interfaceList'
values = {
    #"entry": args.case_entry,
    "entry": entry,
}
(responsedata, code) = HttpUntil.post(url, values, '')
if responsedata['code'] == 0:
    case_date = responsedata['content']
    loop_make_file(case_date, old_run_case_data, task_id, base_host)
    Home = os.getcwd()
    common.logInfo('now you are in ' + Home)
    os.chdir(Home + '/app/static/interface_auto/test_src/' + task_id)
    os.system("python run_case.py")
    os.chdir(Home)
    common.logInfo('now you are in ' + os.getcwd())

sys.exit(0)
"""
调用方法:python makeTestCase.py -e 3,4 -t 123
"""