Beispiel #1
0
def hudson_to_task(JOB_NAME, BUILD_NUMBER, BUILD_ID):
    task = Task.query.get_by_name(JOB_NAME)
    if task:
        input = []
        output = []
        id = []
        caseall_id = []
        casefail_id = []
        other = []

        if request.method == 'POST' and request.headers.get(
                "Referer") == 'izpautotest':
            #tmp1 = ['0','0','0']
            #tmp_timing = time.strftime('%H:%M:%S',time.gmtime(tmp2-float(task.timing)))
            #tmp2 = time.mktime(tuple(int(i) for i in str(BUILD_NUMBER).replace('_','-').split('-') + tmp1))
            try:
                tmp_timing = BUILD_NUMBER.replace(
                    '_', ' ')[0:10] + BUILD_NUMBER.replace('-', ':').replace(
                        '_', ' ')[10:]
                post_data = request.values.to_dict()
                taskcount = Taskcount()
                taskcount.task_id = task.id
                taskcount.case_all = len(task.case)
                if len(task.case) == len(eval(post_data.get('success'))):
                    taskcount.fail_case = str(caseall_id)
                else:
                    for name in task.case:
                        case = Case.query.get_by_title(name)
                        caseall_id.append(case.id)
                    for i in caseall_id:
                        if str(i) not in post_data.get('success'):
                            casefail_id.append(i)
                    taskcount.fail_case = str(casefail_id)
                taskcount.case_pass = post_data.get('case_pass')
                taskcount.case_fail = taskcount.case_all - eval(
                    taskcount.case_pass)
                taskcount.result_path = post_data.get('result_path')
                taskcount.build_id = BUILD_ID
                taskcount.timing = tmp_timing
                task.timing = tmp_timing
                task.hudson = 4
                name = task.name
                fail_num = taskcount.case_fail
                db.session.add(taskcount)
                db.session.add(task)
                db.session.commit()
                db.session.remove()
                clear_cache()
                if fail_num:

                    subject = defaultconfig().MAIL_SUBJECT % (name,
                                                              str(fail_num))
                    body = defaultconfig().MAIL_BODY % name
                    mail_send(subject, body, defaultconfig().MAIL_RECEIVER)

                return 'OK'
Beispiel #2
0
def showstat(id=1):
    parents = ModuleType.query.get_parent()
    nodes = Taskcount.query.data(id)
    task = Task.query.get_or_404(id)
    HUDSON = defaultconfig().HUDSON
    LOG_URL = defaultconfig().LOG_URL

    task = Task.query.get_or_404(id)
    #task.permissions.view.test(403)
    return render_template('task/showstat.html', task=task, parents=parents,
                           nodes=nodes, HUDSON=HUDSON, LOG_URL=LOG_URL)
Beispiel #3
0
def showstatByname(name):
    task = Task.query.get_by_name(name)
    if task:
        parents = ModuleType.query.get_parent()
        nodes = Taskcount.query.data(task.id)
        HUDSON = defaultconfig().HUDSON
        LOG_URL = defaultconfig().LOG_URL

        task = Task.query.get_or_404(task.id)
        #task.permissions.view.test(403)
        return render_template('task/showstat.html', task=task, parents=parents,
                               nodes=nodes, HUDSON=HUDSON, LOG_URL=LOG_URL)
    return render_template('errors/403.html')
Beispiel #4
0
def showstat(id=1):
    parents = ModuleType.query.get_parent()
    nodes = Taskcount.query.data(id)
    task = Task.query.get_or_404(id)
    HUDSON = defaultconfig().HUDSON
    LOG_URL = defaultconfig().LOG_URL

    task = Task.query.get_or_404(id)
    #task.permissions.view.test(403)
    return render_template('task/showstat.html',
                           task=task,
                           parents=parents,
                           nodes=nodes,
                           HUDSON=HUDSON,
                           LOG_URL=LOG_URL)
