from installclass import BaseInstallClass
import rhpl
from rhpl.translate import N_,_
from constants import *
from flags import flags
import os
import iutil
import types
try:
    import instnum
except ImportError:
    instnum = None

import logging
log = logging.getLogger("anaconda")

class InstallClass(BaseInstallClass):
    id = "slf"
    name = N_("Scientific Linux Fermi")
    description = N_("The default installation of %s includes a set of "
                     "software applicable for general internet usage. "
                     "What additional tasks would you like your system "
                     "to include support for?") %(productName,)
    sortPriority = 10000
    showLoginChoice = 1
    allowExtraRepos = True
    hidden = 0

    taskMap = {'sites/fermi/sl' : [(N_("GNOME Desktop"), ["graphics", "office", "games", "sound-and-video","base-x","gnome-desktop","graphical-internet","printing"],),
                                   (N_("KDE Desktop"), ["graphics", "office", "games", "sound-and-video","base-x","kde-desktop","graphical-internet","printing"],),
                                   (N_("Office and Productivity"), ["graphics", "office", "games", "sound-and-video"]),
                                   (N_("Software Development"), ["development-libs", "development-tools", "gnome-software-development", "x-software-development"],),
                                   (N_("Virtualization"), ["virtualization"])],
               'sites/fermi/slf' : [(N_("Fermi"), ["Fermi"])]
             }

    def setInstallData(self, anaconda):
	BaseInstallClass.setInstallData(self, anaconda)
        BaseInstallClass.setDefaultPartitioning(self, anaconda.id.partitions,
                                                CLEARPART_TYPE_LINUX)

    def setGroupSelection(self, anaconda):
        grps = anaconda.backend.getDefaultGroups(anaconda)
        map(lambda x: anaconda.backend.selectGroup(x), grps)

    def setSteps(self, dispatch):
	BaseInstallClass.setSteps(self, dispatch);
	dispatch.skipStep("partition")
	dispatch.skipStep("regkey", skip = 1)        

    # for rhel, we're putting the metadata under productpath
    def getPackagePaths(self, uri):
        rc = {}
        for (name, path) in self.repopaths.items():
            if not type(uri) == types.ListType:
                uri = [uri,]
            if not type(path) == types.ListType:
                path = [path,]

            lst = []
            for i in uri:
                for p in path:
                    lst.append("%s/%s" % (i, p))

            rc[name] = lst

        log.info("package paths is %s" %(rc,))
        return rc





    def __init__(self, expert):
	BaseInstallClass.__init__(self, expert)

        log.info("Adding Base Path")
        self.repopaths = { "base": "%s" %(productPath,) }
	
        log.info("Adding Fermi Path")
        self.repopaths["fermi"] = "sites/Fermi/SLF"

        for repo in self.repopaths.values():
            if not self.taskMap.has_key(repo.lower()):
                continue

            for task in self.taskMap[repo.lower()]:
                if task not in self.tasks:
                    self.tasks.append(task)
        self.tasks.sort()

        log.info("repopaths is %s" %(self.repopaths,))
        #log.info("tasks are %s" %(self.tasks,))

