buildhistory.bbclass: Fix python whitespace

(From OE-Core rev: 51d402fa0ec9e4adf10c3dac2a69a385ee720fa1)

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Richard Purdie
2012-07-19 11:32:20 +00:00
parent 09d11c2794
commit 2665be9dd5

View File

@@ -29,249 +29,249 @@ do_package[vardepsexclude] += "buildhistory_emit_pkghistory"
# for comparision when writing future packages
#
python buildhistory_emit_pkghistory() {
import re
import re
if not "package" in (d.getVar('BUILDHISTORY_FEATURES', True) or "").split():
return 0
if not "package" in (d.getVar('BUILDHISTORY_FEATURES', True) or "").split():
return 0
pkghistdir = d.getVar('BUILDHISTORY_DIR_PACKAGE', True)
pkghistdir = d.getVar('BUILDHISTORY_DIR_PACKAGE', True)
class RecipeInfo:
def __init__(self, name):
self.name = name
self.pe = "0"
self.pv = "0"
self.pr = "r0"
self.depends = ""
self.packages = ""
class RecipeInfo:
def __init__(self, name):
self.name = name
self.pe = "0"
self.pv = "0"
self.pr = "r0"
self.depends = ""
self.packages = ""
class PackageInfo:
def __init__(self, name):
self.name = name
self.pe = "0"
self.pv = "0"
self.pr = "r0"
self.size = 0
self.depends = ""
self.rdepends = ""
self.rrecommends = ""
self.files = ""
self.filelist = ""
class PackageInfo:
def __init__(self, name):
self.name = name
self.pe = "0"
self.pv = "0"
self.pr = "r0"
self.size = 0
self.depends = ""
self.rdepends = ""
self.rrecommends = ""
self.files = ""
self.filelist = ""
# Should check PACKAGES here to see if anything removed
# Should check PACKAGES here to see if anything removed
def getpkgvar(pkg, var):
val = bb.data.getVar('%s_%s' % (var, pkg), d, 1)
if val:
return val
val = bb.data.getVar('%s' % (var), d, 1)
def getpkgvar(pkg, var):
val = bb.data.getVar('%s_%s' % (var, pkg), d, 1)
if val:
return val
val = bb.data.getVar('%s' % (var), d, 1)
return val
return val
def readRecipeInfo(pn, histfile):
rcpinfo = RecipeInfo(pn)
f = open(histfile, "r")
try:
for line in f:
lns = line.split('=')
name = lns[0].strip()
value = lns[1].strip(" \t\r\n").strip('"')
if name == "PE":
rcpinfo.pe = value
elif name == "PV":
rcpinfo.pv = value
elif name == "PR":
rcpinfo.pr = value
elif name == "DEPENDS":
rcpinfo.depends = value
elif name == "PACKAGES":
rcpinfo.packages = value
finally:
f.close()
return rcpinfo
def readRecipeInfo(pn, histfile):
rcpinfo = RecipeInfo(pn)
f = open(histfile, "r")
try:
for line in f:
lns = line.split('=')
name = lns[0].strip()
value = lns[1].strip(" \t\r\n").strip('"')
if name == "PE":
rcpinfo.pe = value
elif name == "PV":
rcpinfo.pv = value
elif name == "PR":
rcpinfo.pr = value
elif name == "DEPENDS":
rcpinfo.depends = value
elif name == "PACKAGES":
rcpinfo.packages = value
finally:
f.close()
return rcpinfo
def readPackageInfo(pkg, histfile):
pkginfo = PackageInfo(pkg)
f = open(histfile, "r")
try:
for line in f:
lns = line.split('=')
name = lns[0].strip()
value = lns[1].strip(" \t\r\n").strip('"')
if name == "PE":
pkginfo.pe = value
elif name == "PV":
pkginfo.pv = value
elif name == "PR":
pkginfo.pr = value
elif name == "RDEPENDS":
pkginfo.rdepends = value
elif name == "RRECOMMENDS":
pkginfo.rrecommends = value
elif name == "PKGSIZE":
pkginfo.size = long(value)
elif name == "FILES":
pkginfo.files = value
elif name == "FILELIST":
pkginfo.filelist = value
finally:
f.close()
return pkginfo
def readPackageInfo(pkg, histfile):
pkginfo = PackageInfo(pkg)
f = open(histfile, "r")
try:
for line in f:
lns = line.split('=')
name = lns[0].strip()
value = lns[1].strip(" \t\r\n").strip('"')
if name == "PE":
pkginfo.pe = value
elif name == "PV":
pkginfo.pv = value
elif name == "PR":
pkginfo.pr = value
elif name == "RDEPENDS":
pkginfo.rdepends = value
elif name == "RRECOMMENDS":
pkginfo.rrecommends = value
elif name == "PKGSIZE":
pkginfo.size = long(value)
elif name == "FILES":
pkginfo.files = value
elif name == "FILELIST":
pkginfo.filelist = value
finally:
f.close()
return pkginfo
def getlastrecipeversion(pn):
try:
histfile = os.path.join(pkghistdir, "latest")
return readRecipeInfo(pn, histfile)
except EnvironmentError:
return None
def getlastrecipeversion(pn):
try:
histfile = os.path.join(pkghistdir, "latest")
return readRecipeInfo(pn, histfile)
except EnvironmentError:
return None
def getlastpkgversion(pkg):
try:
histfile = os.path.join(pkghistdir, pkg, "latest")
return readPackageInfo(pkg, histfile)
except EnvironmentError:
return None
def getlastpkgversion(pkg):
try:
histfile = os.path.join(pkghistdir, pkg, "latest")
return readPackageInfo(pkg, histfile)
except EnvironmentError:
return None
def sortpkglist(string):
pkgiter = re.finditer(r'[a-zA-Z0-9.+-]+( \([><=]+ [^ )]+\))?', string, 0)
pkglist = [p.group(0) for p in pkgiter]
pkglist.sort()
return ' '.join(pkglist)
def sortpkglist(string):
pkgiter = re.finditer(r'[a-zA-Z0-9.+-]+( \([><=]+ [^ )]+\))?', string, 0)
pkglist = [p.group(0) for p in pkgiter]
pkglist.sort()
return ' '.join(pkglist)
def sortlist(string):
items = string.split(' ')
items.sort()
return ' '.join(items)
def sortlist(string):
items = string.split(' ')
items.sort()
return ' '.join(items)
pn = d.getVar('PN', True)
pe = d.getVar('PE', True) or "0"
pv = d.getVar('PV', True)
pr = d.getVar('PR', True)
packages = squashspaces(d.getVar('PACKAGES', True))
pn = d.getVar('PN', True)
pe = d.getVar('PE', True) or "0"
pv = d.getVar('PV', True)
pr = d.getVar('PR', True)
packages = squashspaces(d.getVar('PACKAGES', True))
rcpinfo = RecipeInfo(pn)
rcpinfo.pe = pe
rcpinfo.pv = pv
rcpinfo.pr = pr
rcpinfo.depends = sortlist(squashspaces(d.getVar('DEPENDS', True) or ""))
rcpinfo.packages = packages
write_recipehistory(rcpinfo, d)
write_latestlink(None, pe, pv, pr, d)
rcpinfo = RecipeInfo(pn)
rcpinfo.pe = pe
rcpinfo.pv = pv
rcpinfo.pr = pr
rcpinfo.depends = sortlist(squashspaces(d.getVar('DEPENDS', True) or ""))
rcpinfo.packages = packages
write_recipehistory(rcpinfo, d)
write_latestlink(None, pe, pv, pr, d)
# Apparently the version can be different on a per-package basis (see Python)
pkgdest = d.getVar('PKGDEST', True)
for pkg in packages.split():
pe = getpkgvar(pkg, 'PE') or "0"
pv = getpkgvar(pkg, 'PV')
pr = getpkgvar(pkg, 'PR')
#
# Find out what the last version was
# Make sure the version did not decrease
#
lastversion = getlastpkgversion(pkg)
if lastversion:
last_pe = lastversion.pe
last_pv = lastversion.pv
last_pr = lastversion.pr
r = bb.utils.vercmp((pe, pv, pr), (last_pe, last_pv, last_pr))
if r < 0:
bb.error("Package version for package %s went backwards which would break package feeds from (%s:%s-%s to %s:%s-%s)" % (pkg, last_pe, last_pv, last_pr, pe, pv, pr))
# Apparently the version can be different on a per-package basis (see Python)
pkgdest = d.getVar('PKGDEST', True)
for pkg in packages.split():
pe = getpkgvar(pkg, 'PE') or "0"
pv = getpkgvar(pkg, 'PV')
pr = getpkgvar(pkg, 'PR')
#
# Find out what the last version was
# Make sure the version did not decrease
#
lastversion = getlastpkgversion(pkg)
if lastversion:
last_pe = lastversion.pe
last_pv = lastversion.pv
last_pr = lastversion.pr
r = bb.utils.vercmp((pe, pv, pr), (last_pe, last_pv, last_pr))
if r < 0:
bb.error("Package version for package %s went backwards which would break package feeds from (%s:%s-%s to %s:%s-%s)" % (pkg, last_pe, last_pv, last_pr, pe, pv, pr))
pkginfo = PackageInfo(pkg)
pkginfo.pe = pe
pkginfo.pv = pv
pkginfo.pr = pr
pkginfo.rdepends = sortpkglist(squashspaces(getpkgvar(pkg, 'RDEPENDS') or ""))
pkginfo.rrecommends = sortpkglist(squashspaces(getpkgvar(pkg, 'RRECOMMENDS') or ""))
pkginfo.files = squashspaces(getpkgvar(pkg, 'FILES') or "")
pkginfo = PackageInfo(pkg)
pkginfo.pe = pe
pkginfo.pv = pv
pkginfo.pr = pr
pkginfo.rdepends = sortpkglist(squashspaces(getpkgvar(pkg, 'RDEPENDS') or ""))
pkginfo.rrecommends = sortpkglist(squashspaces(getpkgvar(pkg, 'RRECOMMENDS') or ""))
pkginfo.files = squashspaces(getpkgvar(pkg, 'FILES') or "")
# Gather information about packaged files
pkgdestpkg = os.path.join(pkgdest, pkg)
filelist = []
pkginfo.size = 0
for root, dirs, files in os.walk(pkgdestpkg):
relpth = os.path.relpath(root, pkgdestpkg)
for f in files:
fstat = os.lstat(os.path.join(root, f))
pkginfo.size += fstat.st_size
filelist.append(os.sep + os.path.join(relpth, f))
filelist.sort()
pkginfo.filelist = " ".join(filelist)
# Gather information about packaged files
pkgdestpkg = os.path.join(pkgdest, pkg)
filelist = []
pkginfo.size = 0
for root, dirs, files in os.walk(pkgdestpkg):
relpth = os.path.relpath(root, pkgdestpkg)
for f in files:
fstat = os.lstat(os.path.join(root, f))
pkginfo.size += fstat.st_size
filelist.append(os.sep + os.path.join(relpth, f))
filelist.sort()
pkginfo.filelist = " ".join(filelist)
write_pkghistory(pkginfo, d)
write_pkghistory(pkginfo, d)
write_latestlink(pkg, pe, pv, pr, d)
write_latestlink(pkg, pe, pv, pr, d)
}
def write_recipehistory(rcpinfo, d):
bb.debug(2, "Writing recipe history")
bb.debug(2, "Writing recipe history")
pkghistdir = d.getVar('BUILDHISTORY_DIR_PACKAGE', True)
pkghistdir = d.getVar('BUILDHISTORY_DIR_PACKAGE', True)
if not os.path.exists(pkghistdir):
os.makedirs(pkghistdir)
if not os.path.exists(pkghistdir):
os.makedirs(pkghistdir)
verfile = os.path.join(pkghistdir, "%s:%s-%s" % (rcpinfo.pe, rcpinfo.pv, rcpinfo.pr))
f = open(verfile, "w")
try:
if rcpinfo.pe != "0":
f.write("PE = %s\n" % rcpinfo.pe)
f.write("PV = %s\n" % rcpinfo.pv)
f.write("PR = %s\n" % rcpinfo.pr)
f.write("DEPENDS = %s\n" % rcpinfo.depends)
f.write("PACKAGES = %s\n" % rcpinfo.packages)
finally:
f.close()
verfile = os.path.join(pkghistdir, "%s:%s-%s" % (rcpinfo.pe, rcpinfo.pv, rcpinfo.pr))
f = open(verfile, "w")
try:
if rcpinfo.pe != "0":
f.write("PE = %s\n" % rcpinfo.pe)
f.write("PV = %s\n" % rcpinfo.pv)
f.write("PR = %s\n" % rcpinfo.pr)
f.write("DEPENDS = %s\n" % rcpinfo.depends)
f.write("PACKAGES = %s\n" % rcpinfo.packages)
finally:
f.close()
def write_pkghistory(pkginfo, d):
bb.debug(2, "Writing package history")
bb.debug(2, "Writing package history")
pkghistdir = d.getVar('BUILDHISTORY_DIR_PACKAGE', True)
pkghistdir = d.getVar('BUILDHISTORY_DIR_PACKAGE', True)
verpath = os.path.join(pkghistdir, pkginfo.name)
if not os.path.exists(verpath):
os.makedirs(verpath)
verpath = os.path.join(pkghistdir, pkginfo.name)
if not os.path.exists(verpath):
os.makedirs(verpath)
verfile = os.path.join(verpath, "%s:%s-%s" % (pkginfo.pe, pkginfo.pv, pkginfo.pr))
f = open(verfile, "w")
try:
if pkginfo.pe != "0":
f.write("PE = %s\n" % pkginfo.pe)
f.write("PV = %s\n" % pkginfo.pv)
f.write("PR = %s\n" % pkginfo.pr)
f.write("RDEPENDS = %s\n" % pkginfo.rdepends)
f.write("RRECOMMENDS = %s\n" % pkginfo.rrecommends)
f.write("PKGSIZE = %d\n" % pkginfo.size)
f.write("FILES = %s\n" % pkginfo.files)
f.write("FILELIST = %s\n" % pkginfo.filelist)
finally:
f.close()
verfile = os.path.join(verpath, "%s:%s-%s" % (pkginfo.pe, pkginfo.pv, pkginfo.pr))
f = open(verfile, "w")
try:
if pkginfo.pe != "0":
f.write("PE = %s\n" % pkginfo.pe)
f.write("PV = %s\n" % pkginfo.pv)
f.write("PR = %s\n" % pkginfo.pr)
f.write("RDEPENDS = %s\n" % pkginfo.rdepends)
f.write("RRECOMMENDS = %s\n" % pkginfo.rrecommends)
f.write("PKGSIZE = %d\n" % pkginfo.size)
f.write("FILES = %s\n" % pkginfo.files)
f.write("FILELIST = %s\n" % pkginfo.filelist)
finally:
f.close()
def write_latestlink(pkg, pe, pv, pr, d):
import shutil
import shutil
pkghistdir = d.getVar('BUILDHISTORY_DIR_PACKAGE', True)
pkghistdir = d.getVar('BUILDHISTORY_DIR_PACKAGE', True)
def rm_link(path):
try:
os.unlink(path)
except OSError:
return
def rm_link(path):
try:
os.unlink(path)
except OSError:
return
if pkg:
filedir = os.path.join(pkghistdir, pkg)
else:
filedir = pkghistdir
latest_file = os.path.join(filedir, "latest")
ver_file = os.path.join(filedir, "%s:%s-%s" % (pe, pv, pr))
rm_link(latest_file)
if d.getVar('BUILDHISTORY_KEEP_VERSIONS', True) == '1':
shutil.copy(ver_file, latest_file)
else:
shutil.move(ver_file, latest_file)
if pkg:
filedir = os.path.join(pkghistdir, pkg)
else:
filedir = pkghistdir
latest_file = os.path.join(filedir, "latest")
ver_file = os.path.join(filedir, "%s:%s-%s" % (pe, pv, pr))
rm_link(latest_file)
if d.getVar('BUILDHISTORY_KEEP_VERSIONS', True) == '1':
shutil.copy(ver_file, latest_file)
else:
shutil.move(ver_file, latest_file)
buildhistory_get_image_installed() {
@@ -360,29 +360,29 @@ ROOTFS_POSTPROCESS_COMMAND =+ "buildhistory_get_image_installed ; "
IMAGE_POSTPROCESS_COMMAND += " buildhistory_get_imageinfo ; "
def buildhistory_get_layers(d):
layertext = "Configured metadata layers:\n%s\n" % '\n'.join(get_layers_branch_rev(d))
return layertext
layertext = "Configured metadata layers:\n%s\n" % '\n'.join(get_layers_branch_rev(d))
return layertext
def squashspaces(string):
import re
return re.sub("\s+", " ", string).strip()
import re
return re.sub("\s+", " ", string).strip()
def buildhistory_get_imagevars(d):
imagevars = "DISTRO DISTRO_VERSION USER_CLASSES IMAGE_CLASSES IMAGE_FEATURES IMAGE_LINGUAS IMAGE_INSTALL BAD_RECOMMENDATIONS ROOTFS_POSTPROCESS_COMMAND IMAGE_POSTPROCESS_COMMAND"
listvars = "USER_CLASSES IMAGE_CLASSES IMAGE_FEATURES IMAGE_LINGUAS IMAGE_INSTALL BAD_RECOMMENDATIONS"
imagevars = "DISTRO DISTRO_VERSION USER_CLASSES IMAGE_CLASSES IMAGE_FEATURES IMAGE_LINGUAS IMAGE_INSTALL BAD_RECOMMENDATIONS ROOTFS_POSTPROCESS_COMMAND IMAGE_POSTPROCESS_COMMAND"
listvars = "USER_CLASSES IMAGE_CLASSES IMAGE_FEATURES IMAGE_LINGUAS IMAGE_INSTALL BAD_RECOMMENDATIONS"
imagevars = imagevars.split()
listvars = listvars.split()
ret = ""
for var in imagevars:
value = d.getVar(var, True) or ""
if var in listvars:
# Squash out spaces
value = squashspaces(value)
ret += "%s = %s\n" % (var, value)
return ret.rstrip('\n')
imagevars = imagevars.split()
listvars = listvars.split()
ret = ""
for var in imagevars:
value = d.getVar(var, True) or ""
if var in listvars:
# Squash out spaces
value = squashspaces(value)
ret += "%s = %s\n" % (var, value)
return ret.rstrip('\n')
buildhistory_commit() {
@@ -414,10 +414,10 @@ buildhistory_commit() {
}
python buildhistory_eventhandler() {
if isinstance(e, bb.event.BuildCompleted):
if e.data.getVar('BUILDHISTORY_FEATURES', True).strip():
if e.data.getVar("BUILDHISTORY_COMMIT", True) == "1":
bb.build.exec_func("buildhistory_commit", e.data)
if isinstance(e, bb.event.BuildCompleted):
if e.data.getVar('BUILDHISTORY_FEATURES', True).strip():
if e.data.getVar("BUILDHISTORY_COMMIT", True) == "1":
bb.build.exec_func("buildhistory_commit", e.data)
}
addhandler buildhistory_eventhandler