Beispiel #5
0
def upload_file(AddCodeForm):
    folder = str(g.user) + "/" + str(AddCodeForm.name.data)
    sys_path = defaultconfig().UPLOADED_FILES_DEST + folder
    os.system("mkdir -p " + sys_path)
    os.system("chmod 777 " + sys_path)
    print sys_path
    os.system("rm -rf " + sys_path + "/*")
    print "zhengwei"
    uploadfile = up.save(AddCodeForm.path.data, folder=folder)
    print uploadfile
    filename = uploadfile.split('/')[-1]
    print filename
    os.chdir(sys_path)
    os.system("mv " + filename + " izptest." + filename.rsplit('.', 1)[1])

    if filename.rsplit('.', 1)[1] in ["zip"]:
        cmd1 = "unzip izptest.zip"
    elif filename.rsplit('.', 1)[1] in ["tar"]:
        cmd1 = "tar -xf izptest.tar"
    os.system(cmd1)
    os.system("rm izptest." + filename.rsplit('.', 1)[1])
    os.system("mv * izptest/")
    os.chdir(sys_path + '/izptest')
    os.system("hg init")
    os.system("hg add *")
    os.system("hg commit -m 'add'")
    return "izptest"
Beispiel #6
0
def addcode():
    form = AddCodeForm(next=request.referrer)
    form.related_module.choices = [
        (item.id, _(item.name))
        for item in ModuleType.query.get_allsubmodule()
    ]
    if form.validate_on_submit():
        code = Code()
        try:
            if form.path.has_file():
                try:
                    filename = upload_file(form)
                except:
                    flash(u"错误的压缩文件内容,请重新上传", "error")
                    return redirect(url_for("code.addcode"))
            code.author_id = g.user.id
            form.populate_obj(code)
            code.path = unicode(defaultconfig().CODE_URL + str(g.user) + "/" +
                                str(form.name.data) + "/" + filename)
            code.parent_id = ModuleType.query.get_or_404(
                form.related_module.data).parent_id
            db.session.add(code)
            db.session.commit()
            clear_cache()
            flash(u"Add {0} successfully!".format(code.name), "success")
            return redirect(form.next.data or url_for("code.showcode"))
        except:
            flash(u"错误的文件类型,只允许ZIP或TAR", "error")
            return redirect(url_for("code.addcode"))
    parents = ModuleType.query.get_parent()
    nodes = ModuleType.query.get_allsubmodule()
    return render_template('code/code.html',
                           form=form,
                           parents=parents,
                           nodes=nodes)
Beispiel #7
0
def showstatByname(name):
    task = Task.query.get_by_name(name)
    if task:
        parents = ModuleType.query.get_parent()
        nodes = Taskcount.query.data(task.id)
        HUDSON = defaultconfig().HUDSON
        LOG_URL = defaultconfig().LOG_URL

        task = Task.query.get_or_404(task.id)
        #task.permissions.view.test(403)
        return render_template('task/showstat.html',
                               task=task,
                               parents=parents,
                               nodes=nodes,
                               HUDSON=HUDSON,
                               LOG_URL=LOG_URL)
    return render_template('errors/403.html')
Beispiel #8
0
def delcode(code_id):
    code = Code.query.get_or_404(code_id)
    code.permissions.delete.test(403)
    cmd = "rm -rf " + defaultconfig().UPLOADED_FILES_DEST + str(
        g.user) + "/" + str(code.name)
    os.system(cmd)
    db.session.delete(code)
    db.session.commit()
    clear_cache()
    flash(u"{0} has been deleted".format(code.name), "success")
    return redirect(request.referrer or url_for("code.showcode"))
Beispiel #9
0
def init_configure_app(app, config):
    if config is not None:
        app.config.from_object(config)
    else:
        app.config.from_object(defaultconfig())
    app.config.from_envvar('IZPPY_SET', silent=True)
Beispiel #10
0
# -*- coding: utf-8 -*-
"""
    extensions.py
    ~~~~~~~~~~~

    flask extension initialization.(not contain flask-principal!)

    :copyright: (c) 2013.
    :license: BSD, see LICENSE for more details.
"""

from flask.ext.mail import Mail
from flask.ext.cache import Cache
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.uploads import UploadSet, ARCHIVES
from izppy.hudson import Hudson
from izppy.config import defaultconfig


