Exemple #1
0
def list(request):
    if 'generate' in request.POST:
        # 生成测试数据请求
        generateAifangTestData(request.user.id)
        return redirect(list)

    if 'set' in request.POST:
        # 测试数据应用到测试环境请求
        setAifangTestDatabaseTo(request.user.id, request.POST['set'])
        return redirect(list)

    if 'unlock' in request.GET:
        locker.unlock('setAifangTestDatabaseTo')
        locker.unlock('generateAifangTestData')
        return redirect(list)

    versions = DataVersion.objects.order_by('-created')[:20]
    for version in versions:
        version.generator = User.objects.get(id=version.generator) if version.generator else None
        version.publisher = User.objects.get(id=version.publisher) if version.publisher else None

    current_version = (DataVersion.objects.filter(published__isnull=False).order_by('-published')[:1] or [None])[0]
    dumping = locker.hasLocked('generateAifangTestData')
    setting = locker.hasLocked('setAifangTestDatabaseTo')

    return {
        'versions': versions,
        'dumping': dumping,
        'setting': setting,
        'current_version': current_version
    }
Exemple #2
0
    def importIn(publisher, versionId):
        try:
            locker.lock('setAifangTestDatabaseTo')

            version = DataVersion.objects.get(id=versionId)

            dbIns = db(set='aifang_dev')
            dbIns.importIn(dumpFile(version.name), 'aifangcrm_db')

            version.published = datetime.now()
            version.publisher = publisher
            version.save()

        except:
            # todo
            pass
        finally:
            locker.unlock('setAifangTestDatabaseTo')
Exemple #3
0
    def generate(generator):
        locker.lock('generateAifangTestData')

        dbIns = db(set='aifang_backup')
        databases = getTablesFromDumpSql()

        # dump 数据到文件
        for (database, table, where) in databases:
            dbIns.dump(dumpFile(versionName()), database, table, where)

        # dump 完成后,压缩
        os.popen("gzip %s -9" % dumpFile(versionName()))

        # 生成版本信息
        DataVersion(
            name=versionName(),
            created=time.strftime("%Y-%m-%d %X", time.localtime()),
            generator=generator
        ).save()

        locker.unlock('generateAifangTestData')