"repomd": None,
"local_pkgs_path": None,
"release": None,
+ "record_pkgs": [],
}
class ConfigMgr(object):
optparser.add_option('-o', '--outdir', type='string', action='store', dest='outdir', default=None, help='Output directory')
optparser.add_option('-A', '--arch', type='string', dest='arch', default=None, help='Specify repo architecture')
optparser.add_option('', '--release', type='string', dest='release', default=None, metavar='RID', help='Generate a release of RID with all neccessary files ')
+ optparser.add_option("", "--record-pkgs", type="string", dest="record_pkgs", default=None, help="Record the installed packages, valid values: name, content, license")
optparser.add_option('', '--pkgmgr', type='string', dest='pkgmgr', default=None, help='Specify backend package manager')
optparser.add_option('', '--local-pkgs-path', type='string', dest='local_pkgs_path', default=None, help='Path for local pkgs(rpms) to be installed')
return optparser
if self.options.release:
self.configmgr.create['release'] = self.options.release
+ if self.options.record_pkgs:
+ self.configmgr.create['record_pkgs'] = []
+ for type in self.options.record_pkgs.split(','):
+ if type not in ('name', 'content', 'license'):
+ msger.error("Please specify what to be recorded: \"name\", \"content\", \"license\"")
+ self.configmgr.create['record_pkgs'].append(type)
+
if self.options.arch is not None:
self.configmgr.create['arch'] = self.options.arch
# This value is set with compression_method function. """
self.__img_compression_method = None
- self._recording_pkgs = None
+ self._recording_pkgs = []
# available size in root fs, init to 0
self._root_fs_avail = 0
def _save_recording_pkgs(self, destdir):
"""Save the list or content of installed packages to file.
"""
- if self._recording_pkgs not in ('content', 'name'):
- return
-
pkgs = self._pkgs_content.keys()
pkgs.sort() # inplace op
- # save package name list anyhow
if not os.path.exists(destdir):
os.makedirs(destdir)
-
- namefile = os.path.join(destdir, self.name + '-pkgs.txt')
- f = open(namefile, "w")
- content = '\n'.join(pkgs)
- f.write(content)
- f.close()
- self.outimage.append(namefile);
+ if 'name' in self._recording_pkgs :
+ namefile = os.path.join(destdir, self.name + '-pkgs.txt')
+ f = open(namefile, "w")
+ content = '\n'.join(pkgs)
+ f.write(content)
+ f.close()
+ self.outimage.append(namefile);
# if 'content', save more details
- if self._recording_pkgs == 'content':
+ if 'content' in self._recording_pkgs :
contfile = os.path.join(destdir, self.name + '-pkgs-content.txt')
f = open(contfile, "w")
f.close()
self.outimage.append(contfile)
+ if 'license' in self._recording_pkgs:
+ licensefile = os.path.join(destdir, self.name + '-license.txt')
+ f = open(licensefile, "w")
+ f.write('Summary:\n')
+ for license in sorted (self._pkgs_license, key=lambda license: len(self._pkgs_license[license])):
+ f.write("\t- %s: %s\n" % (license, len(self._pkgs_license[license])))
+ f.write('\nDetails:\n')
+ for license in sorted (self._pkgs_license, key=lambda license: len(self._pkgs_license[license])):
+ f.write("\t- %s:\n" % (license))
+ for pkg in sorted(self._pkgs_license[license]):
+ f.write("\t\t- %s\n" % (pkg))
+ f.write('\n')
+ f.close()
+ self.outimage.append(licensefile);
+
def _get_required_packages(self):
"""Return a list of required packages.
yum_conf = self._mktemp(prefix = "yum.conf-")
- keep_record = None
- if hasattr(self, '_include_src') and self._include_src:
- keep_record = 'include_src'
- if self._recording_pkgs in ('name', 'content'):
+ keep_record = []
+ if len(self._recording_pkgs) > 0:
keep_record = self._recording_pkgs
pkg_manager = self.get_pkg_manager(keep_record)
except CreatorError, e:
raise
finally:
- if keep_record:
+ if len(keep_record):
self._pkgs_content = pkg_manager.getAllContent()
+ self._pkgs_license = pkg_manager.getPkgLicense()
pkg_manager.closeRpmDB()
pkg_manager.close()
self.arch.setup_arch(self.creator.target_arch)
self.__recording_pkgs = recording_pkgs
+ self.__pkgs_license = {}
self.__pkgs_content = {}
def doFileLogSetup(self, uid, logfile):
if checksize and pkgs_total_size > checksize:
raise CreatorError("Size of specified root partition in kickstart file is too small to install all selected packages.")
- if self.__recording_pkgs:
+ if len(self.__recording_pkgs) > 0:
# record all pkg and the content
for pkg in dlpkgs:
pkg_long_name = "%s-%s.%s.rpm" % (pkg.name, pkg.printVer(), pkg.arch)
self.__pkgs_content[pkg_long_name] = pkg.files
+ license = pkg.license
+ if license in self.__pkgs_license.keys():
+ self.__pkgs_license[license].append(pkg_long_name)
+ else:
+ self.__pkgs_license[license] = [pkg_long_name]
total_count = len(dlpkgs)
cached_count = 0
def getAllContent(self):
return self.__pkgs_content
+
+ def getPkgLicense(self):
+ return self.__pkgs_license
raise CreatorError("Invalid argument: creator")
self.__recording_pkgs = recording_pkgs
+ self.__pkgs_license = {}
self.__pkgs_content = {}
self.creator = creator
self.repos = []
if checksize and pkgs_total_size > checksize:
raise CreatorError("Size of specified root partition in kickstart file is too small to install all selected packages.")
- if self.__recording_pkgs:
+ if len(self.__recording_pkgs) > 0:
# record all pkg and the content
localpkgs = self.localpkgs.keys()
for pkg in dlpkgs:
+ license = ''
if pkg.name() in localpkgs:
hdr = rpmmisc.readRpmHeader(self.ts, self.localpkgs[pkg.name()])
pkg_long_name = "%s-%s-%s.%s.rpm" % (hdr['name'], hdr['version'], hdr['release'], hdr['arch'])
+ license = hdr['license']
else:
pkg_long_name = "%s-%s.%s.rpm" % (pkg.name(), pkg.edition(), pkg.arch())
+ package = zypp.asKindPackage(pkg)
+ license = package.license()
self.__pkgs_content[pkg_long_name] = {} #TBD: to get file list
+ if license in self.__pkgs_license.keys():
+ self.__pkgs_license[license].append(pkg_long_name)
+ else:
+ self.__pkgs_license[license] = [pkg_long_name]
total_count = len(dlpkgs)
cached_count = 0
def getAllContent(self):
return self.__pkgs_content
+ def getPkgLicense(self):
+ return self.__pkgs_license
+
def __initialize_repo_manager(self):
if self.repo_manager:
return
createopts = cfgmgr.create
ksconf = args[0]
- recording_pkgs = None
+ recording_pkgs = []
+ if len(createopts['record_pkgs']) > 0:
+ recording_pkgs = createopts['record_pkgs']
if createopts['release'] is not None:
- recording_pkgs = "name"
+ if 'name' not in recording_pkgs:
+ recording_pkgs.append('name')
ksconf = misc.save_ksconf_file(ksconf, createopts['release'])
name = os.path.splitext(os.path.basename(ksconf))[0]
createopts['outdir'] = "%s/%s-%s/" % (createopts['outdir'], name, createopts['release'])
creator = fs.FsImageCreator(createopts, pkgmgr)
creator._include_src = opts.include_src
- if recording_pkgs is not None:
+ if len(recording_pkgs) > 0:
creator._recording_pkgs = recording_pkgs
destdir = os.path.abspath(os.path.expanduser(createopts["outdir"]))
msger.warning('livecd cannot support arm images, Quit')
return
- recording_pkgs = None
+ recording_pkgs = []
+ if len(creatoropts['record_pkgs']) > 0:
+ recording_pkgs = creatoropts['record_pkgs']
if creatoropts['release'] is not None:
- recording_pkgs = "name"
+ if 'name' not in recording_pkgs:
+ recording_pkgs.append('name')
ksconf = misc.save_ksconf_file(ksconf, creatoropts['release'])
name = os.path.splitext(os.path.basename(ksconf))[0]
creatoropts['outdir'] = "%s/%s-%s/" % (creatoropts['outdir'], name, creatoropts['release'])
creator = livecd.LiveCDImageCreator(creatoropts, pkgmgr)
- if recording_pkgs is not None:
+ if len(recording_pkgs) > 0:
creator._recording_pkgs = recording_pkgs
try:
msger.warning('liveusb cannot support arm images, Quit')
return
- recording_pkgs = None
+ recording_pkgs = []
+ if len(creatoropts['record_pkgs']) > 0:
+ recording_pkgs = creatoropts['record_pkgs']
if creatoropts['release'] is not None:
- recording_pkgs = "name"
+ if 'name' not in recording_pkgs:
+ recording_pkgs.append('name')
ksconf = misc.save_ksconf_file(ksconf, creatoropts['release'])
name = os.path.splitext(os.path.basename(ksconf))[0]
creatoropts['outdir'] = "%s/%s-%s/" % (creatoropts['outdir'], name, creatoropts['release'])
creator = liveusb.LiveUSBImageCreator(creatoropts, pkgmgr)
- if recording_pkgs is not None:
+ if len(recording_pkgs) > 0:
creator._recording_pkgs = recording_pkgs
try:
creatoropts = cfgmgr.create
ksconf = args[0]
- recording_pkgs = None
+ recording_pkgs = []
+ if len(creatoropts['record_pkgs']) > 0:
+ recording_pkgs = creatoropts['record_pkgs']
if creatoropts['release'] is not None:
- recording_pkgs = "name"
+ if 'name' not in recording_pkgs:
+ recording_pkgs.append('name')
ksconf = misc.save_ksconf_file(ksconf, creatoropts['release'])
name = os.path.splitext(os.path.basename(ksconf))[0]
creatoropts['outdir'] = "%s/%s-%s/" % (creatoropts['outdir'], name, creatoropts['release'])
creator = loop.LoopImageCreator(creatoropts, pkgmgr, opts.taring_to)
- if recording_pkgs is not None:
+ if len(recording_pkgs) > 0:
creator._recording_pkgs = recording_pkgs
try:
creatoropts = cfgmgr.create
ksconf = args[0]
- recording_pkgs = None
+ recording_pkgs = []
+ if len(creatoropts['record_pkgs']) > 0:
+ recording_pkgs = creatoropts['record_pkgs']
if creatoropts['release'] is not None:
- recording_pkgs = "name"
+ if 'name' not in recording_pkgs:
+ recording_pkgs.append('name')
ksconf = misc.save_ksconf_file(ksconf, creatoropts['release'])
name = os.path.splitext(os.path.basename(ksconf))[0]
creatoropts['outdir'] = "%s/%s-%s/" % (creatoropts['outdir'], name, creatoropts['release'])
creator = raw.RawImageCreator(creatoropts, pkgmgr)
- if recording_pkgs is not None:
+ if len(recording_pkgs) > 0:
creator._recording_pkgs = recording_pkgs
try: