* We will chop off these ugliness later. Not touching it right now, just moving

around to easily port these changes to maintanence.
This commit is contained in:
Faik Uygur
2007-01-25 12:36:45 +00:00
parent 8c8fafdfe6
commit 517d4baaef
+60 -50
View File
@@ -635,16 +635,7 @@ class Builder:
files.write(files_xml_path) files.write(files_xml_path)
self.files = files self.files = files
def calc_build_no(self, package_name): def find_old_package_info(self, package_name):
"""Calculate build number"""
def metadata_changed(old_metadata, new_metadata):
for key in old_metadata.package.__dict__.keys():
if old_metadata.package.__dict__[key] != new_metadata.package.__dict__[key]:
if key != "build":
return True
return False
# find previous build in packages dir # find previous build in packages dir
found = [] found = []
@@ -674,61 +665,76 @@ class Builder:
if os.path.isfile(file): if os.path.isfile(file):
locate_old_package(file) locate_old_package(file)
if not found: if found:
return (1, None)
ctx.ui.warning(_('(no previous build found, setting build no to 1.)'))
else:
a = filter(lambda (x,y): y != None, found) a = filter(lambda (x,y): y != None, found)
ctx.ui.debug(str(a)) ctx.ui.debug(str(a))
if a: if a:
# sort in order of increasing build number # sort in order of increasing build number
a.sort(lambda x,y : cmp(x[1],y[1])) a.sort(lambda x,y : cmp(x[1],y[1]))
old_package_fn = a[-1][0] # get the last one old_package_fn = a[-1][0] # get the last one
old_build = a[-1][1] old_build = a[-1][1]
return (old_package_fn, old_build)
# compare old files.xml with the new one.. return None
old_pkg = Package(old_package_fn, 'r')
old_pkg.read(util.join_path(ctx.config.tmp_dir(), 'oldpkg'))
changed = False def calc_build_no(self, old_package_info):
fnew = self.files.list """Calculate build number"""
fold = old_pkg.files.list
fold.sort(lambda x,y : cmp(x.path,y.path))
fnew.sort(lambda x,y : cmp(x.path,y.path))
if len(fnew) != len(fold): def metadata_changed(old_metadata, new_metadata):
changed = True for key in old_metadata.package.__dict__.keys():
else: if old_metadata.package.__dict__[key] != new_metadata.package.__dict__[key]:
for i in range(len(fold)): if key != "build":
fo = fold.pop(0) return True
fn = fnew.pop(0)
if fo.path != fn.path: return False
if not old_package_info:
return (1, None)
ctx.ui.warning(_('(no previous build no info found, setting build no to 1.)'))
else:
old_package_fn, old_build = old_package_info
# compare old files.xml with the new one..
old_pkg = Package(old_package_fn, 'r')
old_pkg.read(util.join_path(ctx.config.tmp_dir(), 'oldpkg'))
changed = False
fnew = self.files.list
fold = old_pkg.files.list
fold.sort(lambda x,y : cmp(x.path,y.path))
fnew.sort(lambda x,y : cmp(x.path,y.path))
if len(fnew) != len(fold):
changed = True
else:
for i in range(len(fold)):
fo = fold.pop(0)
fn = fnew.pop(0)
if fo.path != fn.path:
changed = True
break
else:
if fo.hash != fn.hash:
changed = True changed = True
break break
else:
if fo.hash != fn.hash:
changed = True
break
if metadata_changed(old_pkg.metadata, self.metadata):
changed = True
if metadata_changed(old_pkg.metadata, self.metadata):
changed = True
self.old_packages.append(os.path.basename(old_package_fn)) self.old_packages.append(os.path.basename(old_package_fn))
else: # no old build had a build number
old_build = None
ctx.ui.debug('old build number: %s' % old_build) ctx.ui.debug('old build number: %s' % old_build)
# set build number # set build number
if old_build is None: if old_build is None:
ctx.ui.warning(_('(old package lacks a build no, setting build no to 1.)')) ctx.ui.warning(_('(old package lacks a build no, setting build no to 1.)'))
return (1, None) return (1, None)
elif changed: elif changed:
ctx.ui.info(_('There are changes, incrementing build no to %d') % (old_build + 1)) ctx.ui.info(_('There are changes, incrementing build no to %d') % (old_build + 1))
return (old_build + 1, old_build) return (old_build + 1, old_build)
else: else:
ctx.ui.info(_('There is no change from previous build %d') % old_build) ctx.ui.info(_('There is no change from previous build %d') % old_build)
return (old_build, old_build) return (old_build, old_build)
def build_packages(self): def build_packages(self):
"""Build each package defined in PSPEC file. After this process there """Build each package defined in PSPEC file. After this process there
@@ -808,12 +814,16 @@ class Builder:
ctx.ui.info(_("Generating %s,") % ctx.const.metadata_xml) ctx.ui.info(_("Generating %s,") % ctx.const.metadata_xml)
self.gen_metadata_xml(package) self.gen_metadata_xml(package)
# find the latest build info if any with build no.
# old_package_info = (old_package_file_name, old_build_no)
old_package_info = self.find_old_package_info(package.name)
# build number # build number
if ctx.config.options.ignore_build_no or not ctx.config.values.build.buildno: if ctx.config.options.ignore_build_no or not ctx.config.values.build.buildno:
build_no = old_build_no = None build_no = old_build_no = None
ctx.ui.warning(_('Build number is not available. For repo builds you must enable buildno in pisi.conf.')) ctx.ui.warning(_('Build number is not available. For repo builds you must enable buildno in pisi.conf.'))
else: else:
build_no, old_build_no = self.calc_build_no(package.name) build_no, old_build_no = self.calc_build_no(old_package_info)
self.metadata.package.build = build_no self.metadata.package.build = build_no
self.metadata.write(util.join_path(self.pkg_dir(), ctx.const.metadata_xml)) self.metadata.write(util.join_path(self.pkg_dir(), ctx.const.metadata_xml))