Re: Splitdistro

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Jean-Yves Lenhof wrote:
 
Hi guys,
I've hacked splitdistro for my needs. This is a bad hacked because :
- The original source is not well commented
- I'm not a real python programmer but an Unix/Linux administrator
But with this version you should be able to create your binary CD for your installation. So if you have added too much packages it will create three or more binary CDs
Have fun,
Jean-Yves
 


Ok here it is....
I forget to push the join button...


Jean-yves

 
#!/usr/bin/python

# Changes by Jean-Yves LENHOF <lenh_jea@xxxxxxxxxxxx> <jean-yves.lenhof@xxxxxx>

# These dirs, along with RPMS, make up last binary disc 
lastdiscdirs = [ "preview" ]

# These files appear on all binary CDs
# CHANGES was added for my needs
jointfiles = [ "COPYING", "RPM-GPG-KEY", "README", "autorun","CHANGES" ]

targetSize = 640 * 1024 * 1024

# Leave about 1.44MB of space on the disc
fudgeFactor = 1.44 * 1024 * 1024

#-----------------

import sys
import os
import os.path
import string
import getopt
import time
import types

# Write time in .disc?-arch file

def stamp(path, name, arch, startedAt):
    f = open("%s/.%s-%s" % (path, name, arch), "w")
    f.write("%f\n" % startedAt)
    f.close()

def moveFiles(srcDir, destDir, files):
    for fn in files:
	src = "%s/%s" % (srcDir, fn)
	dest = "%s/%s" % (destDir, fn)
	os.rename(src, dest)

def excessFiles(path, fileList, maxSize):
    total = 0
    moveList = []

    for fns in fileList:
	if type(fns) == types.StringType:
	    fns = [ fns ]

	size = 0
	for fn in fns:
	    thisSize = os.path.getsize(path + "/" + fn)
	    size = size + thisSize + ((thisSize + 2047) % 2048)

	if size + total  < maxSize:
	    total = total + size
	else:
	    # once we're done, we're done
	    total = maxSize
	    moveList.extend(fns)

    return moveList

class DirectoryIterator:
    def __init__(self):
        self.inodes = {}
    
    def traverse (self, arg, dirname, names):
        for name in names:
            sb = os.lstat (dirname + "/" + name)
            if not self.inodes.has_key(sb[1]):
                self.inodes[sb[1]] = sb[6]

    def total(self):
        total = 0
        for size in self.inodes.values():
            total = total + size
	return total

def spaceUsed(path):
    foo = DirectoryIterator()
    os.path.walk (path, foo.traverse, None)
    return foo.total()


# Main

startedAt = time.time()

fns = {}

(args, extra) = getopt.getopt(sys.argv[1:], '', [ 'fileorder=' ])
if len(extra) != 2:
    print "splitdistro --fileorder <file> <toppath> <arch>"
    sys.exit(1)


# Change made by JYL...... str is a functioni, I need it and it confuse python !!!!
for n in args:
    (MyString, arg) = n
    if MyString == '--fileorder':
	packageOrderFile = arg

arch = extra[1]
distDir = os.path.normpath(extra[0] + "/" + arch)
srcDir = os.path.normpath(extra[0] + "/SRPMS")

if not os.path.isdir(distDir):
    print "error: %s is not a directory" % distDir
    sys.exit(1)

if not os.path.isdir(srcDir):
    print "error: %s is not a directory" % srcDir
    sys.exit(1)

files = os.listdir(distDir + "/RedHat/RPMS")
files.sort()
packages = {}
for file in files:
    l = string.split(file, ".")
    pkg = string.join(l[:-2], ".")
    if packages.has_key(pkg):
	packages[pkg].append(file)
    else:
	packages[pkg] = [ file ]

f = open(packageOrderFile, "r")
binPkgList = []
for pkg in f.readlines():
    # chop
    pkg = pkg[:len(pkg) - 1]
    if pkg[0:8] != "warning:":
	binPkgList.append(packages[pkg])

del f

print "Splitting tree..."

#totalsize = spaceUsed(distDir)
#rpmsize = spaceUsed(distDir + "/RedHat/RPMS")

#for file in jointfiles:
#    src = "%s/%s" % (disc1Dir, file)
#    dest = "%s/%s" %(disc2Dir, file)
#    try:
#	os.link(src, dest)
#    except OSError, (errno, msg):
#	print "**** WARNING linking %s to %s: %s" % (src, dest, msg)

#Do some cleanup

print "Remove old %s-* and every disc already created" % distDir
os.system("rm -rf %s-*" % distDir)

#Make a copy in distDir-everything (Just hard link)

print "Copy everything in %s-everything" % distDir
os.system("mkdir -p %s-everything" % distDir)
os.system("cp -al %s/. %s-everything" % (distDir,distDir))

# Move RPMS in distDir-RPMS

print "Move RPMs in %s-RPMS" % distDir
os.system("mkdir -p %s-RPMS" % distDir)
os.system("mv %s-everything/RedHat/RPMS %s-RPMS" % (distDir,distDir))

# Move lastdiscdirs on distDir-preview (preview and so an)

print "Move %s in %s-preview " % (lastdiscdirs,distDir)
os.system("mkdir -p %s-preview" % distDir)
for FileName in lastdiscdirs:
	os.system("mv %s-everything/%s %s-preview/" % (distDir,FileName,distDir))

# Move jointfiles on distDir-jointfiles
print "Move %s in %s-jointfiles " % (jointfiles,distDir)
os.system("mkdir -p %s-jointfiles" % distDir)
for FileName in jointfiles:
	print FileName
	print "%s-everything/%s %s-jointfiles/" % (distDir,FileName,distDir)
	os.system("cp -al %s-everything/%s %s-jointfiles/" % (distDir,FileName,distDir))

# OK, now really constructing first CD (There are everything except joinfiles, lastdirdiscs, RPMS)

print "OK now %s-everything is called %s-disc1" % (distDir,distDir)
os.system("mv %s-everything %s-disc1" % (distDir,distDir))

# Compute the actual occupation of disc1

NameOfDisk=distDir+"-disc1"
disc1Used=spaceUsed(NameOfDisk)

# Compute the actual occupation of jointfiles
JointFilesSize=spaceUsed(distDir+"-jointfiles")

# Write the stamp on the first CD 

stamp(NameOfDisk,"disc1",arch,startedAt)


# Filling CD with RPMs
CurrentBinaryCDNumber = 1

print "\nFilling Binary CD number 1 with RPMs\n"

os.system("mv %s-RPMS/* %s-disc1/RedHat/RPMS" % (distDir,distDir))

discpkgs = excessFiles(distDir+"/RedHat/RPMS",binPkgList,targetSize-disc1Used-JointFilesSize-fudgeFactor)

while len(discpkgs):

        os.system("mkdir -p %s-disc%s/RedHat/RPMS" % (distDir,CurrentBinaryCDNumber+1))
	
	moveFiles("%s-disc%s/RedHat/RPMS" % (distDir,CurrentBinaryCDNumber),"%s-disc%s/RedHat/RPMS" % (distDir,CurrentBinaryCDNumber+1),discpkgs)
	
	CurrentBinaryCDNumber=CurrentBinaryCDNumber+1
	print "\nFilling Binary CD number %s with RPMS\n" %CurrentBinaryCDNumber
	
	stamp(distDir+"-disc"+str(CurrentBinaryCDNumber),"disc"+str(CurrentBinaryCDNumber),arch,startedAt)

	discpkgs = excessFiles(distDir+"/RedHat/RPMS",binPkgList,targetSize*CurrentBinaryCDNumber-CurrentBinaryCDNumber*JointFilesSize-disc1Used-fudgeFactor)

# Now copy jointfiles on each CD

CDNumber=1
while CDNumber <= CurrentBinaryCDNumber:
	print "\nCopying jointfiles on Binary CD number %s\n" % CDNumber
	os.system("cp -alr %s-jointfiles/* %s-disc%s/" % (distDir,distDir,CDNumber))
	CDNumber=CDNumber+1

# FIXME : Create Source CDs
# FIXME : Move preview on the last CD 

sys.exit(0)

sys.stdout.flush()

#os.system("du -sh %s %s %s" % (disc1Dir, disc2Dir, disc1SrcDir))

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux