Ejemplo n.º 1
0
def read(path):
    doc = minidom.parse(path)
    fileDatas = []
    fileDict = {}
    fileTags = doc.getElementsByTagName('File')
    for fileTag in fileTags :
        relativePath = fileTag.getAttributeNode('RelativePath').nodeValue
        md5 = fileTag.getAttributeNode('Md5').nodeValue
        size = fileTag.getAttributeNode('Size').nodeValue
        fileData = FileData(parentPath='', relativePath=relativePath, md5=md5, size=size)
        fileDatas.append(fileData)
        fileDict[fileData.relativePath] = fileData
    fileScanner = FileScanner()
    fileScanner.initFromXml(fileDatas, fileDict);
    return fileScanner
Ejemplo n.º 2
0
def read(path):
    doc = minidom.parse(path)
    fileDatas = []
    fileDict = {}
    fileTags = doc.getElementsByTagName('File')
    for fileTag in fileTags:
        relativePath = fileTag.getAttributeNode('RelativePath').nodeValue
        md5 = fileTag.getAttributeNode('Md5').nodeValue
        size = fileTag.getAttributeNode('Size').nodeValue
        fileData = FileData(parentPath='',
                            relativePath=relativePath,
                            md5=md5,
                            size=size)
        fileDatas.append(fileData)
        fileDict[fileData.relativePath] = fileData
    fileScanner = FileScanner()
    fileScanner.initFromXml(fileDatas, fileDict)
    return fileScanner
