#!/usr/bin/python
#---------------------------------------------------------------
# Project         : pxemngr
# File            : syncbootnames
# Copyright       : 2009 Splitted-Desktop Systems
# Author          : Frederic Lepied
# Created On      : Sun Feb  1 19:17:33 2009
# Purpose         : read the pxe directory containing the profiles
#                   and add them to the database as available.
#---------------------------------------------------------------

import os
import settings
from pxe.models import *
from pxe.common import *

l = len(settings.PXE_SUFFIX)
list = []
for f in os.listdir(settings.PXE_ROOT + '/' + settings.PXE_PROFILES):
    if f[-l:] == settings.PXE_SUFFIX:
        list.append(f[:-l])

if 'local' not in list:
    print 'error local profile not present. Add it with a content like this:'
    print
    print '''prompt 0
timeout 0
default 0

label 0
  LOCALBOOT 0
'''

for b in BootName.objects.all():
    if b.available:
        b.available = False
        b.save()

for n in list:
    try:
        boot_name = BootName.objects.get(name=n)
        boot_name.available = True
    except BootName.DoesNotExist:
        boot_name = BootName(name=n, available=True)
    print 'registering', boot_name.name
    boot_name.save()
    
# syncbootnames ends here

