Example #1
0
def buildScriptValidate(triggerScript, sourceScript):
	if os.path.realpath(triggerScript) != os.path.realpath(sourceScript):
		theirBuildScriptFile= open(triggerScript, 'r')
		theirBuildScriptHashes= bArchive.transferAndHash(
								theirBuildScriptFile, bArchive.kAllKnownHashes,
								output= None, detectText= None, changeLineEndingsTo= None,
								blockTransferSize= bConstants.kReadBlockSize
							)[1]
		theirBuildScriptFile.close()
		ourBuildScriptFile= open(sourceScript, 'r')
		ourBuildScriptContentsCompressed= bPythonCompress.compress(ourBuildScriptFile.readline)
		#print [ourBuildScriptContentsCompressed]
		ourBuildScriptFile.close()
		ourBuildScriptHashes= bArchive.transferAndHash(
								cStringIO.StringIO(ourBuildScriptContentsCompressed), bArchive.kAllKnownHashes,
								output= None, detectText= None, changeLineEndingsTo= None,
								blockTransferSize= bConstants.kReadBlockSize
							)[1]
		#print os.path.join(buildBasePath, bConstants.kBuildScriptName),triggerScript
		#print ourBuildScriptHashes,theirBuildScriptHashes
		if not bArchive.hashListsMatch(theirBuildScriptHashes, ourBuildScriptHashes, isText= True):
			#print "Removing ",triggerScript
			os.remove(triggerScript)
			#print "Copying",sourceScript, triggerScript
			#shutil.copy2(sourceScript, triggerScript)
			triggerFile= open(triggerScript, 'w')
			triggerFile.write(ourBuildScriptContentsCompressed)
			triggerFile.close()
			makeExecutable(triggerScript)
			return False
	makeExecutable(triggerScript)
	return True
Example #2
0
	def __download(self, identifier, server):
		#print "__download(",identifier,",",server,")"
		url= server.rsplit('/',1)[0]+'/'+identifier.filename()
		localPath= os.path.join(self.__exportDir, identifier.filename())
		#print "\t","localPath",localPath,url
		source= urllib2.urlopen(url)
		#print "\t","Downloading"
		destination= open(localPath, 'w')
		#print "\t","Saving"
		hash= bArchive.transferAndHash( input= source, output= destination,
			hashers= bArchive.kMD5Hash, blockTransferSize= bConstants.kReadBlockSize,
			detextText= False, changeLineEndingsTo= None
		)[1][0][1] # 1 = hashes (instead of number of lines), 0 = 1st, 1 = digest (instead of algorithm or is text)
		destination.close()
		source.close()
		hashMatch= hash.lower() == identifier.hash().lower()
		#print "\t","hashMatch",hashMatch,"hash",hash,"identifier.hash()",identifier.hash()
		idMatch= False
		if hashMatch:
			#print "\t","Looks good so far"
			exportZip= zipfile.ZipFile(localPath, 'r')
			package= bPackage.Package(exportZip.read(bConstants.kPackageFileName))
			idMatch= package.asID().equals(identifier)
			exportZip.close()
			if idMatch:
				#print "\t","Still looking good"
				identifier.merge(package.asID())
				identifier.merge(bID.ID(localPath))
				identifier.merge(bID.ID(url))
				self.addExport(identifier.filename())
				return identifier
		#print "\t","bummer, we failed"
		os.remove(localPath)
		return None