Ejemplo n.º 3
0
def process(ctx=Context()):
    try:
        Log.printInfoln('==============开始打包==============')
        if not os.path.isdir(ctx.resPath):
            Log.printInfoln('源目录不存在, resPath : ' + ctx.resPath)
            return

        if os.path.exists(ctx.getOutputPath()):
            shutil.rmtree(ctx.getOutputPath(), True)
            Log.printDetailln('删除目录 : ' + ctx.getOutputPath())

        if os.path.exists(ctx.getTempPath()):
            shutil.rmtree(ctx.getTempPath(), True)
            Log.printDetailln('删除目录 : ' + ctx.getTempPath())

        # 不管新包还是旧包,release数据备份都不已md5命名,只有export里用md5命名
        if os.path.exists(ctx.getExportPath()):
            shutil.rmtree(ctx.getExportPath(), True)
            Log.printDetailln('删除目录 : ' + ctx.getExportPath())

        Log.printInfo('【1/4】<1/1> 扫描并计算MD5...')
        ctx.curScanner = FileScanner()
        ctx.curScanner.initFromRootPath(ctx.resPath)
        Log.printInfoln('完成')

        os.makedirs(ctx.getDataFolder(), exist_ok=True)

        # 路径比较的时候加入root前缀,然后判断是不是同一个文件,不需要直接判断相对路径
        ctx.folderPackList = PackHelper.getFolderPackList(ctx.resPath)

        # 从output文件件到release文件夹的备份
        if ctx.isNew or ctx.lastReleasePath == '':
            Log.printInfo('复制完整文件夹, from : ' + ctx.resPath + ", to : " +
                          ctx.getOutputResPath() + ' ...')
            shutil.copytree(ctx.resPath, ctx.getOutputResPath())
            Log.printInfoln('完成')
            if not PackProcess.process(ctx):
                return
            Log.printInfo('复制完整文件夹, from : ' + ctx.getOutputResPath() +
                          ", to : " + ctx.getReleaseOutputPath() + ' ...')
            shutil.copytree(ctx.getOutputPath(), ctx.getReleaseOutputPath())
            Log.printInfoln('完成')
        else:
            removeSet = set()
            if not compareAndPack(ctx, removeSet):
                return
            Log.printInfo('复制最近release版本 to : ' + ctx.getReleaseOutputPath() +
                          ' ...')
            shutil.copytree(ctx.lastReleasePath, ctx.getReleaseOutputPath())
            Log.printInfoln('完成')

            Log.printInfo('删除失效文件(' + str(len(removeSet)) + '个)...')
            # 删除removeSet中的文件和文件夹
            for removeRelPath in removeSet:
                removeAbsPath = os.path.join(
                    ctx.getReleaseOutputPath() + os.sep + 'res', removeRelPath)
                if not os.path.exists(removeAbsPath):
                    continue
                if os.path.isfile(removeAbsPath):
                    os.remove(removeAbsPath)
                elif os.path.isdir(removeAbsPath):
                    shutil.rmtree(removeAbsPath)

            dir_util.copy_tree(ctx.getOutputPath(), ctx.getReleaseOutputPath())
            Log.printInfoln('完成')

        # 生成xml-before
        Log.printInfo('生成Xml-before...')
        beforeXml = ctx.getReleaseOutputPath() + os.sep + Constant.BEFORE_XML
        XmlMgr.write(beforeXml, ctx.curScanner.fileList)
        Log.printInfoln('完成')

        # 生成xml-after
        Log.printInfo('生成Xml-after...')
        afterScanner = FileScanner()
        afterScanner.initFromRootPath(ctx.getReleaseOutputPath() + os.sep +
                                      'res')
        afterXml = ctx.getReleaseOutputPath() + os.sep + Constant.AFTER_XML
        XmlMgr.write(afterXml, afterScanner.fileList)
        Log.printInfoln('完成')

        os.makedirs(ctx.getExportPath(), exist_ok=True)

        Log.printInfo('导出变更文件到export目录...')
        if ctx.isFull:
            for r, d, fileList in os.walk(ctx.getReleaseOutputPath() + os.sep +
                                          'res'):
                for file in fileList:
                    srcAbsPath = os.path.join(r, file)
                    relativePath = os.path.relpath(srcAbsPath,
                                                   ctx.getReleaseOutputPath())
                    targetPath = os.path.join(
                        ctx.getExportPath(),
                        relativePath + '_' + PackHelper.calcMd5(srcAbsPath))
                    os.makedirs(os.path.dirname(targetPath), exist_ok=True)
                    shutil.copyfile(srcAbsPath, targetPath)
        else:
            for r, d, fileList in os.walk(ctx.getOutputPath()):
                for file in fileList:
                    srcAbsPath = os.path.join(r, file)
                    relativePath = os.path.relpath(srcAbsPath,
                                                   ctx.getOutputPath())
                    targetPath = os.path.join(
                        ctx.getExportPath(),
                        relativePath + '_' + PackHelper.calcMd5(srcAbsPath))
                    os.makedirs(os.path.dirname(targetPath), exist_ok=True)
                    shutil.copyfile(srcAbsPath, targetPath)
        xmlMd5 = PackHelper.calcMd5(afterXml)

        # 生成文件列表
        shutil.copyfile(afterXml, ctx.getExportPath() + os.sep + xmlMd5)

        # 生成version文件
        output = open(ctx.getExportPath() + os.sep + 'version.html', 'w')
        output.write('{\n')
        output.write('\tmd5:\"' + xmlMd5 + '\"\n')
        output.write('}')
        output.close()
        Log.printInfoln('完成')

    except:
        t, v, tb = sys.exc_info()
        print(t, v)
        traceback.print_tb(tb)
