# Path: k_os/OIL/Parser.py
# class NestedParameter(NameMappedDict):
#     def __init__(self, name, value, parent):
#         self.name = name
#         self.value = value
#         self.parent = parent
#         self.type_ = name
#         self.parameters = dict()
# 
#         keys = ImplDefMap.keys()
# 
#         if name == 'ACTION' and value == 'ACTIVATETASK' or name == 'DIRECTION':
#             pass
# 
#         (self.root, self.path) = GetParameterPathToRootObject(self, name)
# 
#         if self.root.type_ not in keys:
#             pass
# 
#         defMap = parent.implDef
#         if isinstance(defMap, ImplSpec):
#             try:
#                 self.implDef =  defMap.defs[name]
#             except:
#                 self.implDef = None
#         else:
#             self.implDef = filter(lambda x: x[1].name == name , defMap.valueRange.get(parent.value))
#             try:
#                 self.implDef = self.implDef[0][1]
#             except:
#                 di = defMap.valueRange._dict.items()
#                 self.implDef = None
# 
#         if not self.implDef is None:
#             if self.implDef.attrType == 'BOOLEAN':
#                 v = self.implDef.valueRange.get(value)
#             elif self.implDef.attrType == 'ENUM':
#                 """
#                 for v in self.implDef.valueRange.getValues():
#                     print v
#                 """
#             else:
#                 pass    # TODO: ErrorHandling!!!
#         # self.implDef = GetParameterDefinition(self.root, name, self.path)
# 
#     def AddParameter(self, name, value):
#         if self.implDef is None:
#             return
#         if self.implDef.multiple_specifier == True:
#             self.setdefault(name, []).append(value)
#         else:
#             self[name] = value
# 
#     def __repr__(self):
#         return "%s (type: '%s' name: '%s' value: '%s')\n" % (self.__class__, self.type_, self.name, self.value)
# 
#     def __setitem__(self, name, value):
#         self.parameters[name] = value
#         super(NestedParameter, self).__setitem__(name, value)
#         #print self[name]
# 
# Path: k_os/OIL/Error.py
# class OILError(object):
#     inst=None
# 
#     def __new__(cls):
#         if cls.inst is None:
#             # Make it a Singleton.
#             cls.inst=super(OILError,cls).__new__(cls)
#             cls.fatalErrorCounter=0
#             cls.errorCounter=0
#             cls.warningCounter=0
#             cls.informationCounter=0
# 
#             cls.loggerMessageonly=createLogger(logging.NOTSET,"kos.oil.logger.messageonly",
#                 "[%(levelname)s] - %(message)s"
#             )
#             cls.loggerFilename=createLogger(logging.NOTSET,"kos.oil.logger.filename",
#                 "[%(levelname)s]:%(fname)s - %(message)s"
#             )
#             cls.loggerFull=createLogger(logging.NOTSET,"kos.oil.logger.full",
#                  "[%(levelname)s]:%(fname)s:%(lno)s - %(message)s"
#             )
#         return cls.inst
# 
#     def logMessage(self,level,message,lineno=None,filename=None,code=None):
#         if lineno and filename:
#             self.loggerFull.log(level,message,extra={'lno': lineno,'fname': filename})
#         elif filename:
#             self.loggerFilename.log(level,message,extra={'fname': filename})
#         else:
#             self.loggerMessageonly.log(level,message)
# 
# 
#     def fatalError(self,message,lineno=None,filename=None,code=''):
#         self.logMessage(logging.CRITICAL,message,lineno,filename,"F-"+code)
#         self.fatalErrorCounter+=1
#         sys.exit(1)
# 
#     def error(self,message,lineno=None,filename=None,code=''):
#         self.logMessage(logging.ERROR,message,lineno,filename,"E-"+code)
#         self.errorCounter+=1
# 
#     def warning(self,message,lineno=None,filename=None,code=''):
#         self.logMessage(logging.WARNING,message,lineno,filename,"W-"+code)
#         self.warningCounter+=1
# 
#     def information(self,message,lineno=None,filename=None,code=''):
#         self.logMessage(logging.INFO,message,lineno,filename,"I-"+code)
#         self.informationCounter+=1


from collections import namedtuple
from Cheetah.Template import Template
from k_os.OIL.Parser import NestedParameter
from k_os.OIL.Error import OILError
import codecs
import os
import stat
import string
import sys
import time
import inspect
import types
import k_os.OIL.ORTICfg
        return '|'.join(map(lambda x: x.value, obj['AUTOSTART']['APPMODE']))
    else:
        return obj['AUTOSTART']['APPMODE'].value


osVars = {
    'lastError': 'OsLastError',
    'serviceID': 'Os_ServiceContext.id',
    'appMode': 'Os_AppMode',
    'isrID': '(uint8)OsCurrentISRID',
    'runningTask': '(uint8)OsCurrentTID',
    'callevel': 'OsCallevel',
    'runningTaskPriority': 'OsCurrentTCB->CurrentPriority',
    }


Register = namedtuple('Register', 'name type offset')
Stack = namedtuple('Stack', 'direction fillpattern')

# all((isinstance(x,types.StringTypes) for x in l))


def Generate(fname, AppDef, Info):
    global errObj
    global app
    global info
    print
    print 'Creating Configuration Files...'
    print


