-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbrocre_package_tools.py
210 lines (169 loc) · 8.82 KB
/
brocre_package_tools.py
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
import commands
import string
import os
import sys
import time
from datetime import date
class packageDescription:
def __init__(self):
self.name = ""
self.folder = ""
self.version = ""
self.categories = []
self.installedVersion = ""
self.maintainer = ""
self.homepage = ""
self.license = ""
self.description = ""
self.brief = ""
self.dependencies = []
self.masterSite = ""
self.fileToCheckIfInstall = ""
self.sourcePath = ""
def extractPackagesFromRobotPKGMakefile(MakefilePath):
COMMENT_IN_MAKEFILE = "#"
SUBDIR_STRING = "SUBDIR+="
Makefile = file(MakefilePath)
packageDescriptionFolder = []
#Check every line if it contains SUBDIR+= and is not commented out via '#'
for line in Makefile:
if not COMMENT_IN_MAKEFILE in line and SUBDIR_STRING in line:
# parse line
packageDescriptionFolder.append(line[len(SUBDIR_STRING):].strip())
Makefile.close()
return packageDescriptionFolder
def parsePKGMakefile(filename,currentpackage):
COMMENT_IN_MAKEFILE = "#"
filehandle = file(filename)
for line in filehandle:
if not COMMENT_IN_MAKEFILE in line and "CATEGORIES" in line:
categories = line[line.find("=")+1:].strip()
currentpackage.categories = categories.split(" ")
if not COMMENT_IN_MAKEFILE in line and "PACKAGE_VERSION" in line and currentpackage.version == "":
currentpackage.version = line[line.find("=")+1:].strip()
if not COMMENT_IN_MAKEFILE in line and "MAINTAINER" in line and currentpackage.maintainer == "":
currentpackage.maintainer = line[line.find("=")+1:].strip()
if not COMMENT_IN_MAKEFILE in line and "HOMEPAGE" in line and currentpackage.homepage == "":
currentpackage.homepage = line[line.find("=")+1:].strip()
if not COMMENT_IN_MAKEFILE in line and "LICENSE" in line and currentpackage.license == "":
currentpackage.license = line[line.find("=")+1:].strip()
#filehandle.close()
def extractPackageDescriptions(ROBOTPKG_BASE):
# Parse Makefile which contains Package Description folders
MAKEFILE_NAME = "Makefile"
ROBOT_PACKAGE_PATH = "./"
packageDescriptionFolders = extractPackagesFromRobotPKGMakefile(ROBOT_PACKAGE_PATH + MAKEFILE_NAME)
packageDescriptionsList = dict()
#load hashmap key=Robotpkg Category/Folder, value = packageList
for folder in packageDescriptionFolders:
packageDescriptionsList[folder] = extractPackagesFromRobotPKGMakefile(ROBOT_PACKAGE_PATH + folder +"/"+ MAKEFILE_NAME)
allPackages = []
for folder in packageDescriptionsList.keys():
for package in packageDescriptionsList[folder]:
currentpackage = packageDescription()
parsePKGMakefile(ROBOT_PACKAGE_PATH + folder +"/" + package + "/Makefile", currentpackage)
DESCRfile = file(ROBOT_PACKAGE_PATH + folder +"/" + package +"/DESCR")
currentpackage.description = DESCRfile.read()
DESCRfile.close()
currentpackage.name = package
currentpackage.folder = folder
robotpkgInfoText = commands.getoutput(ROBOTPKG_BASE+"/sbin/robotpkg_info -e "+currentpackage.name)
compareInstalledVersionWithCurrentPackageVersion(robotpkgInfoText,currentpackage)
allPackages.append(currentpackage)
#check for packages which have been install but the package has been removed from brocre
if (os.path.isfile(ROBOTPKG_BASE+"/sbin/robotpkg_info")):
robotpkgInfoText = commands.getoutput(ROBOTPKG_BASE+"/sbin/robotpkg_info -u")
robotpkgInfoText = robotpkgInfoText.split("\n")
for line in robotpkgInfoText:
packageDescriptionAvailable = False
for package in allPackages:
if package.name in line:
packageDescriptionAvailable = True
if line == "" or "pkg_install" in line:
packageDescriptionAvailable = True
if packageDescriptionAvailable == False:
newpackage = packageDescription()
newpackage.name = line.split(" ")[0]
newpackage.categories = ["unknown"]
newpackage.installedVersion = "-"
newpackage.version = "-"
allPackages.append(newpackage)
return allPackages
def compareInstalledVersionWithCurrentPackageVersion(inputtext,currentpackage):
text = inputtext.split("\n")
for line in text:
if currentpackage.name in line:
newline = line.split(" ")
currentpackage.installedVersion = newline[0][len(currentpackage.name)+1:]
def generateBrocreFiles(package):
if not os.path.exists(package.folder+'/'+package.name):
os.makedirs(package.folder+'/'+package.name)
print "create Makefile file"
makefile = open(package.folder+'/'+package.name+'/Makefile', 'w')
versionstring = "PACKAGE_VERSION"
makefile.write("# generated on "+ date.today().__str__() +"\n\n")
makefile.write(versionstring +" = "+ package.version+"\n")
makefile.write("DISTNAME = "+ package.name+"-${"+versionstring+"}\n")
makefile.write("PKGNAME = "+ package.name+"-${"+versionstring+"}\n")
makefile.write("CATEGORIES = " + package.categories + "\n")
makefile.write("MASTER_SITES = "+ package.masterSite+"\n")
makefile.write("MASTER_REPOSITORY = \n\n")
makefile.write("MAINTAINER = " + package.maintainer +"\n")
makefile.write("HOMEPAGE = " + package.homepage +"\n")
makefile.write("COMMENT = " + package.brief +"\n")
makefile.write("LICENSE = " + package.license +"\n\n")
makefile.write("NO_CONFIGURE = yes\nNO_BUILD = yes\nNO_EXTRACT = yes\n\n")
makefile.write("do-install:\n\t${RUN} tar -C $(ROBOTPKG_BASE) -xvf ${DISTDIR}/${DISTNAME}${EXTRACT_SUFX}\n\n")
for depend in package.dependencies:
makefile.write("include ../../" + depend + "/depend.mk\n")
makefile.write("include ../../mk/robotpkg.mk")
makefile.close()
DESCR = open(package.folder+'/'+package.name+'/DESCR', 'w')
DESCR.write(package.description)
DESCR.close()
print "create depend.mk file"
depend_mk = open(package.folder+'/'+package.name+'/depend.mk', 'w')
depend_mk.write("DEPEND_DEPTH:= ${DEPEND_DEPTH}+\n")
depend_mk.write(package.name + "_DEPEND_MK:= ${" + package.name + "_DEPEND_MK}+\n\n")
depend_mk.write("ifeq (+,$(DEPEND_DEPTH))\n")
depend_mk.write("DEPEND_PKG+= "+package.name+"\n")
depend_mk.write("endif\n\n")
depend_mk.write("ifeq (+,$(" + package.name + "_DEPEND_MK))\n")
depend_mk.write("PREFER." + package.name + "?= robotpkg\n\n")
depend_mk.write("DEPEND_USE+= " + package.name + "\n\n")
depend_mk.write("DEPEND_ABI." + package.name + "?= " + package.name + ">=" + package.version + "\n")
depend_mk.write("DEPEND_DIR." + package.name + "?= ../../" + package.folder + "/" + package.name + "\n\n")
depend_mk.write("SYSTEM_SEARCH." + package.name + "="+package.folder+"/"+package.fileToCheckIfInstall + "\n")
depend_mk.write("endif\n\n")
depend_mk.write("DEPEND_DEPTH:= ${DEPEND_DEPTH:+=}\n")
depend_mk.close()
print "create tarball"
tarFileName = package.name +"-"+ package.version+ ".tar.gz"
commands.getoutput("mkdir "+package.sourcePath+"/../"+package.folder)
commands.getoutput("ln -s "+package.sourcePath+" "+package.sourcePath+"/../"+package.folder+"/"+package.name)
commands.getoutput("tar -czf "+tarFileName+" --exclude-vcs -h -C"+ package.sourcePath+"/.. " +package.folder)
#commands.getoutput("tar -czf "+tarFileName+" --exclude-vcs -C"+ package.sourcePath+"/.. " +package.name)
commands.getoutput("rm "+package.sourcePath+"/../"+package.folder+"/"+package.name)
commands.getoutput("rmdir "+package.sourcePath+"/../"+package.folder)
print "create PLIST file"
commands.getoutput("tar -tf "+tarFileName+" | grep -P -v '/$' > "+package.folder+'/'+package.name+"/PLIST")
print "compute checksums"
distinfo = open(package.folder+'/'+package.name+'/distinfo', 'w')
line = commands.getoutput("openssl sha1 "+ tarFileName) + "\n"
line = string.replace(line, "SHA1", "SHA1 ")
line = string.replace(line, ")=", ") =")
distinfo.write(line)
line = commands.getoutput("openssl rmd160 "+ tarFileName) + "\n"
line = string.replace(line, "RIPEMD160", "RMD160 ")
line = string.replace(line, ")=", ") =")
distinfo.write(line)
filesize = os.path.getsize(tarFileName)
distinfo.write("Size (" + tarFileName + ") = " + str(filesize) + " bytes")
distinfo.close()
print "Finished"
if __name__ == "__main__":
if len(sys.argv) < 6:
print "Please specify the parameters:\n"
print "python gen_brocre_package.py <packagecription class>"
else:
parseManifest(sys.argv[1])