mail = Mail()
db = SQLAlchemy()
cache = Cache()
up = UploadSet('files', ARCHIVES)
hud = Hudson(url=defaultconfig().HUDSON)
Beispiel #11
0
# -*- coding: utf-8 -*-
"""
    extensions.py
    ~~~~~~~~~~~

    flask extension initialization.(not contain flask-principal!)

    :copyright: (c) 2013.
    :license: BSD, see LICENSE for more details.
"""

from flask.ext.mail import Mail
from flask.ext.cache import Cache
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.uploads import UploadSet, ARCHIVES
from izppy.hudson import Hudson
from izppy.config import defaultconfig

mail = Mail()
db = SQLAlchemy()
cache = Cache()
up = UploadSet('files', ARCHIVES)
hud = Hudson(url=defaultconfig().HUDSON)
Beispiel #12
0
def clear_cache():
    clear(defaultconfig().CACHE_REDIS_HOST,
          defaultconfig().CACHE_REDIS_PORT,
          defaultconfig().CACHE_REDIS_DB)
Beispiel #13
0
def clear_cache():
    clear(defaultconfig().CACHE_REDIS_HOST, defaultconfig().CACHE_REDIS_PORT,
          defaultconfig().CACHE_REDIS_DB)
Beispiel #14
0
def hudson_to_task(JOB_NAME, BUILD_NUMBER, BUILD_ID):
    task = Task.query.get_by_name(JOB_NAME)
    if task:
        input = []
        output = []
        id = []
        caseall_id = []
        casefail_id = []
        other = []

        if request.method == 'POST' and request.headers.get("Referer") == 'izpautotest':
            #tmp1 = ['0','0','0']
            #tmp_timing = time.strftime('%H:%M:%S',time.gmtime(tmp2-float(task.timing)))
            #tmp2 = time.mktime(tuple(int(i) for i in str(BUILD_NUMBER).replace('_','-').split('-') + tmp1))
            try:
                tmp_timing = BUILD_NUMBER.replace('_', ' ')[0:10] + BUILD_NUMBER.replace('-', ':').replace('_', ' ')[10:]
                post_data = request.values.to_dict()
                taskcount = Taskcount()
                taskcount.task_id = task.id
                taskcount.case_all = len(task.case)
                if len(task.case) == len(eval(post_data.get('success'))):
                    taskcount.fail_case = str(caseall_id)
                else:
                    for name in task.case:
                        case = Case.query.get_by_title(name)
                        caseall_id.append(case.id)
                    for i in caseall_id:
                        if str(i) not in post_data.get('success'):
                            casefail_id.append(i)
                    taskcount.fail_case = str(casefail_id)
                taskcount.case_pass = post_data.get('case_pass')
                taskcount.case_fail = taskcount.case_all - eval(taskcount.case_pass)
                taskcount.result_path = post_data.get('result_path')
                taskcount.build_id = BUILD_ID
                taskcount.timing = tmp_timing
                task.timing = tmp_timing
                task.hudson = 4
                name = task.name
                fail_num = taskcount.case_fail
                db.session.add(taskcount)
                db.session.add(task)
                db.session.commit()
                db.session.remove()
                clear_cache()
                if fail_num:

                        subject = defaultconfig().MAIL_SUBJECT % (name, str(fail_num))
                        body = defaultconfig().MAIL_BODY % name
                        mail_send(subject, body, defaultconfig().MAIL_RECEIVER)

                return 'OK'
            except:
                return abort(401)
        for case_title in task.case:
            case = Case.query.get_by_title(case_title)
            if case:
                if case.usecase_input:
                    input.append(case.usecase_input)
                else:
                    input.append('')
                if case.usecase_output:
                    output.append(case.usecase_output)
                else:
                    output.append('')
                if case.other:
                    other.append(case.other)
                else:
                    other.append('')
                id.append(case.id)
        if len(input) == len(output) == len(id):
            return jsonify(input=input, output=output, id=id, other=other)
        else:
            input = []
            output = []
            id = []
            other = []
            return jsonify(input=input, output=output, id=id, other=other)
    return 'fail'