# Path: k_os/OIL/Parser.py
# class NestedParameter(NameMappedDict):
#     def __init__(self, name, value, parent):
#         self.name = name
#         self.value = value
#         self.parent = parent
#         self.type_ = name
#         self.parameters = dict()
# 
#         keys = ImplDefMap.keys()
# 
#         if name == 'ACTION' and value == 'ACTIVATETASK' or name == 'DIRECTION':
#             pass
# 
#         (self.root, self.path) = GetParameterPathToRootObject(self, name)
# 
#         if self.root.type_ not in keys:
#             pass
# 
#         defMap = parent.implDef
#         if isinstance(defMap, ImplSpec):
#             try:
#                 self.implDef =  defMap.defs[name]
#             except:
#                 self.implDef = None
#         else:
#             self.implDef = filter(lambda x: x[1].name == name , defMap.valueRange.get(parent.value))
#             try:
#                 self.implDef = self.implDef[0][1]
#             except:
#                 di = defMap.valueRange._dict.items()
#                 self.implDef = None
# 
#         if not self.implDef is None:
#             if self.implDef.attrType == 'BOOLEAN':
#                 v = self.implDef.valueRange.get(value)
#             elif self.implDef.attrType == 'ENUM':
#                 """
#                 for v in self.implDef.valueRange.getValues():
#                     print v
#                 """
#             else:
#                 pass    # TODO: ErrorHandling!!!
#         # self.implDef = GetParameterDefinition(self.root, name, self.path)
# 
#     def AddParameter(self, name, value):
#         if self.implDef is None:
#             return
#         if self.implDef.multiple_specifier == True:
#             self.setdefault(name, []).append(value)
#         else:
#             self[name] = value
# 
#     def __repr__(self):
#         return "%s (type: '%s' name: '%s' value: '%s')\n" % (self.__class__, self.type_, self.name, self.value)
# 
#     def __setitem__(self, name, value):
#         self.parameters[name] = value
#         super(NestedParameter, self).__setitem__(name, value)
#         #print self[name]
# 
# Path: k_os/OIL/Error.py
# class OILError(object):
#     inst=None
# 
#     def __new__(cls):
#         if cls.inst is None:
#             # Make it a Singleton.
#             cls.inst=super(OILError,cls).__new__(cls)
#             cls.fatalErrorCounter=0
#             cls.errorCounter=0
#             cls.warningCounter=0
#             cls.informationCounter=0
# 
#             cls.loggerMessageonly=createLogger(logging.NOTSET,"kos.oil.logger.messageonly",
#                 "[%(levelname)s] - %(message)s"
#             )
#             cls.loggerFilename=createLogger(logging.NOTSET,"kos.oil.logger.filename",
#                 "[%(levelname)s]:%(fname)s - %(message)s"
#             )
#             cls.loggerFull=createLogger(logging.NOTSET,"kos.oil.logger.full",
#                  "[%(levelname)s]:%(fname)s:%(lno)s - %(message)s"
#             )
#         return cls.inst
# 
#     def logMessage(self,level,message,lineno=None,filename=None,code=None):
#         if lineno and filename:
#             self.loggerFull.log(level,message,extra={'lno': lineno,'fname': filename})
#         elif filename:
#             self.loggerFilename.log(level,message,extra={'fname': filename})
#         else:
#             self.loggerMessageonly.log(level,message)
# 
# 
#     def fatalError(self,message,lineno=None,filename=None,code=''):
#         self.logMessage(logging.CRITICAL,message,lineno,filename,"F-"+code)
#         self.fatalErrorCounter+=1
#         sys.exit(1)
# 
#     def error(self,message,lineno=None,filename=None,code=''):
#         self.logMessage(logging.ERROR,message,lineno,filename,"E-"+code)
#         self.errorCounter+=1
# 
#     def warning(self,message,lineno=None,filename=None,code=''):
#         self.logMessage(logging.WARNING,message,lineno,filename,"W-"+code)
#         self.warningCounter+=1
# 
#     def information(self,message,lineno=None,filename=None,code=''):
#         self.logMessage(logging.INFO,message,lineno,filename,"I-"+code)
#         self.informationCounter+=1


# Path: k_os/OIL/GenCfg.py
from collections import namedtuple
from Cheetah.Template import Template
from k_os.OIL.Parser import NestedParameter
from k_os.OIL.Error import OILError
import codecs
import os
import stat
import string
import sys
import time
import inspect
import types
import k_os.OIL.ORTICfg

        return '|'.join(map(lambda x: x.value, obj['AUTOSTART']['APPMODE']))
    else:
        return obj['AUTOSTART']['APPMODE'].value


osVars = {
    'lastError': 'OsLastError',
    'serviceID': 'Os_ServiceContext.id',
    'appMode': 'Os_AppMode',
    'isrID': '(uint8)OsCurrentISRID',
    'runningTask': '(uint8)OsCurrentTID',
    'callevel': 'OsCallevel',
    'runningTaskPriority': 'OsCurrentTCB->CurrentPriority',
    }


Register = namedtuple('Register', 'name type offset')
Stack = namedtuple('Stack', 'direction fillpattern')

# all((isinstance(x,types.StringTypes) for x in l))


def Generate(fname, AppDef, Info):
    global errObj
    global app
    global info
    print
    print 'Creating Configuration Files...'
    print


    errObj = OILError()