Esempio n. 1
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"
Esempio n. 2
0
def editcode(code_id):
    code = Code.query.get_or_404(code_id)
    code.permissions.edit.test(403)
    form = EditCodeForm(code, next=request.referrer)
    form.related_module.choices = [
        (item.id, _(item.name))
        for item in ModuleType.query.get_allsubmodule()
    ]
    if form.validate_on_submit():
        if form.path.has_file():
            filename = up.save(form.path.data)
            print filename
            code.path = unicode(filename, "gbk")
            print code.path + "/n"
        code.code_update_time = datetime.now()
        code.parent_id = ModuleType.query.get_or_404(
            form.related_module.data).parent_id
        form.populate_obj(code)
        if code.parent_id != ModuleType.query.\
                get_or_404(form.related_module.data).parent_id:
            code.parent_id = ModuleType.query.\
                get_or_404(form.related_module.data).parent_id
        code.code_update_time = datetime.now()
        code.code_update_time = datetime.now()
        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"Update {0} informatiion successfully".format(code.name),
              "success")
        return redirect(form.next.data or url_for("code.showcode"))
    parents = ModuleType.query.get_parent()
    nodes = ModuleType.query.get_allsubmodule()
    return render_template('code/code.html',
                           form=form,
                           parents=parents,
                           nodes=nodes)