Esempio n. 1
0
	def getRPMS(self, path):
		"""Return a list of all the RPMs in the given path, if multiple
		versions of a package are found only the most recent one will
		be included"""
		
		dict = {}
		tree = stack.file.Tree(os.path.join(os.getcwd(), path))
		for dir in tree.getDirs():
			for file in tree.getFiles(dir):
				try:
					file.getPackageName()
				except AttributeError:
					continue # skip all non-rpm files
					
				# Skip RPMS for other architecures
				
				if file.getPackageArch() not in self.getCPUs():
					continue
					
				# Resolve package versions
				
				name = file.getUniqueName()
				if not dict.has_key(name) or file >= dict[name]:
					dict[name] = file
					
		# convert the dictionary to a list and return all the RPMFiles
		
		list = []
		for e in dict.keys():
			list.append(dict[e])
		return list
Esempio n. 2
0
    def getRPMS(self, path):
        """Return a list of all the RPMs in the given path, if multiple
		versions of a package are found only the most recent one will
		be included"""

        dict = {}
        tree = stack.file.Tree(os.path.join(os.getcwd(), path))
        for dir in tree.getDirs():
            for file in tree.getFiles(dir):
                try:
                    file.getPackageName()
                except:
                    continue  # skip all non-rpm files

                # Skip RPMS for other architecures

                if file.getPackageArch() not in self.getCPUs():
                    continue

                # Resolve package versions
                if newest is True:
                    name = file.getUniqueName()
                else:
                    name = file.getFullName()

                if (name not in dict) or (file >= dict[name]):
                    dict[name] = file

        # convert the dictionary to a list and return all the RPMFiles

        list = []
        for e in dict.keys():
            list.append(dict[e])
        return list
Esempio n. 3
0
	def getPackage(self, name, list):

		pkg = {}
		for file in list:
			if file.getBaseName() == name:
				arch = file.getPackageArch()
				if pkg.has_key(arch):
					# Already have a package for the arch, need to
					# decide which one to use.
					orig = pkg[arch]
					if file > orig:
						pkg[arch] = file
				else:
					pkg[arch] = file

		matches = []
		for key in pkg.keys():
			matches.append(pkg[key])

		
		if not matches:
			return None
		elif len(matches) == 1:
			return matches[0]
		else:
			raise DistRPMList(matches)
Esempio n. 4
0
    def getPackage(self, name, list):

        pkg = {}
        for file in list:
            if file.getBaseName() == name:
                arch = file.getPackageArch()
                if pkg.has_key(arch):
                    # Already have a package for the arch, need to
                    # decide which one to use.
                    orig = pkg[arch]
                    if file > orig:
                        pkg[arch] = file
                else:
                    pkg[arch] = file

        matches = []
        for key in pkg.keys():
            matches.append(pkg[key])

        if not matches:
            return None
        elif len(matches) == 1:
            return matches[0]
        else:
            raise DistRPMList(matches)
	def run(self, args):

		(clean, prefix, treeinfo) = args

		name = None
		vers = None
		arch = None

		file = open(treeinfo, 'r')
		for line in file.readlines():
			a = line.split('=')

			if len(a) != 2:
				continue

			key = a[0].strip()
			value = a[1].strip()

			if key == 'family':
				if value == 'Red Hat Enterprise Linux':
					name = 'RHEL'
				elif value == 'CentOS':
					name = 'CentOS'
			elif key == 'version':
				vers = value
			elif key == 'arch':
				arch = value
		file.close()

		if not name:
			name = "BaseOS"
		if not vers:
			vers = stack.version
		if not arch:
			arch = 'x86_64'
			
		OS = 'redhat'
		roll_dir = os.path.join(prefix, name, vers, OS, arch)
		destdir = os.path.join(roll_dir, 'RPMS')

		if clean and os.path.exists(roll_dir):
			print 'Cleaning %s version %s ' % (name, vers),
			print 'for %s from pallets directory' % arch
			os.system('/bin/rm -rf %s' % roll_dir)
			os.makedirs(roll_dir)

		print 'Copying "%s" (%s,%s) pallet ...' % (name, vers, arch)
		if not os.path.exists(destdir):
			os.makedirs(destdir)

		cdtree = stack.file.Tree(self.owner.mountPoint)
		for dir in cdtree.getDirs():
			for file in cdtree.getFiles(dir):
				if not file.getName().endswith('.rpm'):
					continue
				if file.getPackageArch() != 'src' and \
					file.getBaseName() != 'comps' and \
					file.getName() != 'comps.rpm' \
					and not (arch == 'i386' and \
					re.match('^kudzu.*', file.getBaseName())):
						os.system('cp -p %s %s' % (
							file.getFullName(), 
							destdir))
		#
		# lay down a minimal roll XML config file
		#
		f = open('%s' % os.path.join(roll_dir, 'roll-%s.xml' % name),
			'w')
		f.write('<roll name="%s" interface="6.0.2">\n' % name)
		f.write('<info version="%s" release="%s" arch="%s" os="%s"/>\n' % (vers, stack.release, arch, OS))
		f.write('<iso maxsize="0" bootable="0"/>\n')
		f.write('</roll>\n')
		f.close()

		return (name, vers, arch)
