#coding:utf-8

import os
import sys
import sunhpc
import textwrap
class Command(sunhpc.commands.report.command):
    """
    Output the kickstart scripts.
    
    <arg type='string' name='nodes'>
    Output compute node kickstart scripts.
    </arg>

    <example cmd='report kickstart'>
    Output the kickstart scripts.
    </example>

    <example cmd='report kickstart nodes'>
    Output the compute node kickstart scripts.
    </example>
    """
    def run(self, params, args):

        if args and args[0] == 'nodes':

            try:
                hostname = args[1]
            except KeyError:
                hostname = 'temporary-nodes'

            include_info = self.loadModules('kickstart', hostname)
            print ('\n'.join(include_info))

            phases = ['main', 'pre', 'post', 'packages', 'addons', 'anaconda']
            for phase in phases:
                kickstart = self.ks.getKickstart(phase)
                for kslist in kickstart:
                    for ks in kslist:
                        print (textwrap.dedent(ks))
        else:
            # Output control scripts
            self.ks.isFrontend = True
            include_info = self.loadModules('control')
            print ('\n'.join(include_info))

            phases = ['main', 'pre', 'post', 'packages']
            for phase in phases:
                kickstart = self.ks.getKickstart(phase)
                for kslist in kickstart:
                    for ks in kslist:
                        print (textwrap.dedent(ks))

        


RollName = "base"
