#!/usr/bin/python
import os,sys
import time
import re
def listPackages(listing):
packages_counter = -1
packages = []
for package in listing:
package = package.strip()
packages.append(package)
packages_counter += 1
return packages, packages_counter
# Create a packages blacklist. These packages won't be touched
blacklist = [ "portage", "eselect" ]
# Create the Live system packages list
put, get = os.popen4("find /var/db/pkg/ -maxdepth 2 | sed 's/\/var\/db\/pkg\///' | grep '/'")
listing = get.readlines()
live_packages, live_packages_counter = listPackages(listing)
del listing
# Debugging info
print live_packages_counter
time.sleep(4)
print live_packages[0]
print live_packages[1]
print live_packages[2]
print live_packages[live_packages_counter]
# Since Anaconda will use /mnt/gentoo as SL partition
# we need to check if that's a SL installation or at least
# there's /var/db/pkg
if not os.access("/mnt/gentoo/var/db/pkg",os.F_OK):
print "This is not Gentoo or Sabayon !"
sys.exit(1)
# otherwise collect installed packages
put, get = os.popen4("find /mnt/gentoo/var/db/pkg/ -maxdepth 2 | sed 's/\/mnt\/gentoo\/var\/db\/pkg\///' | grep '/'")
listing = get.readlines()
installed_packages, installed_packages_counter = listPackages(listing)
del listing
if not installed_packages_counter > 0:
print "This is not Gentoo or Sabayon !"
sys.exit(2)
print installed_packages_counter
time.sleep(4)
print installed_packages[0]
print installed_packages[1]
print installed_packages[2]
print installed_packages[installed_packages_counter]
# First of all, copy /etc/portage to the destination
os.system("rm -rf /mnt/gentoo/etc/portage && cp /etc/portage /mnt/gentoo/etc -Rp")
# Do we need to update the portage tree? Yes, we need portage tarfile from the DVD.
# Should the user select the path of it under Anaconda or force to use a DVD edition?
# Well, check if we have:
# a. an empty portage --> we need to fill that
# b. the portage db is available under /mnt/cdrom/snapshots/snapshot.tar.bz2
user_specified_path="/root/ciao.tar.bz2"
# Check if the tar file exists and start to update it
# There will be a file selector that let the user to specify a portage tarfile --> for the minis
#if os.access("/mnt/cdrom/snapshots/snapshot.tar.bz2",os.F_OK) or os.access("/mnt/cdrom/snapshots/snapshot.tar.bz2",os.F_OK):
# ok start to update the Portage tree.
# if os.access("/mnt/cdrom/snapshots/snapshot.tar.bz2",os.F_OK):
# os.system("rm -rf /mnt/gentoo/usr/portage/* && tar xjf /mnt/cdrom/snapshots/snapshot.tar.bz2 -C /mnt/gentoo/usr/")
# else:
# os.system("rm -rf /mnt/gentoo/usr/portage/* && tar xjf '"+user_specified_path+"' -C /mnt/gentoo/usr/")
# Portage is prepared now.
# Now, we have to create two containers:
# 1. to_be_removed = packages that will be removed
# 2. to_be_updated = packages that will be updated
to_be_removed = []
to_be_updated = []
for package in installed_packages:
# Compare each package with every package in live_packages
# but first, shrink down the package name, and remove the version number