Example #3
0
	def create(self, package, preferences):
		identifier= package.asID()
		filename= "%s_%s_%x-%x-%x.zip"%(
			identifier.fullName(),
			identifier.filenameVersion(),
			time.time(),
			random.randrange(0,100000),
			os.getpid(),
		)
		intermedeateExportPath= os.path.join(preferences['exports'], filename)
		intermedeateExportFile= bArchive.ZipArchive(intermedeateExportPath, 'w')
		manifestFile= intermedeateExportFile.open(bConstants.kManifestFileNameInExport, 'w')
		signatureFile= intermedeateExportFile.open(bConstants.kSignatureFileNameInExport, 'w')
		bArchive.generate(
			package.directory(), manifestFile, bArchive.kAllKnownHashes, bArchive.kStandardCodecs,
			preferences['key'], signatureFile,
			intermedeateExportFile, detectText= True, blockTransferSize= bConstants.kReadBlockSize,
			skipPaths= package['filterPaths'],
			skipExtensions= package['filterExtensions'],
			skipNames= package['filterNames']
		)
		signatureFile.close()
		manifestFile.close()
		intermedeateExportFile.close()
		intermedeateContents= open(intermedeateExportPath, 'r')
		hash= bArchive.transferAndHash(
			intermedeateContents, bArchive.kMD5Hash, blockTransferSize= bConstants.kReadBlockSize,
			output= None, detectText= False, changeLineEndingsTo= None
		)[1][0][1] # 1 = hashes (instead of number of lines), 0 = 1st, 1 = digest (instead of algorithm or is text)
		finalExportPath= os.path.join(preferences['exports'], identifier.fullName()+"_"+identifier.filenameVersion()+"_"+hash+".zip")
		os.rename(intermedeateExportPath, finalExportPath)
		#print "finalExportPath",finalExportPath,os.path.isfile(finalExportPath)
		identifier.merge(bID.ID(finalExportPath))
		exportURL= preferences['base_url']+"/"+os.path.split(finalExportPath)[1]
		package.addPrevious(identifier)
		package.bumpVersion(bumpPhase= (len(sys.argv) == 3) and ('phase' == sys.argv[2]))
		changesPath= os.path.join(package.directory(), os.path.join(*package['changes'].split('/')))
		changesFile= open(changesPath, "r")
		changes= changesFile.read()
		changesFile.close()
		#print [changes]
		changes= changes.replace(package.changesPattern(), package.changesPattern()+"\n\n<li><b>%(version)s</b><br>\nDescription of changes here\n</li><br>\n\n"%{
			'version': package['version'],
		})
		#print [changes]
		changesFile= open(changesPath, "w")
		changesFile.write(changes)
		changesFile.close()
		#print identifier
		#print identifier.filename()
		self.addExport(identifier.filename())
		return (finalExportPath, exportURL)
Example #4
0
def buildScriptValidate(triggerScript, sourceScript):
    if os.path.realpath(triggerScript) != os.path.realpath(sourceScript):
        theirBuildScriptFile = open(triggerScript, 'r')
        theirBuildScriptHashes = bArchive.transferAndHash(
            theirBuildScriptFile,
            bArchive.kAllKnownHashes,
            output=None,
            detectText=None,
            changeLineEndingsTo=None,
            blockTransferSize=bConstants.kReadBlockSize)[1]
        theirBuildScriptFile.close()
        ourBuildScriptFile = open(sourceScript, 'r')
        ourBuildScriptContentsCompressed = bPythonCompress.compress(
            ourBuildScriptFile.readline)
        #print [ourBuildScriptContentsCompressed]
        ourBuildScriptFile.close()
        ourBuildScriptHashes = bArchive.transferAndHash(
            cStringIO.StringIO(ourBuildScriptContentsCompressed),
            bArchive.kAllKnownHashes,
            output=None,
            detectText=None,
            changeLineEndingsTo=None,
            blockTransferSize=bConstants.kReadBlockSize)[1]
        #print os.path.join(buildBasePath, bConstants.kBuildScriptName),triggerScript
        #print ourBuildScriptHashes,theirBuildScriptHashes
        if not bArchive.hashListsMatch(
                theirBuildScriptHashes, ourBuildScriptHashes, isText=True):
            #print "Removing ",triggerScript
            os.remove(triggerScript)
            #print "Copying",sourceScript, triggerScript
            #shutil.copy2(sourceScript, triggerScript)
            triggerFile = open(triggerScript, 'w')
            triggerFile.write(ourBuildScriptContentsCompressed)
            triggerFile.close()
            makeExecutable(triggerScript)
            return False
    makeExecutable(triggerScript)
    return True