Ejemplo n.º 4
0
def process(ctx=Context()):
    try:
        Log.printInfoln('==============开始打包==============')
        if not os.path.isdir(ctx.resPath) :
            Log.printInfoln('源目录不存在, resPath : ' + ctx.resPath)
            return;
        
        if os.path.exists(ctx.getOutputPath()) :
            shutil.rmtree(ctx.getOutputPath(), True)
            Log.printDetailln('删除目录 : ' + ctx.getOutputPath())
        
        if os.path.exists(ctx.getTempPath()) :
            shutil.rmtree(ctx.getTempPath(), True)
            Log.printDetailln('删除目录 : ' + ctx.getTempPath())
            
        # 不管新包还是旧包,release数据备份都不已md5命名,只有export里用md5命名
        if os.path.exists(ctx.getExportPath()) :
            shutil.rmtree(ctx.getExportPath(), True)
            Log.printDetailln('删除目录 : ' + ctx.getExportPath())
            
        Log.printInfo('【1/4】<1/1> 扫描并计算MD5...')
        ctx.curScanner = FileScanner()
        ctx.curScanner.initFromRootPath(ctx.resPath)
        Log.printInfoln('完成')
        
        os.makedirs(ctx.getDataFolder(), exist_ok=True)
        
        # 路径比较的时候加入root前缀,然后判断是不是同一个文件,不需要直接判断相对路径
        ctx.folderPackList = PackHelper.getFolderPackList(ctx.resPath)
        
        # 从output文件件到release文件夹的备份
        if ctx.isNew or ctx.lastReleasePath == '':
            Log.printInfo('复制完整文件夹, from : ' + ctx.resPath + ", to : " + ctx.getOutputResPath() + ' ...')
            shutil.copytree(ctx.resPath, ctx.getOutputResPath())
            Log.printInfoln('完成')
            if not PackProcess.process(ctx) :
                return
            Log.printInfo('复制完整文件夹, from : ' + ctx.getOutputResPath() + ", to : " + ctx.getReleaseOutputPath() + ' ...')
            shutil.copytree(ctx.getOutputPath(), ctx.getReleaseOutputPath())
            Log.printInfoln('完成')
        else :
            removeSet = set()
            if not compareAndPack(ctx, removeSet) :
                return
            Log.printInfo('复制最近release版本 to : ' + ctx.getReleaseOutputPath() + ' ...')
            shutil.copytree(ctx.lastReleasePath, ctx.getReleaseOutputPath())
            Log.printInfoln('完成')
            
            Log.printInfo('删除失效文件(' + str(len(removeSet)) + '个)...')
            # 删除removeSet中的文件和文件夹
            for removeRelPath in removeSet :
                removeAbsPath = os.path.join(ctx.getReleaseOutputPath() + os.sep + 'res', removeRelPath)
                if not os.path.exists(removeAbsPath) :
                    continue
                if os.path.isfile(removeAbsPath) :
                    os.remove(removeAbsPath)
                elif os.path.isdir(removeAbsPath) :
                    shutil.rmtree(removeAbsPath)
            
            dir_util.copy_tree(ctx.getOutputPath(), ctx.getReleaseOutputPath())
            Log.printInfoln('完成')
            
        # 生成xml-before
        Log.printInfo('生成Xml-before...')
        beforeXml = ctx.getReleaseOutputPath() + os.sep + Constant.BEFORE_XML
        XmlMgr.write(beforeXml, ctx.curScanner.fileList)
        Log.printInfoln('完成')
        
        # 生成xml-after
        Log.printInfo('生成Xml-after...')
        afterScanner = FileScanner()
        afterScanner.initFromRootPath(ctx.getReleaseOutputPath() + os.sep + 'res')
        afterXml = ctx.getReleaseOutputPath() + os.sep + Constant.AFTER_XML
        XmlMgr.write(afterXml, afterScanner.fileList)
        Log.printInfoln('完成')
        
        os.makedirs(ctx.getExportPath(), exist_ok=True)
        
        Log.printInfo('导出变更文件到export目录...')
        if ctx.isFull :
            for r, d, fileList in os.walk(ctx.getReleaseOutputPath() + os.sep + 'res') :
                for file in fileList :
                    srcAbsPath = os.path.join(r, file)
                    relativePath = os.path.relpath(srcAbsPath, ctx.getReleaseOutputPath())
                    targetPath = os.path.join(ctx.getExportPath(), relativePath + '_' + PackHelper.calcMd5(srcAbsPath))
                    os.makedirs(os.path.dirname(targetPath), exist_ok=True)
                    shutil.copyfile(srcAbsPath, targetPath)
        else :
            for r, d, fileList in os.walk(ctx.getOutputPath()) :
                for file in fileList :
                    srcAbsPath = os.path.join(r, file)
                    relativePath = os.path.relpath(srcAbsPath, ctx.getOutputPath())
                    targetPath = os.path.join(ctx.getExportPath(), relativePath + '_' + PackHelper.calcMd5(srcAbsPath))
                    os.makedirs(os.path.dirname(targetPath), exist_ok=True)
                    shutil.copyfile(srcAbsPath, targetPath)
        xmlMd5 = PackHelper.calcMd5(afterXml)
        
        # 生成文件列表
        shutil.copyfile(afterXml, ctx.getExportPath() + os.sep + xmlMd5)
        
        # 生成version文件
        output = open(ctx.getExportPath() + os.sep + 'version.html', 'w')
        output.write('{\n')
        output.write('\tmd5:\"' + xmlMd5 + '\"\n')
        output.write('}')
        output.close()
        Log.printInfoln('完成')
        
    except :
        t, v, tb = sys.exc_info()
        print(t, v)
        traceback.print_tb(tb)