import os
import sys
sys.path.append('../interface/')
sys.path.append('../new_partition/')
sys.path.append('/var/install')
import ri_data
import partition_data
import interface_partition
import ri_newt
import install_step_list

#list=['welcome','partition','raid','mountpoint','serialnumber','network','group','service','information']
list = install_step_list.list

init_partition_from_os_flag = True
init_flag = True
init_raid_from_os = True
count=0
while True :
	if init_raid_from_os:
		ri_data.Raid.init_from_os()
		init_raid_from_os = False
	if init_partition_from_os_flag:
		partition_data.Partition.init_from_os(unit='s')
		init_partition_from_os_flag = False
	if init_flag:
		ri_data.init()
		init_flag = False

	if list[count] == 'partition':
		s = interface_partition.main()

		if len(ri_newt.Raid.init_from_internal()) < 2 and len(ri_data.Raid.dict) == 0:
			if list[count+1] == 'raid':
				del list[count+1]
		else:
			if list[count+1] != 'raid':
				list.insert(count+1, 'raid')
	else:
		if list[count] == 'welcome':
			ri_newt.Welcome()
		elif list[count] == 'raid':
			ri_newt.Raid()
		elif list[count] == 'mountpoint':
			ri_newt.MountPoint()
		elif list[count] == 'serialnumber':
			ri_newt.SerialNumber()
		elif list[count] == 'network':
			ri_newt.Network()
		elif list[count] == 'group':
			ri_newt.Group()
		elif list[count] == 'service':
			ri_newt.Service()
		elif list[count] == 'finishstate':
			ri_newt.FinishState()
		elif list[count] == 'information':
			ri_newt.Prepar_installation()
		s = ri_newt.Screen.dict[list[count]].set_data()
        try:
	    if int(s) == 0: 
		    count = count + 1
	    else:
		    count = count - 1 
	except:
            pass

	if count < 0 or count > len(list) - 1:
		ri_newt.Screen.screen.finish()
		break

if s == 0:
	os.system("python ../interface/ri_install.py")
    

