Exemple #1
0
def download_server_pcakge(package):
    if package is None:
        return {"success": False, "msg": ""}

    lastPackage = None
    record = DeployRecord.objects(machine=package.machine).order_by("-start_time")
    if len(record) > 0:
        lastPackage = record[0].new_version

    stringIO = StringIO()
    writeTar = tarfile.open(fileobj=stringIO, mode="w:gz")
    addCommonPackageInfo(lastPackage, package, writeTar)

    lastFileMap = {}
    if lastPackage is not None:
        for file in lastPackage.files:
            lastFileMap[file.filePath] = file

    # 与前一个包比较
    for file in package.files:
        rawFile = lastFileMap.get(file.filePath, None)
        if rawFile is None or rawFile.sha1 != file.sha1 or rawFile.size != file.size:
            content = file.file.read()
            strIO = StringIO(content)
            info = tarfile.TarInfo(file.filePath)
            info.mode = file.info.mod
            info.size = len(content)
            info.mtime = time.time()
            writeTar.addfile(info, strIO)
            print "add file %s" % file.filePath

    writeTar.close()
    content = stringIO.getvalue()
    tar_file_path = "../media/temp/%s_%s_%s_update.tar.gz" % (
        package.customer.tag,
        package.machine.name,
        datetime.datetime.now().strftime("%Y%m%d"),
    )
    try:
        fp = open(tar_file_path, "wb")
        fp.write(content)
        fp.close()
        return {"success": True, "msg": tar_file_path}
    except:
        return {"success": False, "msg": "无法创建安装包" % tar_file_path}
Exemple #2
0
def checkRevision(branchInfo, firstBugRevision, lastBugRevision, customer_id):
    deployRecords = DeployRecord.objects(customer=customer_id)
    pkg2revision = dict()
    for dr in deployRecords:
        pkgId = dr.new_version.id
        # limit the update to 'all', 'ttservice', 'base', or other
        revision = getPackageRevision(pkgId, "E:/installPackage/", branchInfo.programName)
        if pkgId not in pkg2revision:
            pkg2revision[pkgId] = revision
        elif revision > pkg2revision[pkgId]:
            pkg2revision[pkgId] = revision
    retRev = -1
    for pkgid, revision in pkg2revision.iteritems():
        if retRev < revision:
            retRev = revision
    if firstBugRevision <= retRev <= lastBugRevision:
        return False  # buggy
    else:
        return True  # normal
Exemple #3
0
def checkRevision(branchInfo, firstBugRevision, lastBugRevision, customer_id):
    deployRecords = DeployRecord.objects(customer=customer_id)
    pkg2revision = dict()
    for dr in deployRecords:
        pkgId = dr.new_version.id
        # limit the update to 'all', 'ttservice', 'base', or other
        revision = getPackageRevision(pkgId, 'E:/installPackage/', branchInfo.programName)
        if pkgId not in pkg2revision:
            pkg2revision[pkgId] = revision
        elif revision > pkg2revision[pkgId]:
            pkg2revision[pkgId] = revision
    retRev = -1
    for pkgid, revision in pkg2revision.iteritems():
        if retRev < revision:
            retRev = revision
    if firstBugRevision <= retRev <= lastBugRevision:
        return False # buggy
    else:
        return True # normal
Exemple #4
0
def download_server_pcakge(package):
    if package is None:
        return {'success': False, 'msg': ''}

    lastPackage = None
    record = DeployRecord.objects(machine=package.machine).order_by("-start_time")
    if len(record) > 0:
        lastPackage = record[0].new_version

    stringIO = StringIO()
    writeTar = tarfile.open(fileobj=stringIO, mode="w:gz")
    addCommonPackageInfo(lastPackage, package, writeTar)

    lastFileMap = {}
    if lastPackage is not None:
        for file in lastPackage.files:
            lastFileMap[file.filePath] = file

    # 与前一个包比较
    for file in package.files:
        rawFile = lastFileMap.get(file.filePath, None)
        if rawFile is None or rawFile.sha1 != file.sha1 or rawFile.size != file.size:
            content = file.file.read()
            strIO = StringIO(content)
            info = tarfile.TarInfo(file.filePath)
            info.mode = file.info.mod
            info.size = len(content)
            info.mtime = time.time()
            writeTar.addfile(info, strIO)
            print 'add file %s' % file.filePath

    writeTar.close()
    content = stringIO.getvalue()
    tar_file_path="../media/temp/%s_%s_%s_update.tar.gz" % (package.customer.tag, package.machine.name, datetime.datetime.now().strftime("%Y%m%d"))
    try:
        fp = open(tar_file_path, 'wb')
        fp.write(content)
        fp.close()
        return {'success':True, 'msg': tar_file_path}
    except:
        return {'success': False, 'msg': '无法创建安装包' % tar_file_path}