示例#1
0
def writeFile(strPath, astrLines):
	p4Out = P4File.open(strPath, 'w')
	p4Out.write(codecs.BOM_UTF8)
	for strLine in astrLines:
		p4Out.write(strLine)
		p4Out.write('\n')
	p4Out.close()
示例#2
0
def fixBom(strFilePath):
    fIn = open(strFilePath, "r")
    strFile = fIn.read()
    fIn.close()

    # trim off BOM
    nStart = 0
    while (len(strFile) >= nStart + 3) and (strFile[nStart : nStart + 3] == codecs.BOM_UTF8):
        nStart += 3

    fOut = P4File.open(strFilePath, "w")
    fOut.write(codecs.BOM_UTF8)
    fOut.write(strFile[nStart:])
    fOut.close()
def fixBom(strFilePath):
	fIn = open(strFilePath, 'r')
	strFile = fIn.read()
	fIn.close()
	
	# trim off BOM
	nStart = 0
	while (len(strFile) >= nStart + 3) and (strFile[nStart:nStart+3] == codecs.BOM_UTF8):
		nStart += 3
	
	fOut = P4File.open(strFilePath, 'w')
	fOut.write(codecs.BOM_UTF8)
	fOut.write(strFile[nStart:])
	fOut.close()
示例#4
0
def ValidateTemplateContents(strFile, strFilePath, fFix):
	# first, figure out the locale (if any)
	strLocale, strTemplateName = ExtractTemplateAndLocale(strFilePath)
	SetLocale(strLocale)
	
	# first, check for #encoding UTF-8 on line one
	# We can fix this if needed.
	# Read the first line
	astrParts = strFile.split('\n', 1)
	strFirstLine = astrParts[0]
	if (len(astrParts) == 1):
		strRest = ''
	else:
		strRest = astrParts[1]
	
	fSuccess = True
	
	if strFile.find('#encoding UTF-8') == -1:
		if strFile.find('#encoding') != -1:
			print "Error: Template: " + strFilePath + "\n\tShould be #encoding UTF-8. Found other encoding.\n"
			return False
		else:
			if fFix:
				# No encoding present. We can fix it.
				# First, remove the BOM (we'll add it back later)
				if strFirstLine[0:3] == codecs.BOM_UTF8:
					# has BOM, remove it
					strFirstLine = strFirstLine[len(codecs.BOM_UTF8):]
				fOut = P4File.open(strFilePath, 'w')
				fOut.write(codecs.BOM_UTF8)
				fOut.write('#encoding UTF-8')
				fOut.write('\n')
				fOut.write(strFirstLine)
				fOut.write('\n')
				fOut.write(strRest)
				fOut.close()
				strResult = "Fixed"
			else:
				strResult = "Error"
				fSuccess = False
				
			print strResult + ": Template error: " + strFilePath + "\n\t#encoding UTF-8 should be the first line of every template\n"
	
	if fSuccess:
		try:
		    t = template = APIUtil.GetTemplate(strTemplateName)
		except ImportError, e:
		    pass # Ignore import errors, we don't know which imports to use
		except:
示例#5
0
def ValidateTemplateContents(strFile, strFilePath, fFix):
    # first, figure out the locale (if any)
    strLocale, strTemplateName = ExtractTemplateAndLocale(strFilePath)
    SetLocale(strLocale)

    # first, check for #encoding UTF-8 on line one
    # We can fix this if needed.
    # Read the first line
    astrParts = strFile.split('\n', 1)
    strFirstLine = astrParts[0]
    if (len(astrParts) == 1):
        strRest = ''
    else:
        strRest = astrParts[1]

    fSuccess = True

    if strFile.find('#encoding UTF-8') == -1:
        if strFile.find('#encoding') != -1:
            print "Error: Template: " + strFilePath + "\n\tShould be #encoding UTF-8. Found other encoding.\n"
            return False
        else:
            if fFix:
                # No encoding present. We can fix it.
                # First, remove the BOM (we'll add it back later)
                if strFirstLine[0:3] == codecs.BOM_UTF8:
                    # has BOM, remove it
                    strFirstLine = strFirstLine[len(codecs.BOM_UTF8):]
                fOut = P4File.open(strFilePath, 'w')
                fOut.write(codecs.BOM_UTF8)
                fOut.write('#encoding UTF-8')
                fOut.write('\n')
                fOut.write(strFirstLine)
                fOut.write('\n')
                fOut.write(strRest)
                fOut.close()
                strResult = "Fixed"
            else:
                strResult = "Error"
                fSuccess = False

            print strResult + ": Template error: " + strFilePath + "\n\t#encoding UTF-8 should be the first line of every template\n"

    if fSuccess:
        try:
            t = template = APIUtil.GetTemplate(strTemplateName)
        except ImportError, e:
            pass  # Ignore import errors, we don't know which imports to use
        except:
示例#6
0
print "Excluding unchanged files:"
astrExcludeUnchangedFiles.sort()
for strEx in astrExcludeUnchangedFiles:
	print " - " + strEx
print

print "Excluding exclude:"
for strEx in astrExcludeFiles:
	print " - " + strEx
print

# all done
zip.close()

print "new last change number", nMaxChangeNumber
fOut = P4File.open(strLastChangeRecordFilePath, 'w', strChangeDesc)
fOut.write(str(nMaxChangeNumber))
fOut.write("\n")
fOut.close()

# remove temporary files
os.remove(strDiffFilePath)
os.remove(strNewPropsFilePath)

print "Update the snapshot file before running the script: " + strOldPropsFilePath
print "Make sure you check in the snapshot file when you are done: "
dtNow = datetime.now().date()
strNow = str(dtNow)

print '     g4 upload  ' + str(p4c.GetChangeListNumber())
print "email this zip file: " + strZipPath
示例#7
0
	def generate(self, astrUrls, strName, tDims, fGenerateBundles):
		# First, see if we can find these files
		self.dMapUrlToIndex = {}

		strBasePath = os.path.join(os.getcwd(), 'website', 'clipart')
		self.strUrl = '../clipart/bundles/' + strName + ".png"
		strOutPath = os.path.join(strBasePath, self.strUrl)

		# Take the largest of the first three thumbs
		if tDims == None:
			nWidth = 0
			nHeight = 0
			for i in range(0,16):
				if len(astrUrls) > i:
					nWidth2, nHeight2 = self.getDimensions(os.path.join(strBasePath, astrUrls[i]))
					nWidth = max(nWidth, nWidth2)
					nHeight = max(nHeight, nHeight2)
			tDims = (nWidth, nHeight)
		
		if tDims == None:
			raise "no image dimensions!?!"
		
		self.tDims = tDims
		
		nWidth, nHeight = self.tDims

		cTall = math.ceil((len(astrUrls) * nWidth) / 2800.0)
		cWide = math.ceil(1.0 * len(astrUrls) / cTall)
		
		nTotalWidth = cWide * nWidth
		nTotalHeight = cTall * nHeight
		
		if fGenerateBundles: imDest = Image.new('RGBA', (int(nTotalWidth), int(nTotalHeight)))
		
		for i in range(0, len(astrUrls)):
			self.dMapUrlToIndex[astrUrls[i]] = i
			if fGenerateBundles:
				fh = open(os.path.join(strBasePath, astrUrls[i]), 'rb')
				imSrc = Image.open(fh)
				xDest = (i % cWide) * nWidth
				yDest = int(i / cWide) * nHeight
				
				nImWidth, nImHeight = imSrc.size
				
				xDest += int((nWidth - nImWidth)/2)
				yDest += int((nHeight - nImHeight)/2)
				
				# imDest.paste(imSrc, (int(xDest), int(yDest)), imSrc)
				imDest.paste(imSrc, (int(xDest), int(yDest)))
				fh.close()

		if fGenerateBundles:
			p4Out = P4File.open(strOutPath, 'w')
			strBase, strExtension = os.path.splitext(strOutPath)
			strFormat = strExtension.upper()[1:]
			imDest.save(p4Out, strFormat)
			p4Out.close()
		
		self.strUrl += "?" + NoCacheParam(strOutPath)
		
		# def paste(self, im, box=None, mask=None):
		
		# print "strPath = " + strPath + ", " + str(os.path.exists(strPath))
		pass
示例#8
0
def copyFileToPath(locSource, strDestPath, strLang, fFixQuotes):
	# read the source file, escape unescaped quotes, and write it to the dest file
	fOut = P4File.open(strDestPath, 'w')
	copyFile(locSource, fOut, strLang, fFixQuotes)
	fOut.close()
示例#9
0
def writeFile(strPath, strFile):
	fOut = P4File.open(strPath, 'w')
	fOut.write(codecs.BOM_UTF8)
	fOut.write(strFile)
	fOut.close()