/[gli]/branches/qs/src/GLIPortage.py
Gentoo

Diff of /branches/qs/src/GLIPortage.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1911 Revision 1912
10 10
11import re 11import re
12import os 12import os
13import sys 13import sys
14import GLIUtility 14import GLIUtility
15import GLILogger
15from GLIException import GLIException 16from GLIException import GLIException
16 17
17class GLIPortage(object): 18class GLIPortage(object):
18 19
19 def __init__(self, chroot_dir, logger, debug, cc, compile_logfile): 20 def __init__(self, chroot_dir, logger, debug, cc, compile_logfile):
328 systempkgs = GLIUtility.spawn(r"PKGDIR=/tmp/fake_binpkg emerge -eqKp system | grep -e '^\[binary' | sed -e 's:^\[binary .\+\] ::' -e 's: .\+$::'", return_output=True)[1].strip().split("\n") 329 systempkgs = GLIUtility.spawn(r"PKGDIR=/tmp/fake_binpkg emerge -eqKp system | grep -e '^\[binary' | sed -e 's:^\[binary .\+\] ::' -e 's: .\+$::'", return_output=True)[1].strip().split("\n")
329 return systempkgs 330 return systempkgs
330 331
331def usage(progname): 332def usage(progname):
332 print """ 333 print """
333Usage: %s [-c|--chroot-dir <chroot directory>] [-g|--grp] [-s|--stage3] [-h|--help] 334Usage: %s [-c|--chroot-dir <chroot directory>] [-g|--grp] [-s|--stage3] [-l|--logfile <logfile>] [-h|--help]
334 335
335Options: 336Options:
336 337
337 -c|--chroot-dir Specifies the directory where your chroot is. This is 338 -c|--chroot-dir Specifies the directory where your chroot is. This is
338 "/mnt/gentoo" by default. 339 "/mnt/gentoo" by default.
343 -s|--stage3 Create a stage3 equivelant in the chroot directory by using 344 -s|--stage3 Create a stage3 equivelant in the chroot directory by using
344 files from the LiveCD. 345 files from the LiveCD.
345 346
346 -k|--kernel Install kernel and modules from LiveCD into the chroot 347 -k|--kernel Install kernel and modules from LiveCD into the chroot
347 348
349 -l|--logfile Sets the logfile for the ouput. defaults to cwd/install.log
350
348 -h|--help Display this help 351 -h|--help Display this help
349""" % (progname) 352""" % (progname)
350 353
351if __name__ == "__main__": 354if __name__ == "__main__":
352 chroot_dir = "/mnt/gentoo" 355 chroot_dir = "/mnt/gentoo"
356 logfile = None
353 mode = None 357 mode = None
354 grp_packages = [] 358 grp_packages = []
355 progname = sys.argv.pop(0) 359 progname = sys.argv.pop(0)
356 while len(sys.argv): 360 while len(sys.argv):
357 arg = sys.argv.pop(0) 361 arg = sys.argv.pop(0)
358 if arg == "-c" or arg == "--chroot-dir": 362 if arg == "-c" or arg == "--chroot-dir":
359 chroot_dir = sys.argv.pop(0) 363 chroot_dir = sys.argv.pop(0)
364 elif arg == "-l" or arg == "--logfile":
365 logfile = sys.argv.pop(0)
360 elif arg == "-g" or arg == "--grp": 366 elif arg == "-g" or arg == "--grp":
361 mode = "grp" 367 mode = "grp"
362 elif arg == "-s" or arg == "--stage3": 368 elif arg == "-s" or arg == "--stage3":
363 mode = "stage3" 369 mode = "stage3"
364 elif arg == "-k" or arg == "--kernel": 370 elif arg == "-k" or arg == "--kernel":
369 elif arg[0] == "-": 375 elif arg[0] == "-":
370 usage(progname) 376 usage(progname)
371 sys.exit(1) 377 sys.exit(1)
372 else: 378 else:
373 grp_packages.append(arg) 379 grp_packages.append(arg)
374 380 logger = GLILogger.Logger(logfile)
375 gliportage = GLIPortage(chroot_dir, True, None, False, None, None) 381 gliportage = GLIPortage(chroot_dir, logger, True, None, False)
376 if mode == "stage3": 382 if mode == "stage3":
377 try: 383 try:
378 systempkgs = gliportage.get_system_packages() 384 systempkgs = gliportage.get_system_packages()
379 except: 385 except:
380 print "Could not open generate list of system packages!" 386 print "Could not open generate list of system packages!"
439 print "Copying " + tmppkg + " (" + str(i+1) + "/" + str(len(pkglist)) + ")" 445 print "Copying " + tmppkg + " (" + str(i+1) + "/" + str(len(pkglist)) + ")"
440 gliportage.copy_pkg_to_chroot(tmppkg) 446 gliportage.copy_pkg_to_chroot(tmppkg)
441 gliportage.add_pkg_to_world(pkg) 447 gliportage.add_pkg_to_world(pkg)
442 print "GRP install complete!" 448 print "GRP install complete!"
443 elif mode == "kernel": 449 elif mode == "kernel":
450 #Code copied from GLIArchTemplate
451 GLIUtility.spawn(r"find /var/db/pkg -type f -name CONTENTS | xargs awk '/^obj \/lib\/modules\// { print $2; }' > /tmp/kernel_modules")
452 files = GLIUtility.spawn('ls -1 --color=no /boot/System* /boot/kernel* /boot/initr* $(for i in $(find "/lib/modules/" -type f); do grep --quiet "^${i}$" /tmp/kernel_modules || echo ${i}; done); rm /tmp/kernel_modules 2>/dev/null', return_output=True)[1].strip().split("\n")
453 if not files:
454 print "Error: could not determine files to copy for livecd-kernel"
455 sys.exit(1)
456 if not GLIUtility.exitsuccess(GLIUtility.spawn("cp -p --parents %s %s/" % (" ".join(files), chroot_dir))):
457 print "Error: could not copy kernel, initramfs, or modules"
458 sys.exit(1)
459 GLIUtility.spawn("depmod -a")
460 portage_info = {}
461 for line in GLIUtility.spawn(r"emerge --info 2>/dev/null | grep '^[A-Z0-9_]\+=' | sed -e 's:\" \([A-Z]\):\"\n\1:g'", chroot=chroot_dir, return_output=True)[1].strip().split("\n"):
462 parts = line.split("=", 1)
463 portage_info[parts[0]] = parts[1].strip("'\"")
464 arch = portage_info["ACCEPT_KEYWORDS"].split(" ")[0].strip("~")
465 values = {
466 'CATEGORY': "sys-kernel",
467 'CBUILD': portage_info['CHOST'],
468 'CFLAGS': portage_info['CFLAGS'],
469 'CHOST': portage_info['CHOST'],
470 'CONTENTS': "",
471# 'COUNTER': "0",
472 'CXXFLAGS': portage_info.get("CXXFLAGS", ""),
473 'DEPEND': "",
474 'DESCRIPTION': "LiveCD kernel as installed by GLI",
475 'EAPI': "0",
476 'FEATURES': "",
477 'HOMEPAGE': "http://www.gentoo.org/proj/en/releng/installer/",
478 'INHERITED': "eutils",
479 'KEYWORDS': arch,
480 'LICENSE': "",
481 'NEEDED': "",
482 'PDEPEND': "",
483 'PF': "livecd-kernel-1",
484 'PROVIDE': "virtual/alsa",
485 'RDEPEND': "",
486 'SLOT': "0",
487 'USE': arch
488 }
489 vdbdir = chroot_dir + "/var/db/pkg/sys-kernel/livecd-kernel-1"
490 os.mkdir(vdbdir)
491 for tmpfile in values:
492 fileout = open(vdbdir + "/" + tmpfile, "w")
493 fileout.write(values[tmpfile] + "\n")
494 fileout.close()
495 fileout = open(vdbdir + "/livecd-kernel-1.ebuild", "w")
496 fileout.write("inherit eutils\n\nDESCRIPTION=\"LiveCD kernel as installed by GLI\"\nHOMEPAGE=\"http://www.gentoo.org/proj/en/releng/installer/\"\nSRC_URI=\nLICENSE=\nSLOT=0\nKEYWORDS=\"%s\"\nIUSE=\nDEPEND=\nPROVIDE=virtual/alsa\n" % arch)
497 fileout.close()
498 print "wrote ebuild"
499 counter = gliportage.update_counter()
500 counter_f = open(vdbdir + "/COUNTER", "w")
501 counter_f.write(str(counter))
502 counter_f.close()
503 GLIUtility.spawn("echo | bzip2 > %s/environment.bz2" % vdbdir)
504 print "counter stuff done"
444 kernelpkg = gliportage.get_best_version_vdb("sys-kernel/livecd-kernel") 505 kernelpkg = gliportage.get_best_version_vdb_chroot("sys-kernel/livecd-kernel")
506# print "Copying "+kernelpkg+" to chroot environment"
445 gliportage.copy_pkg_to_chroot(kernelpkg) 507# gliportage.copy_pkg_to_chroot(kernelpkg)
508 print "Normally we would've copied the livecd-kernel via the GRP process, but now done a different way"
509 #20:05 <+agaffney> dberkholz: you can't do the kernel anymore, since it's not a binpkg
510 #20:05 <+agaffney> I got rid of that behavior
511 #20:05 <+agaffney> just copy the contents of /boot and /lib/modules
512 #20:05 <+agaffney> that's what the installer does
513
514 gliportage.add_pkg_to_world(kernelpkg)
515
516 try:
517 os.stat(chroot_dir + "/usr/src/linux")
518 except:
519 kernels = os.listdir(chroot_dir+"/usr/src")
520 found_a_kernel = False
521 counter = 0
522 while not found_a_kernel:
523 if (len(kernels[counter]) > 6) and (kernels[counter][0:6]=="linux-"):
524 exitstatus = GLIUtility.spawn("ln -s /usr/src/"+kernels[counter]+ " /usr/src/linux",chroot=chroot_dir)
525 if not GLIUtility.exitsuccess(exitstatus):
526 print "Error: Could not make a /usr/src/linux symlink"
527 sys.exit(1)
528 found_a_kernel = True
529 else :
530 counter = counter + 1
531 print "Kernel sources:"+kernel_pkg+" emerged and /usr/src/linux symlinked."
446 print "LiveCD kernel installed!" 532 print "LiveCD kernel installed!"
447 else: 533 else:
448 print "You must specify an operating mode (-g or -s)!" 534 print "You must specify an operating mode (-g or -s)!"
449 usage(progname) 535 usage(progname)
450 sys.exit(1) 536 sys.exit(1)

Legend:
Removed from v.1911  
changed lines
  Added in v.1912

  ViewVC Help
Powered by ViewVC 1.1.20