Example #5
0
 def __download(self, identifier, server):
     #print "__download(",identifier,",",server,")"
     url = server.rsplit('/', 1)[0] + '/' + identifier.filename()
     localPath = os.path.join(self.__exportDir, identifier.filename())
     #print "\t","localPath",localPath,url
     source = urllib2.urlopen(url)
     #print "\t","Downloading"
     destination = open(localPath, 'w')
     #print "\t","Saving"
     hash = bArchive.transferAndHash(
         input=source,
         output=destination,
         hashers=bArchive.kMD5Hash,
         blockTransferSize=bConstants.kReadBlockSize,
         detextText=False,
         changeLineEndingsTo=None
     )[1][0][
         1]  # 1 = hashes (instead of number of lines), 0 = 1st, 1 = digest (instead of algorithm or is text)
     destination.close()
     source.close()
     hashMatch = hash.lower() == identifier.hash().lower()
     #print "\t","hashMatch",hashMatch,"hash",hash,"identifier.hash()",identifier.hash()
     idMatch = False
     if hashMatch:
         #print "\t","Looks good so far"
         exportZip = zipfile.ZipFile(localPath, 'r')
         package = bPackage.Package(
             exportZip.read(bConstants.kPackageFileName))
         idMatch = package.asID().equals(identifier)
         exportZip.close()
         if idMatch:
             #print "\t","Still looking good"
             identifier.merge(package.asID())
             identifier.merge(bID.ID(localPath))
             identifier.merge(bID.ID(url))
             self.addExport(identifier.filename())
             return identifier
     #print "\t","bummer, we failed"
     os.remove(localPath)
     return None
Example #6
0
 def create(self, package, preferences):
     identifier = package.asID()
     filename = "%s_%s_%x-%x-%x.zip" % (
         identifier.fullName(),
         identifier.filenameVersion(),
         time.time(),
         random.randrange(0, 100000),
         os.getpid(),
     )
     intermedeateExportPath = os.path.join(preferences['exports'], filename)
     intermedeateExportFile = bArchive.ZipArchive(intermedeateExportPath,
                                                  'w')
     manifestFile = intermedeateExportFile.open(
         bConstants.kManifestFileNameInExport, 'w')
     signatureFile = intermedeateExportFile.open(
         bConstants.kSignatureFileNameInExport, 'w')
     bArchive.generate(package.directory(),
                       manifestFile,
                       bArchive.kAllKnownHashes,
                       bArchive.kStandardCodecs,
                       preferences['key'],
                       signatureFile,
                       intermedeateExportFile,
                       detectText=True,
                       blockTransferSize=bConstants.kReadBlockSize,
                       skipPaths=package['filterPaths'],
                       skipExtensions=package['filterExtensions'],
                       skipNames=package['filterNames'])
     signatureFile.close()
     manifestFile.close()
     intermedeateExportFile.close()
     intermedeateContents = open(intermedeateExportPath, 'r')
     hash = bArchive.transferAndHash(
         intermedeateContents,
         bArchive.kMD5Hash,
         blockTransferSize=bConstants.kReadBlockSize,
         output=None,
         detectText=False,
         changeLineEndingsTo=None
     )[1][0][
         1]  # 1 = hashes (instead of number of lines), 0 = 1st, 1 = digest (instead of algorithm or is text)
     finalExportPath = os.path.join(
         preferences['exports'],
         identifier.fullName() + "_" + identifier.filenameVersion() + "_" +
         hash + ".zip")
     os.rename(intermedeateExportPath, finalExportPath)
     #print "finalExportPath",finalExportPath,os.path.isfile(finalExportPath)
     identifier.merge(bID.ID(finalExportPath))
     exportURL = preferences['base_url'] + "/" + os.path.split(
         finalExportPath)[1]
     package.addPrevious(identifier)
     package.bumpVersion(
         bumpPhase=(len(sys.argv) == 3) and ('phase' == sys.argv[2]))
     changesPath = os.path.join(
         package.directory(), os.path.join(*package['changes'].split('/')))
     changesFile = open(changesPath, "r")
     changes = changesFile.read()
     changesFile.close()
     #print [changes]
     changes = changes.replace(
         package.changesPattern(),
         package.changesPattern() +
         "\n\n<li><b>%(version)s</b><br>\nDescription of changes here\n</li><br>\n\n"
         % {
             'version': package['version'],
         })
     #print [changes]
     changesFile = open(changesPath, "w")
     changesFile.write(changes)
     changesFile.close()
     #print identifier
     #print identifier.filename()
     self.addExport(identifier.filename())
     return (finalExportPath, exportURL)