#coding:utf-8
import textwrap
class Modules(object):
    """
    base config module.
    """
    def __init__(self, command):
        self.cmd = command

    @property
    def __help__(self):
        info = """
        #==============================================================
        # %s
        #
        # module_path: %s
        # module_name: %s
        #==============================================================
        """ % (self.__doc__.strip(), self.__module__.strip(), self.__repr__())
        return info
        
    def run(self, args):

        addr = self.cmd.db.getHostAttr('localhost', 'Kickstart_PrivateAddress')
        base = self.cmd.db.getHostAttr('localhost', 'Kickstart_BaseDir')
        dist = self.cmd.db.getHostAttr('localhost', 'distribution')
        http = "http://%s/%s/%s/%s" % (addr, base, dist, self.cmd.arch)
        zone = self.cmd.db.getHostAttr('localhost', 'Kickstart_Timezone')
        
        main = ['#', '# sunhpc cluster system for kickstart', '#']
        main.append(self.__help__)

        # System authorization information
        main.append('auth --enableshadow --passalgo=sha512')

        # Use URL installation
        main.append('install')
        main.append('url --url %s' % http)

        # Use graphical install
        main.append('graphical')

        # # Keyboard layouts
        main.append("keyboard --vckeymap=us --xlayouts='us'")

        # System language
        main.append('lang en_US.UTF-8')

        main.append('eula --agreed')

        # Run the Setup Agent on first boot
        main.append('firstboot --disable')

        # System timezone
        main.append('timezone %s --isUtc --nontp' % zone)

        # X Window System configuration information
        # 请不要在不安装X windows系统中使用下面命令.
        # --startxonboot - 在安装的系统中使用图形界面登录
        # main.append('xconfig --startxonboot')

        # System services
        main.append("services --disabled='chronyd'")

        # Root password
        passwd  = '$6$6oVIU.5y$mAFN7begXFk5A1g0ODIQauIz6na5ja3AM0'
        passwd += 'QebWc8dLVHmLguPv65nVQbpYR3.w1h6HdfbUkFfhJkv/KNO2Sj3/'
        main.append('rootpw --iscrypted %s' % passwd)

        # Reboot install finished
        main.append('reboot')

        # Disk partitioning information
        main.append('%include /tmp/partition-info')

        self.cmd.ks.addMain(main)

    def __repr__(self):
        return "kickstart-base"
