pungi/pungi

183 lines
7.7 KiB
Plaintext
Raw Normal View History

2006-10-24 01:46:30 +00:00
#!/usr/bin/python -tt
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
2006-10-24 13:44:11 +00:00
# the Free Software Foundation; version 2 of the License.
2006-10-24 01:46:30 +00:00
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
import os
import pypungi.config
import pypungi.gather
import pypungi.pungi
2006-10-24 01:46:30 +00:00
import yum
import pykickstart.parser
import pykickstart.version
import subprocess
2006-10-24 01:46:30 +00:00
def main():
config = pypungi.config.Config()
(opts, args) = get_arguments(config)
2007-11-30 20:41:58 +00:00
# You must be this high to ride if you're going to do root tasks
if os.geteuid () != 0 and (opts.do_all or opts.do_buildinstall):
print >> sys.stderr, "You must run pungi as root"
return 1
if opts.do_all or opts.do_buildinstall:
try:
selinux = subprocess.Popen('/usr/sbin/getenforce', stdout=subprocess.PIPE).communicate()[0].strip('\n')
if selinux == 'Enforcing':
print >> sys.stdout, "WARNING: SELinux is enforcing. This may lead to a compose with selinux disabled."
print >> sys.stdout, "Consider running with setenforce 0."
except:
pass
# Set up the kickstart parser and pass in the kickstart file we were handed
ksparser = pykickstart.parser.KickstartParser(pykickstart.version.makeVersion())
ksparser.readKickstart(opts.config)
if opts.sourceisos:
config.set('default', 'arch', 'source')
for part in ksparser.handler.partition.partitions:
if part.mountpoint == 'iso':
config.set('default', 'cdsize', str(part.size))
config.set('default', 'force', str(opts.force))
# Set up our directories
if not os.path.exists(config.get('default', 'destdir')):
2006-10-24 01:46:30 +00:00
try:
os.makedirs(config.get('default', 'destdir'))
2006-10-24 01:46:30 +00:00
except OSError, e:
print >> sys.stderr, "Error: Cannot create destination dir %s" % config.get('default', 'destdir')
2006-10-24 01:46:30 +00:00
sys.exit(1)
else:
print >> sys.stdout, "Warning: Reusing existing destination directory."
2006-10-24 01:46:30 +00:00
cachedir = config.get('default', 'cachedir')
if not os.path.exists(cachedir):
2006-10-24 01:46:30 +00:00
try:
os.makedirs(cachedir)
2006-10-24 01:46:30 +00:00
except OSError, e:
print >> sys.stderr, "Error: Cannot create cache dir %s" % cachedir
2006-10-24 01:46:30 +00:00
sys.exit(1)
# Actually do work.
if not opts.sourceisos:
if opts.do_all or opts.do_gather:
mygather = pypungi.gather.Gather(config, ksparser)
mygather.getPackageObjects()
mygather.downloadPackages()
mygather.makeCompsFile()
if not opts.nosource:
mygather.getSRPMList()
mygather.downloadSRPMs()
2007-08-16 14:03:13 +00:00
del mygather
mypungi = pypungi.pungi.Pungi(config)
2007-07-28 14:59:14 +00:00
if opts.do_all or opts.do_createrepo:
mypungi.doCreaterepo()
if opts.do_all or opts.do_buildinstall:
mypungi.doGetRelnotes()
2007-12-03 04:02:51 +00:00
mypungi.doBuildinstall()
if opts.do_all or opts.do_createiso:
mypungi.doCreateIsos(split=opts.nosplitmedia)
# Do things slightly different for src.
if opts.sourceisos:
# we already have all the content gathered
mypungi = pypungi.pungi.Pungi(config)
mypungi.topdir = os.path.join(config.get('default', 'destdir'),
config.get('default', 'version'),
2007-01-29 21:06:08 +00:00
config.get('default', 'flavor'),
'source', 'SRPM')
if opts.do_all or opts.do_createiso:
mypungi.doCreateIsos(split=opts.nosplitmedia)
2006-10-24 01:46:30 +00:00
print "All done!"
2006-10-24 01:46:30 +00:00
if __name__ == '__main__':
from optparse import OptionParser
import sys
import time
today = time.strftime('%Y%m%d', time.localtime())
2006-10-24 01:46:30 +00:00
def get_arguments(config):
2007-11-22 14:31:15 +00:00
parser = OptionParser(version="%prog 1.1.10")
def set_config(option, opt_str, value, parser, config):
config.set('default', option.dest, value)
# Pulled in from config file to be cli options as part of pykickstart conversion
parser.add_option("--name", dest="name", type="string",
action="callback", callback=set_config, callback_args=(config, ),
help='the name for your distribution (defaults to "Fedora")')
parser.add_option("--ver", dest="version", type="string",
action="callback", callback=set_config, callback_args=(config, ),
help='the version of your distribution (defaults to datestamp)')
parser.add_option("--flavor", dest="flavor", type="string",
action="callback", callback=set_config, callback_args=(config, ),
help='the flavor of your distribution spin (optional)')
parser.add_option("--destdir", dest="destdir", type="string",
action="callback", callback=set_config, callback_args=(config, ),
help='destination directory (defaults to current directory)')
parser.add_option("--cachedir", dest="cachedir", type="string",
action="callback", callback=set_config, callback_args=(config, ),
help='package cache directory (defaults to /var/cache/pungi)')
parser.add_option("--bugurl", dest="bugurl", type="string",
action="callback", callback=set_config, callback_args=(config, ),
help='the url for your bug system (defaults to http://bugzilla.redhat.com)')
parser.add_option("--discs", dest="discs", type="string",
action="callback", callback=set_config, callback_args=(config, ),
help='the number of discs you want to create (defaults to 1)')
parser.add_option("--nosource", action="store_true", dest="nosource",
2007-08-27 20:59:31 +00:00
help='disable gathering of source packages (optional)')
2007-11-30 15:36:28 +00:00
parser.add_option("--nosplitmedia", action="store_false", dest="nosplitmedia", default=True,
help='disable creation of split media (optional)')
parser.add_option("--sourceisos", default=False, action="store_true", dest="sourceisos",
help='Create the source isos (other arch runs must be done)')
parser.add_option("--force", default=False, action="store_true",
help='Force reuse of an existing destination directory (will overwrite files)')
parser.add_option("-c", "--config", dest="config",
help='Path to kickstart config file')
parser.add_option("--all-stages", action="store_true", default=True, dest="do_all",
help="Enable ALL stages")
parser.add_option("-G", action="store_true", default=False, dest="do_gather",
help="Flag to enable processing the Gather stage")
2007-07-28 14:59:14 +00:00
parser.add_option("-C", action="store_true", default=False, dest="do_createrepo",
help="Flag to enable processing the Createrepo stage")
parser.add_option("-B", action="store_true", default=False, dest="do_buildinstall",
help="Flag to enable processing the BuildInstall stage")
parser.add_option("-I", action="store_true", default=False, dest="do_createiso",
help="Flag to enable processing the CreateISO stage")
2006-10-24 01:46:30 +00:00
(opts, args) = parser.parse_args()
if not opts.config:
parser.print_help()
sys.exit(0)
2006-10-24 01:46:30 +00:00
if opts.do_gather or opts.do_createrepo or opts.do_buildinstall or opts.do_createiso:
opts.do_all = False
return (opts, args)
2006-10-24 01:46:30 +00:00
main()