def makePatch(_currentVersionPath, _previousVersionPath, _currentVersionPatchPath): patchCount = 0 for dirPath, dirNames, fileNames in os.walk(_currentVersionPath): for f in fileNames: newerFile = os.path.join(dirPath, f) olderFile = os.path.join( dirPath.replace(_currentVersionPath, _previousVersionPath), f) tempPath = newerFile.replace(_currentVersionPath, _currentVersionPatchPath) try: if hashlib.md5(open( newerFile, 'rb').read()).hexdigest() != hashlib.md5( open(olderFile, 'rb').read()).hexdigest(): patchCount += 1 if not os.path.exists(os.path.dirname(tempPath)): os.makedirs(os.path.dirname(tempPath)) myshutil.copyfile(newerFile, tempPath) #except IOError as e: #print "I/O error({0}): {1}".format(e.errno, e.strerror) except: patchCount += 1 if not os.path.exists(os.path.dirname(tempPath)): os.makedirs(os.path.dirname(tempPath)) myshutil.copyfile(newerFile, tempPath) #t = 1 #print "Unknown" print _currentVersionPatchPath + "\n" + " have " + str( patchCount) + " files are diff" + "\n"
def renameFolder(): try: os.rename(localSourceFullPath + "\\Bin64", localSourceFullPath + "\\G6Bin64") except: print "Full G6Bin64 already exist." try: os.rename(localSourceTrialPath + "\\Bin64", localSourceTrialPath + "\\G6Bin64") except: print "Lite G6Bin64 already exist." try: os.remove(localSourceFullPath + "\\G6Bin64\\ccprcustombuild.bin") except: print "No ccprcustombuild.bin detected in Full." try: os.remove(localSourceTrialPath + "\\G6Bin64\\ccprcustombuild.bin") except: print "No ccprcustombuild.bin detected in Lite." try: myshutil.copyfile( localSourceFullPath + "\\Program\\Default\\filemap.ini", localFolder + extraData + "\\Program\\Default\\filemap.ini") except: print "Error filemap.ini."
def compare_two_folders(_a, _b, _common, _noneCommon): same_count = 0 diff_count = 0 print _a + "\n" + "compare to" + "\n" + _b for dirPath, dirNames, fileNames in os.walk(_a): #print dirPath for f in fileNames: try: aFile = os.path.join(dirPath, f) bFile = os.path.join(dirPath.replace(_a, _b), f) if hashlib.md5(open(aFile, 'rb').read()).hexdigest() == hashlib.md5( open(bFile, 'rb').read()).hexdigest(): same_count += 1 commonPath = aFile.replace(_a, _common) if not os.path.exists(os.path.dirname(commonPath)): os.makedirs(os.path.dirname(commonPath)) myshutil.copyfile(aFile, commonPath) else: diff_count += 1 noneCommonPath = aFile.replace(_a, _noneCommon) if not os.path.exists(os.path.dirname(noneCommonPath)): os.makedirs(os.path.dirname(noneCommonPath)) myshutil.copyfile(aFile, noneCommonPath) except IOError as e: print "I/O error({0}): {1}".format(e.errno, e.strerror) except: print "Unknown Error" print " same_count:" + str(same_count) print " diff_count:" + str(diff_count) + "\n"
def recursive_overwrite(src, dest, pbar, ignore=None): if os.path.isdir(src): if not os.path.isdir(dest): os.makedirs(dest) files = os.listdir(src) if ignore is not None: ignored = ignore(src, files) else: ignored = set() for f in files: if f not in ignored: recursive_overwrite(os.path.join(src, f), os.path.join(dest, f), pbar, ignore) else: global file_copy_progress_count file_copy_progress_count = file_copy_progress_count + 1 myshutil.copyfile(src, dest) pbar.update(file_copy_progress_count)