コード例 #1
0
ファイル: updateLocales.py プロジェクト: purrfectt/PicEditor
def UpdateHtml():
	strBaseDir = os.path.join(os.getcwd(), 'website','app')

	for strFile in ['noaccess.html', 'noaccess_guest.html', 'noaccess_registered.html']:
		for dLocaleInfo in LocaleInfo.LocaleListSortedByName():
			astrLocaleLinks = []
			for dLocaleInfo2 in LocaleInfo.LocaleListSortedByName():
				strClass = ''
				if dLocaleInfo2['locale'] == dLocaleInfo['locale']:
					strClass = 'selected'
				astrLocaleLinks.append('\t<a href="/?locale=' + dLocaleInfo2['locale'] + '" class="' + strClass + '">' + dLocaleInfo2['name'] + '</a>')
			strFooterLocaleLinks = "\n\t\t|\n".join(astrLocaleLinks)

			strPath = os.path.join(strBaseDir, dLocaleInfo['locale'], strFile)
			try:
				fin = open(strPath, 'rb')
				strContents = fin.read()
				fin.close()
			except:
				strPath = strPath.replace(dLocaleInfo['locale'], 'en_US')
				print "Reading contents from en_US location: ", strPath
				fin = open(strPath, 'rb')
				strContents = fin.read()
				fin.close()
			
			try:
				strOut = ReplaceGeneratedCode2(strContents, "FooterLocaleList", strFooterLocaleLinks)
			except:
				print "Error writing", strPath
				print "strContents"
				print strContents
				raise

			P4File.p4write(strPath, strOut, "updateLocales")
コード例 #2
0
ファイル: buildXML.py プロジェクト: templeblock/PicEditor
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()
コード例 #3
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()
コード例 #4
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()
コード例 #5
0
ファイル: validate.py プロジェクト: alex4u2nv/PicEditor
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
ファイル: validate.py プロジェクト: templeblock/PicEditor
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:
コード例 #7
0
strDiffFileBase = 'loc/client/en_US'
strDiffFilePath = strDiffFileBase + '/diff.properties'

# Merge files to create the new snapshot
MergeUtil.mergeFilesToPath('client/loc', strNewPropsFilePath) # new props file path is not under p4


# Diff
print "Including changed/new properties: "
if not os.path.exists(strDiffFileBase):
	os.mkdir(strDiffFileBase)
DiffUtil.diffPropsToPath(strOldPropsFilePath, strNewPropsFilePath, strDiffFilePath, True)
print

# Replace old props snapshot with new props
P4File.copyfile(strNewPropsFilePath, strOldPropsFilePath, strChangeDesc)

# open our files
xmlSources = xml.dom.minidom.parse("bin/loc/loc_sources.xml")
strZipPath = os.path.expanduser("~/loc_sources_" + strOutFileExtension + ".zip")
zip = zipfile.ZipFile(strZipPath, "w")

if nLastUpdateChangeNumber == 0:
	nLastUpdateChangeNumber = ReadChangeNumber(strLastChangeRecordFilePath, -1) # default last drop is eons ago

print "nLastUpdateChangeNumber = ", nLastUpdateChangeNumber

# Read list of files to exclude
dtExclude = {}
for node in xmlSources.getElementsByTagName("exclude"):
	if node.nodeType == Node.ELEMENT_NODE:
コード例 #8
0
p4c = GetP4C(strChangeDesc)

# Calculate the max change number
files = p4c.GetFiles(astrFilesToCheck)
nMaxChangeNumber = 0
for i in range(0, len(files)):
	nChange = int(files[i].Change())
	nMaxChangeNumber = max(nMaxChangeNumber, nChange)
		
strOldPropsFileExtension = dGroupInfo['strPropsFileExtension']
astrLocs = dGroupInfo['astrLocs']
strOldPropsFilePath = 'loc/client/props_at_last_drop' + strOldPropsFileExtension + '.properties'

strLastChangeRecordFilePath = 'loc/client/last_sent_change_record' + strOldPropsFileExtension + '.txt'

fOut = P4File.open(strOldPropsFilePath, 'w', strChangeDesc)
fIn = open(strDiffFilePath, 'r')
fOut.write(fIn.read())
fIn.close()
fOut.close()

os.remove(strDiffFilePath)

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

strEmailSubject = "Pincik " + str(datetime.now().date()) + " complete loc sources"
if dGroupInfo != None:
コード例 #9
0
ファイル: buildXML.py プロジェクト: templeblock/PicEditor
	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
コード例 #10
0
ファイル: install_drop.py プロジェクト: templeblock/PicEditor
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()
コード例 #11
0
ファイル: updateLocales.py プロジェクト: purrfectt/PicEditor
def UpdateLocaleInfoAs():
	print "Updating LocaleInfo.as"

	strPath = os.path.join(os.getcwd(), 'as','util','picnik','util','LocaleInfo.as')

	fin = open(strPath, 'rb')
	strContents = fin.read()
	fin.close()
	strInsert =  "\t\tstatic private var _aobAllLocales:Array = [\n\t\t\t"
	fFirst = True

	for dLocaleInfo in LocaleInfo.LocaleListSortedByName():
		if not fFirst:
			strInsert += ",\n\t\t\t"
		strLine = "{"
		fFirstKey = True
		
		# these are the keys we are interested in
		
		dKeys = {
						'label':{'fnGet':lambda x : x['name']},
						'locale':{'sortPriority':0},
						'flag':{'fnGet':lambda x : x['locale'][3:].lower()},
						'useSystemFont':{},
						'nonBold':{},
						'countries':{},
						'googleCode':{},
						'googlePlus':{'fOptional':True}
						}
		
		atKeys = sorted(dKeys.items(), key=lambda t: (t[1].get('sortPriority', 100), t[0]))
		
		for atKeys in atKeys:
			strKey, dKeyInfo = atKeys
			
			if 'fnGet' in dKeyInfo:
				obVal = dKeyInfo['fnGet'](dLocaleInfo)
			else:
				if not (strKey in dLocaleInfo):
					if dKeyInfo.get('fOptional', False):
						continue
					else:
						print "ERROR: Locale missing field: " + strKey
						print dLocaleInfo
						sys.exit(1)
				obVal = dLocaleInfo[strKey]

			if not fFirstKey:
				strLine += ", "
			fFirstKey = False

			strLine += strKey + ": "
			if type(obVal) == type(True):
				strLine += str(obVal).lower()
			elif type(obVal) == type([]):
				strLine += str(obVal)
			else: # everything else is a string
				strLine += "'" + str(obVal) + "'"
				
		strLine += "}"
		strInsert += strLine
		fFirst = False
	strInsert += "\n\t\t];\n"

	strOut = ReplaceGeneratedCode(strContents, "LocaleInfo", strInsert)

	P4File.p4write(strPath, strOut, "updateLocales")
コード例 #12
0
def writeFile(strPath, strFile):
	fOut = P4File.open(strPath, 'w')
	fOut.write(codecs.BOM_UTF8)
	fOut.write(strFile)
	fOut.close()
コード例 #13
0
def copyfile(strSrc, strDest):
	if not os.path.exists(os.path.dirname(strDest)):
		os.mkdir(os.path.dirname(strDest))
	P4File.copyfile(strSrc, strDest, 'dummyloc')