summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Dieter <jdieter@gmail.com>2007-06-19 16:59:35 +0300
committerJonathan Dieter <jdieter@gmail.com>2007-06-19 16:59:35 +0300
commit93b2295180471308e969640472bdc601d1f10015 (patch)
tree15cd1a0d4ed1789984d6d98b5f1cbac4baf529f7
parentd60f28d66709c0c7fed26d19b1b7fb2c55439507 (diff)
downloadpresto-93b2295180471308e969640472bdc601d1f10015.zip
presto-93b2295180471308e969640472bdc601d1f10015.tar.gz
presto-93b2295180471308e969640472bdc601d1f10015.tar.xz
Small changes
Signed-off-by: Jonathan Dieter <jdieter@gmail.com>
-rwxr-xr-xcreateprestorepo/gendeltarpms.py59
-rw-r--r--createprestorepo/packagelist.py51
2 files changed, 80 insertions, 30 deletions
diff --git a/createprestorepo/gendeltarpms.py b/createprestorepo/gendeltarpms.py
index fc4a9ca..26d795b 100755
--- a/createprestorepo/gendeltarpms.py
+++ b/createprestorepo/gendeltarpms.py
@@ -105,7 +105,7 @@ def getFileList(path, ext, filelist):
return filelist
-def createPrestoRepo(base_dir, drpm_dir):
+def createPrestoRepo(base_dir, drpm_dir, dst_dir=None):
ts = rpmUtils.transaction.initReadOnlyTransaction()
changed = False
@@ -115,11 +115,18 @@ def createPrestoRepo(base_dir, drpm_dir):
print 'Using destination dir: %s' % drpm_dir
rpm_files = getFileList(base_dir, ".rpm", [])
- drpm_files = getFileList(base_dir, ".drpm", [])
+ if dst_dir != None:
+ dst_rpm_files = getFileList(dst_dir, ".rpm", [])
+ drpm_files = getFileList(drpm_dir, ".drpm", [])
+
if not len(rpm_files):
print ' Nothing found.'
return changed
+ if dst_dir != None and not len(dst_rpm_files):
+ print ' No new rpms found.'
+ return changed
+
# Check whether rel_dir exists, and if it doesn't, create it
if not os.access(drpm_dir, os.F_OK):
os.makedirs(drpm_dir, 0755)
@@ -144,6 +151,24 @@ def createPrestoRepo(base_dir, drpm_dir):
rpm = RpmItem(nevra, f)
rpm_list.addRpm(rpm)
+ # If we have a new distro, add its rpms with epoch bumped +5
+ if dst_dir != None:
+ for f in dst_rpm_files:
+ try:
+ hdr = rpmUtils.miscutils.hdrFromPackage(ts, f)
+ except:
+ print "Unable to open %s" % f
+ else:
+ nm = hdr['name'] + "." + hdr['arch']
+ e = hdr['epoch']
+ if e is None:
+ e = "0"
+ e = str(int(e) + 5)
+
+ nevra = (hdr['name'], e, hdr['version'], hdr['release'], hdr['arch'])
+ rpm = RpmItem(nevra, f)
+ rpm_list.addRpm(rpm)
+
# Add all deltarpms to PackageList
for f in drpm_files:
try:
@@ -167,23 +192,25 @@ def createPrestoRepo(base_dir, drpm_dir):
rpm_list.dump()
# Build deltarpms
- rpm_list.makeDeltaRpms()
-
-def main(bin_rpm_path, delta_rpm_path):
- assert rpmUtils.miscutils.compareEVR((1,2,3),(1,2,0)) > 0
- assert rpmUtils.miscutils.compareEVR((0,1,2),(0,1,2)) == 0
- assert rpmUtils.miscutils.compareEVR((1,2,3),(4,0,99)) < 0
-
- return createPrestoRepo(bin_rpm_path, delta_rpm_path)
-
+ if dst_dir != None:
+ rpm_list.makeDeltaRpms(DrpmsPerPackage=1, DoFirst=False)
+ else:
+ rpm_list.makeDeltaRpms(DrpmsPerPackage=5)
if __name__ == '__main__':
- if len(sys.argv) < 2:
- print 'Usage: %s <bin_rpm_dir> <delta_rpm_dir> \n' % os.path.basename(sys.argv[0])
+ if len(sys.argv) < 2 or (sys.argv[1] == "-d" and len(sys.argv) < 4):
+ print 'Usage: %s <bin_rpm_dir> <delta_rpm_dir>' % os.path.basename(sys.argv[0])
+ print ' %s -d <old_dist_dir> <new_dist_dir> <delta_rpm_dir>' % os.path.basename(sys.argv[0])
sys.exit(errno.EINVAL)
- bin_rpm_path = sys.argv[1]
- delta_rpm_path = sys.argv[2]
+ if sys.argv[1] != "-d":
+ bin_rpm_path = sys.argv[1]
+ delta_rpm_path = sys.argv[2]
+ createPrestoRepo(bin_rpm_path, delta_rpm_path)
+ else:
+ src_bin_rpm_path = sys.argv[2]
+ dst_bin_rpm_path = sys.argv[3]
+ delta_rpm_path = sys.argv[4]
+ createPrestoRepo(src_bin_rpm_path, delta_rpm_path, dst_bin_rpm_path)
- main(bin_rpm_path, delta_rpm_path)
sys.exit(0)
diff --git a/createprestorepo/packagelist.py b/createprestorepo/packagelist.py
index 5482572..c057f3f 100644
--- a/createprestorepo/packagelist.py
+++ b/createprestorepo/packagelist.py
@@ -60,7 +60,7 @@ class DrpmItem:
return (self.dst_name, self.dst_epoch, self.dst_version, self.dst_release, self.dst_arch)
def getSrcDstNevra(self):
- return [getSrcNevra(), getDstNevra()]
+ return [self.getSrcNevra(), self.getDstNevra()]
def __eq__(self, b):
if b == None:
@@ -94,7 +94,13 @@ class PackageList:
rpm_key = "%s.%s" % (rpm.name, rpm.arch)
self.rpm_list.setdefault(rpm_key, {})
self.rpm_list[rpm_key].setdefault("rpms", [])
- self.rpm_list[rpm_key]["rpms"].append(rpm)
+ found = False
+ for found_rpm in self.rpm_list[rpm_key]["rpms"]:
+ if rpm == found_rpm:
+ found = True
+ break
+ if not found:
+ self.rpm_list[rpm_key]["rpms"].append(rpm)
def addDrpm(self, drpm):
"""Add DrpmItem to PackageList"""
@@ -102,7 +108,13 @@ class PackageList:
rpm_key = "%s.%s" % (drpm.src_name, drpm.src_arch)
self.rpm_list.setdefault(rpm_key, {})
self.rpm_list[rpm_key].setdefault("drpms", [])
- self.rpm_list[rpm_key]["drpms"].append(drpm)
+ found = False
+ for found_drpm in self.rpm_list[rpm_key]["drpms"]:
+ if drpm == found_drpm:
+ found = True
+ break
+ if not found:
+ self.rpm_list[rpm_key]["drpms"].append(drpm)
def sort(self):
"""Sort all rpms and deltarpms in reverse order. This is necessary before running any
@@ -186,10 +198,9 @@ class PackageList:
(code, out) = commands.getstatusoutput(deltaCommand)
if code:
- #raise Exception("genDeltaRPM: exitcode was %s - Reported Error: %s" % (code, out))
print "Error genDeltaRPM for %s: exitcode was %s - Reported Error: %s" % (n1, code, out)
return False
- else:
+ else:
# Check whether or not we should keep the drpm
drpmsize = os.path.getsize(deltaRPMName)
if not self.__drpmIsWorthKeeping(drpmsize, f1):
@@ -261,11 +272,12 @@ class PackageList:
return False
- def makeDeltaRpms(self, OnlyLastPackage=True, DrpmsPerPackage=0):
+ def makeDeltaRpms(self, DrpmsPerPackage=0, OnlyLastPackage=True, DoFirst=True):
"""Create deltarpms for packages.
Attributes:
- OnlyLastPackage (Boolean): Only create deltarpms for last package
- DrpmsPerPackage (Int): Number of deltarpms to make for each package (0 = all possible)"""
+ OnlyLastPackage (Boolean): Only create deltarpms to point to last destination package
+ DrpmsPerPackage (Int): Number of deltarpms to make for each package (0 = all possible)
+ DoFirst (Boolean): Create deltarpm for first source package"""
if not self.sorted:
self.sort()
temp_list = []
@@ -341,19 +353,30 @@ class PackageList:
newpkg_list.append(rpm)
for newpkg in newpkg_list:
- start = False
- count = 0
- for build in build_list:
+ start = False
+ count = 0
+ do_last = True
+ for build in build_list[:-1]:
if start:
self.__makeDeltaRpm(build[0], newpkg, package)
if not self.sorted:
self.sort()
count += 1
- if count > DrpmsPerPackage and DrpmsPerPackage != 0:
- break
+ if DrpmsPerPackage != 0:
+ if count >= DrpmsPerPackage and not DoFirst:
+ do_last = False
+ break
+ elif count >= DrpmsPerPackage - 1 and DoFirst:
+ break
if build[0] == newpkg.getNevra():
start = True
-
+
+ if DoFirst == 1 and start and do_last:
+ self.__makeDeltaRpm(build_list[-1][0], newpkg, package)
+ if not self.sorted:
+ self.sort()
+ return
+
def __drpmIsWorthKeeping(self, drpmsize, newrpm):
newsize = os.path.getsize(newrpm)
# Delete the drpm if it's too large