--- mock.multi 2006-05-10 14:03:18.000000000 -0500 +++ mock.multicfg 2006-05-10 16:03:43.000000000 -0500 @@ -670,32 +670,9 @@ default=False, help="quiet down output") return parser.parse_args() - -def main(): - # before we go on, make sure the user is a member of the 'mock' group. - member = False - for item in os.getgroups(): - try: - grptup = grp.getgrgid(item) - except KeyError, e: - continue - if grptup[0] == 'mock': - member = True - - if not member: - print "You need to be a member of the mock group for this to work" - sys.exit(1) - # and make sure they're not root - if os.geteuid() == 0: - error("Don't try to run mock as root!") - sys.exit(1) - - # config path - config_path='/etc/mock' - +def set_default_config_opts(config_opts): # defaults - config_opts = {} config_opts['basedir'] = '/var/lib/mock/' # root name is automatically added to this config_opts['chroot'] = '/usr/sbin/mock-helper chroot' config_opts['mount'] = '/usr/sbin/mock-helper mount' @@ -724,29 +701,9 @@ config_opts['files']['/etc/resolv.conf'] = "nameserver 192.168.1.1\n" config_opts['files']['/etc/hosts'] = "127.0.0.1 localhost localhost.localdomain\n" - - # cli option parsing - (options, args) = command_parse() - - if len(args) < 1: - error("No srpm or command specified - nothing to do") - sys.exit(50) + - if options.configdir: - config_path = options.configdir - - # read in the config file by chroot name - if options.chroot.endswith('.cfg'): - cfg = '%s/%s' % (config_path, options.chroot) - else: - cfg = '%s/%s.cfg' % (config_path, options.chroot) - - if os.path.exists(cfg): - execfile(cfg) - else: - error("Could not find config file %s for chroot %s" % (cfg, options.chroot)) - sys.exit(1) - +def set_config_opts_from_cmdline(config_opts, options): # do some other options and stuff if options.arch: config_opts['target_arch'] = options.arch @@ -768,36 +725,123 @@ if options.uniqueext: config_opts['unique-ext'] = options.uniqueext - - # do whatever we're here to do - if args[0] == 'clean': - # unset a --no-clean - config_opts['clean'] = True - try: - my = None - my = Root(config_opts) - except Error, e: - print e - if my: - my.close() - sys.exit(100) +def do_clean(config_opts, prep=False): + # unset a --no-clean + config_opts['clean'] = True + try: + my = None + my = Root(config_opts) + if prep: + my.prep() + except Error, e: + print e + if my: + my.close() + sys.exit(100) - my.close() + my.close() + + if prep: + print 'Finished initializing root' + else: print 'Finished cleaning root' - - elif args[0] == 'init': + +def do_rebuild( config_opts, srpms ): + # check all srpms to ensure they are all valid + for srpm in srpms: + ts = rpmUtils.transaction.initReadOnlyTransaction() try: - my = None - my = Root(config_opts) - my.prep() + hdr = rpmUtils.miscutils.hdrFromPackage(ts, srpm) + except rpmUtils.RpmUtilsError, e: + error("Specified srpm %s cannot be found/opened" % srpm) + sys.exit(50) + + if hdr[rpm.RPMTAG_SOURCEPACKAGE] != 1: + error("Specified srpm isn't a srpm! Can't go on") + sys.exit(50) + + # Prep build root + my = None # if Root() fails, my will be undefined so we force it to None + try: + my = Root(config_opts) + os.umask(0022) # set a umask- protects from paranoid whackjobs with an 002 umask + my.prep() + except Error, e: + error(e) + if my: + my.close() + sys.exit(e.resultcode) + + # build each srpm + for srpm in srpms: + try: + my.build(srpm) except Error, e: - print e + error(e) if my: my.close() - sys.exit(100) + sys.exit(e.resultcode) + + my.close() + print "Results and/or logs in: %s" % my.resultdir + +def main(): + # before we go on, make sure the user is a member of the 'mock' group. + member = False + for item in os.getgroups(): + try: + grptup = grp.getgrgid(item) + except KeyError, e: + continue + if grptup[0] == 'mock': + member = True - my.close() - print 'Finished initializing root' + if not member: + print "You need to be a member of the mock group for this to work" + sys.exit(1) + + # and make sure they're not root + if os.geteuid() == 0: + error("Don't try to run mock as root!") + sys.exit(1) + + # config path + config_path='/etc/mock' + + # cli option parsing + (options, args) = command_parse() + + # set default config_opts + config_opts = {} + set_default_config_opts(config_opts) + + if len(args) < 1: + error("No srpm or command specified - nothing to do") + sys.exit(50) + + if options.configdir: + config_path = options.configdir + + # read in the config file by chroot name + if options.chroot.endswith('.cfg'): + cfg = '%s/%s' % (config_path, options.chroot) + else: + cfg = '%s/%s.cfg' % (config_path, options.chroot) + + if os.path.exists(cfg): + execfile(cfg) + else: + error("Could not find config file %s for chroot %s" % (cfg, options.chroot)) + sys.exit(1) + + set_config_opts_from_cmdline(config_opts, options) + + # do whatever we're here to do + if args[0] == 'clean': + do_clean(config_opts, prep=False ) + + elif args[0] == 'init': + do_clean(config_opts, prep=True ) elif args[0] == 'chroot': config_opts['clean'] = config_opts['quiet'] = False @@ -815,42 +859,7 @@ else: srpms = args[0:] - for srpm in srpms: - ts = rpmUtils.transaction.initReadOnlyTransaction() - try: - hdr = rpmUtils.miscutils.hdrFromPackage(ts, srpm) - except rpmUtils.RpmUtilsError, e: - error("Specified srpm %s cannot be found/opened" % srpm) - sys.exit(50) - - if hdr[rpm.RPMTAG_SOURCEPACKAGE] != 1: - error("Specified srpm isn't a srpm! Can't go on") - sys.exit(50) - - # Prep build root - my = None # if Root() fails, my will be undefined so we force it to None - try: - my = Root(config_opts) - os.umask(0022) # set a umask- protects from paranoid whackjobs with an 002 umask - my.prep() - except Error, e: - error(e) - if my: - my.close() - sys.exit(e.resultcode) - - for srpm in srpms: - try: - my.build(srpm) - except Error, e: - error(e) - if my: - my.close() - sys.exit(e.resultcode) - - my.close() - print "Results and/or logs in: %s" % my.resultdir - + do_rebuild( config_opts, srpms ) if __name__ == '__main__': main()