Esempio n. 6
0
	def run(self):

		# Make a list of all the files that we need to copy onto the
		# pallets cds.  Don't worry about what the file types are right
		# now, we can figure that out later.
			
		list = []
		if self.config.hasRPMS():
			list.extend(self.getRPMS('RPMS'))
		for rpm in list:
			self.signRPM(rpm)

		# Make a list of both required and optional packages.  The copy
		# code is here since python is by-reference for everything.
		# After we segregate the packages add
		# any local rpms to the required list.  This makes sure we
		# pick up the roll-os-kickstart package.
		
		required = []
		if self.config.hasRolls():
			(required, optional) = self.getExternalRPMS()
			for file in list:
				required.append(file)
			print 'Required Packages', len(required)
			print 'Optional Packages', len(optional)
			for file in required: # make a copy of the list
				list.append(file)
			list.extend(optional)


		optional = 0
		for (name, id, size, files) in self.spanDisks(list):
			print 'Creating %s (%.2fMB)...' % (name, size),
			if optional:
				print ' This disk is optional (extra rpms)'
			else:
				print 
				
			if self.config.getRollInterface() == '4.0':
				# old style
				root = os.path.join(name,
						    self.config.getRollName(),
						    self.config.getRollVersion(),
						    self.config.getRollArch())
				rpmsdir = os.path.join('RedHat', 'RPMS')
			else:
				root = os.path.join(name,
						    self.config.getRollName(),
						    self.config.getRollVersion(),
						    'redhat',
						    self.config.getRollArch())
				rpmsdir = 'RPMS'

			os.makedirs(root)
			os.makedirs(os.path.join(root, rpmsdir))
			
			# Symlink in all the RPMS
			
			for file in files:
				try:
					#
					# not RPM files will throw an exception
					# in getPackageArch()
					#
					arch = file.getPackageArch()
				except:
					continue

				if arch != 'src':
					file.symlink(
						os.path.join(root, rpmsdir,
							     file.getName()))
				if file in required:
					del required[required.index(file)]
					
			if len(required) == 0:
				optional = 1
				
			# Copy the pallet XML file onto all the disks
			shutil.copy(self.config.getFullName(), root)
			
			# Create the .discinfo file
					
			self.stampDisk(name, self.config.getRollName(), 
				self.config.getRollArch(), id)
				
			# write repo data 
			self.writerepo()
			
			# make the ISO.  This code will change and move into
			# the base class, and supported bootable pallets.  Get
			# this working here and then test on the bootable
			# kernel pallet.
			
			isoname = '%s-%s-%s.%s.%s.iso' % (
				self.config.getRollName(),
				self.config.getRollVersion(),
				self.config.getRollRelease(),
				self.config.getRollArch(),
				name)
				
			if id == 1 and self.config.isBootable() == 1:
				self.makeBootable(name)
			
			self.mkisofs(isoname, self.config.getRollName(), name)
Esempio n. 7
0
	def run(self, params, args):

		(dryrun, ) = self.fillParams([ ('dryrun', 'true')])
		
                dryrun = self.str2bool(dryrun)
                
		script = []
		script.append('#!/bin/sh')

		rolls = []
		for roll in args:
			rolls.append(roll)
		if sys.stdin.isatty():
			xml = self.command('list.host.xml', [ 'localhost', 
				'pallet=%s' % string.join(rolls, ',') ])
		else:
			xml = sys.stdin.read()
		reader = Sax2.Reader()
		gen = getattr(stack.gen,'Generator_%s' % self.os)()
		gen.parse(xml)

		distPath = os.path.join(self.command('report.distribution')[:-1],
			'default')
                tree = stack.file.Tree(distPath)
		rpm_list = {}
		for file in tree.getFiles(os.path.join(self.arch, 
			'RedHat', 'RPMS')):
			if isinstance(file, stack.file.RPMFile):
				rpm_list[file.getBaseName()] = \
					file.getFullName()
				rpm_list["%s.%s" % (file.getBaseName(), \
					file.getPackageArch())] = \
						file.getFullName()
			
		rpms = []
		for line in gen.generate('packages'):
			if line.find('%package') == -1 and line.find('%end') == -1:
				rpms.append(line)
		for rpm in rpms:
			if rpm in rpm_list.keys():
				script.append('yum install -y %s' %
					rpm)
				script.append(rpm_force_template %
					rpm_list[rpm])


		cur_proc = False
		for line in gen.generate('post'):
			if not line.startswith('%post') and not line.startswith('%end'):
				script.append(line)
			else:
				if cur_proc == True:
					script.append('__POSTEOF__')
					script.append('%s %s' % (interpreter,
						t_name))
					cur_proc = False
				try:
					i = line.split().index('--interpreter')
				except ValueError:
					continue
				interpreter = line.split()[i+1]
				t_name = tempfile.mktemp()
				cur_proc = True
				script.append('cat > %s << "__POSTEOF__"' %
					t_name)
		
		script.append('\n# Boot scripts\n')
		for line in gen.generate('boot'):
			#
			# skip lines that start with '%post' or '%end'
			#
			if line[0:5] == '%post' or line[0:4] == '%end':
				continue

			script.append(line)

		if dryrun:
			self.addText(string.join(script, '\n'))
		else:
			os.system(string.join(script, '\n'))
