1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
#!/usr/bin/env python
import os, sys, shutil, re
def replaceStrings(library, licensee, product, licenseKey):
tmpLib = os.path.join(os.environ["INSTALLER_TEMP"], os.path.basename(library) + "_t")
if os.path.exists(tmpLib):
os.remove(tmpLib)
shutil.move(library, tmpLib)
tmpLibFile = open(tmpLib, 'r')
libraryFile = open(library, 'w')
namRe = re.compile(r'(qt_lcnsuser=).{' + str(len(licensee) + 1) + r'}')
prdRe = re.compile(r'(qt_lcnsprod=).{' + str(len(product) + 1) + r'}')
keyRe = re.compile(r'(qt_qevalkey=).{' + str(len(licenseKey) + 1) + r'}')
for line in tmpLibFile.readlines():
line = namRe.sub('\\1' + licensee + '\0', line)
line = prdRe.sub('\\1' + product + '\0', line)
line = keyRe.sub('\\1' + licenseKey + '\0', line)
libraryFile.write(line)
libraryFile.close()
tmpLibFile.close()
os.remove(tmpLib)
def getEditionDefine(licenseKey):
ProductMap = { 'F': 'Universal', 'B': 'Desktop',
'L': 'Desktop Light', 'R': 'Console',
'OPEN': 'Opensource' }
LicenseTypeMap = { 'Z4M': "Evaluation", 'R4M': "Evaluation",
'Q4M': "Evaluation", '34M': "Academic",
'TBM': "Educational" }
if len(licenseKey) == 0:
return 'QT_EDITION_UNKNOWN'
licenseParts = licenseKey.split('-')
productDefine = LicenseTypeMap.get(licenseParts[2], "")
if len(productDefine) == 0:
productDefine = ProductMap.get(licenseParts[0][0], 'QT_EDITION_UNKNOWN')
return productDefine
def readLicenseFile():
licenseKeyPath = os.path.join(os.environ['HOME'], '.qt-license');
licenseKeyRE = re.compile(r"^LicenseKeyExt=(.+)$")
licenseeRE = re.compile(r"^Licensee=(.+)$")
license = open(licenseKeyPath, 'r')
licensee = "Bad Licensee"
product = "Bad Product"
licensekey = "Bad Key"
for line in license:
matchObj = licenseeRE.match(line)
if matchObj:
licensee = matchObj.group(1)
else:
matchObj = licenseKeyRE.match(line)
if matchObj:
licensekey = matchObj.group(1)
product = getEditionDefine(licensekey)
return (licensee, product, licensekey)
def fixLibraries():
licensee, product, licensekey = readLicenseFile()
frameworks = [ "QtCore", "QtGui", "QtNetwork", "QtXml", "QtOpenGL", "QtSql", "Qt3Support", "QtSvg", "QtScript" ]
for framework in frameworks:
frameworkPath = os.path.join(sys.argv[3], 'Library', 'Frameworks', framework + '.framework')
if not os.path.exists(frameworkPath):
continue
os.chdir(os.path.join(frameworkPath, 'Versions', '4.0'))
replaceStrings(framework, licensee, product, licensekey)
if __name__ == "__main__":
fixLibraries()
sys.exit(0)
|