Esempio n. 8
0
    def run(self):

        # Make a list of all the files that we need to copy onto the
        # pallets cds.	Don't worry about what the file types are right
        # now, we can figure that out later.

        list = []
        if self.config.hasRPMS():
            list.extend(self.getRPMS('RPMS'))

        # Make a list of both required and optional packages.  The copy
        # code is here since python is by-reference for everything.
        # After we segregate the packages add
        # any local rpms to the required list.	This makes sure we
        # pick up the roll-os-kickstart package.

        required = []
        if self.config.hasRolls():
            (required, optional) = self.getExternalRPMS()
            for file in list:
                required.append(file)
            print('Required Packages', len(required))
            print('Optional Packages', len(optional))
            for file in required:  # make a copy of the list
                list.append(file)
            list.extend(optional)

        optional = 0
        for (name, id, size, files) in self.spanDisks(list):
            print('Creating %s (%.2fMB)...' % (name, size), end=' ')
            if optional:
                print(' This disk is optional (extra rpms)')
            else:
                print()

            root = os.path.join(name, self.config.getRollName(),
                                self.config.getRollVersion(),
                                self.config.getRollRelease(),
                                self.config.getRollOS(),
                                self.config.getRollArch())

            rpmsdir = 'RPMS'

            os.makedirs(root)
            if self.config.getRollOS() in ['redhat', 'sles']:
                os.makedirs(os.path.join(root, rpmsdir))

            # Symlink in all the RPMS

            for file in files:
                try:
                    #
                    # not RPM files will throw an exception
                    # in getPackageArch()
                    #
                    arch = file.getPackageArch()
                except:
                    continue

                if arch != 'src':
                    file.symlink(os.path.join(root, rpmsdir, file.getName()))
                if file in required:
                    del required[required.index(file)]

            if len(required) == 0:
                optional = 1

            # Copy the pallet XML file onto all the disks
            shutil.copy(self.config.getFullName(), root)

            # Create the .discinfo file

            self.stampDisk(name, self.config.getRollName(),
                           self.config.getRollArch(), id)

            # write repodata
            if self.config.getRollOS() in ['redhat', 'sles']:
                self.writerepo(self.config.getRollName(),
                               self.config.getRollVersion(),
                               self.config.getRollRelease(),
                               self.config.getRollOS(),
                               self.config.getRollArch())

            # copy the graph and node XMLs files into the pallet
            self.copyXMLs(self.config.getRollOS(), self.config.getRollName(),
                          self.config.getRollVersion(),
                          self.config.getRollRelease(),
                          self.config.getRollArch())

            # make the ISO.	 This code will change and move into
            # the base class, and supported bootable pallets.  Get
            # this working here and then test on the bootable
            # kernel pallet.

            isoname = '%s-%s-%s.%s.%s.iso' % (
                self.config.getRollName(), self.config.getRollVersion(),
                self.config.getRollRelease(), self.config.getRollArch(), name)

            if id == 1 and self.config.isBootable() == 1:
                try:
                    self.makeBootable(self.config.getRollName(),
                                      self.config.getRollVersion(),
                                      self.config.getRollRelease(),
                                      self.config.getRollArch())
                except ValueError as msg:
                    print('ERROR -', msg)
                    print('Pallet is not bootable')
                    self.config.setBootable(False)

            self.mkisofs(isoname, self.config.getRollName(), name)
Esempio n. 9
0
    def run(self, params, args):

        (dryrun, ) = self.fillParams([('dryrun', 'true')])

        dryrun = self.str2bool(dryrun)

        script = []
        script.append('#!/bin/sh')

        rolls = []
        for roll in args:
            rolls.append(roll)
        if sys.stdin.isatty():
            xml = self.command(
                'list.host.xml',
                ['localhost',
                 'pallet=%s' % string.join(rolls, ',')])
        else:
            xml = sys.stdin.read()
        reader = Sax2.Reader()
        gen = getattr(stack.gen, 'Generator_%s' % self.os)()
        gen.parse(xml)

        distPath = os.path.join(
            self.command('report.distribution')[:-1], 'default')
        tree = stack.file.Tree(distPath)
        rpm_list = {}
        for file in tree.getFiles(os.path.join(self.arch, 'RedHat', 'RPMS')):
            if isinstance(file, stack.file.RPMFile):
                rpm_list[file.getBaseName()] = \
                 file.getFullName()
                rpm_list["%s.%s" % (file.getBaseName(), \
                 file.getPackageArch())] = \
                  file.getFullName()

        rpms = []
        for line in gen.generate('packages'):
            if line.find('%package') == -1 and line.find('%end') == -1:
                rpms.append(line)
        for rpm in rpms:
            if rpm in rpm_list.keys():
                script.append('yum install -y %s' % rpm)
                script.append(rpm_force_template % rpm_list[rpm])

        cur_proc = False
        for line in gen.generate('post'):
            if not line.startswith('%post') and not line.startswith('%end'):
                script.append(line)
            else:
                if cur_proc == True:
                    script.append('__POSTEOF__')
                    script.append('%s %s' % (interpreter, t_name))
                    cur_proc = False
                try:
                    i = line.split().index('--interpreter')
                except ValueError:
                    continue
                interpreter = line.split()[i + 1]
                t_name = tempfile.mktemp()
                cur_proc = True
                script.append('cat > %s << "__POSTEOF__"' % t_name)

        script.append('\n# Boot scripts\n')
        for line in gen.generate('boot'):
            #
            # skip lines that start with '%post' or '%end'
            #
            if line[0:5] == '%post' or line[0:4] == '%end':
                continue

            script.append(line)

        if dryrun:
            self.addText(string.join(script, '\n'))
        else:
            os.system(string.join(script, '\n'))
Esempio n. 10
0
	def run(self, args):
		import stack

		(clean, prefix, treeinfo) = args

		name = None
		vers = None
		arch = None

		file = open(treeinfo, 'r')
		for line in file.readlines():
			a = line.split('=')

			if len(a) != 2:
				continue

			key = a[0].strip()
			value = a[1].strip()

			if key == 'family':
				if value == 'Red Hat Enterprise Linux':
					name = 'RHEL'
				elif value == 'CentOS':
					name = 'CentOS'
			elif key == 'version':
				vers = value
			elif key == 'arch':
				arch = value
		file.close()

		if not name:
			name = "BaseOS"
		if not vers:
			vers = stack.version
		if not arch:
			arch = 'x86_64'
			
		OS = 'redhat'
		roll_dir = os.path.join(prefix, name, vers, OS, arch)
		destdir = os.path.join(roll_dir, 'RPMS')

		print 'stack.release (%s)' % stack.release
		if stack.release == '7.x':
			liveosdir = os.path.join(roll_dir, 'LiveOS')

		if clean and os.path.exists(roll_dir):
			print 'Cleaning %s version %s ' % (name, vers),
			print 'for %s from pallets directory' % arch
			os.system('/bin/rm -rf %s' % roll_dir)
			os.makedirs(roll_dir)

		print 'Copying "%s" (%s,%s) pallet ...' % (name, vers, arch)
		if not os.path.exists(destdir):
			os.makedirs(destdir)

		if stack.release == '7.x' and not os.path.exists(liveosdir):
			os.makedirs(liveosdir)

		cdtree = stack.file.Tree(self.owner.mountPoint)
		for dir in cdtree.getDirs():
			for file in cdtree.getFiles(dir):
				if stack.release == '7.x' and dir == 'LiveOS' \
					and file.getName().endswith('.img'):

					os.system('cp -p %s %s' % (
						file.getFullName(), 
						liveosdir))
				else:
					if not file.getName().endswith('.rpm'):
						continue
					if file.getPackageArch() != 'src' and \
						file.getBaseName() != 'comps' and \
						file.getName() != 'comps.rpm' \
						and not (arch == 'i386' and \
						re.match('^kudzu.*', file.getBaseName())):
							os.system('cp -p %s %s' % (
								file.getFullName(), 
								destdir))
		#
		# lay down a minimal roll XML config file
		#
		f = open('%s' % os.path.join(roll_dir, 'roll-%s.xml' % name),
			'w')
		f.write('<roll name="%s" interface="6.0.2">\n' % name)
		f.write('<info version="%s" release="%s" arch="%s" os="%s"/>\n' % (vers, stack.release, arch, OS))
		f.write('<iso maxsize="0" bootable="0"/>\n')
		f.write('</roll>\n')
		f.close()

		return (name, vers, arch)