buildframework/helium/tools/common/python/lib/archive/mappers.py
changeset 179 d8ac696cc51f
parent 1 be27ed110b50
equal deleted inserted replaced
1:be27ed110b50 179:d8ac696cc51f
    22 
    22 
    23 """
    23 """
    24 
    24 
    25 import buildtools
    25 import buildtools
    26 import os
    26 import os
    27 import sys
       
    28 import codecs
    27 import codecs
    29 import fileutils
    28 import fileutils
    30 import logging
    29 import logging
    31 import symrec
    30 import symrec
    32 import re
    31 import re
   286                 elif os.path.exists(os.path.join(dirname, name)): 
   285                 elif os.path.exists(os.path.join(dirname, name)): 
   287                     policyfile = os.path.join(dirname, name)
   286                     policyfile = os.path.join(dirname, name)
   288                     break
   287                     break
   289             
   288             
   290             value = self._config.get('policy.default.value', MISSING_POLICY)
   289             value = self._config.get('policy.default.value', MISSING_POLICY)
   291             if policyfile != None:
   290             if policyfile != None:      #policy file present
   292                 try:
   291                 try:
   293                     value = fileutils.read_policy_content(policyfile)
   292                     value = fileutils.read_policy_content(policyfile)
   294                     if value not in self._binary.keys():
   293                     if value not in self._binary.keys():    #check policy file is valid
   295                         _logger.error("POLICY_ERROR: policy file found %s but policy %s value not exists in csv" % (policyfile, value))
   294                         _logger.error("POLICY_ERROR: policy file found %s but policy %s value not exists in csv" % (policyfile, value))
   296                 except Exception, exc:
   295                 except Exception, exc:
   297                     _logger.error("POLICY_ERROR: %s" % exc)         
   296                     _logger.error("POLICY_ERROR: %s" % exc)         
   298                     value = self._config.get('policy.default.value', MISSING_POLICY)
   297                     value = self._config.get('policy.default.value', MISSING_POLICY)
   299             else:
   298             else:       #no policy file present
   300                 _logger.error("POLICY_ERROR: could not find a policy file under: '%s'" % dirname)
   299                 filePresent = False
       
   300                 dirPresent = False
       
   301                 for ftype in os.listdir(dirname):   #see if files or directories are present
       
   302                     if os.path.isdir(os.path.join(dirname, ftype)):
       
   303                         dirPresent = True
       
   304                     if os.path.isfile(os.path.join(dirname, ftype)):
       
   305                         filePresent = True
       
   306                         
       
   307                 if filePresent:    #files present : error     
       
   308                     _logger.error("POLICY_ERROR: could not find a policy file under: '%s'" % dirname)
       
   309                 elif dirPresent and not filePresent:  #directories only : warning
       
   310                     _logger.error("POLICY_WARNING: no policy file, no files present, but sub-folder present in : '%s'" % dirname)
       
   311                 else:       #no files no dirs : warning
       
   312                     _logger.error("POLICY_WARNING: empty directory at : '%s'" % dirname)
       
   313                 
   301             # saving the policy value for that directory.
   314             # saving the policy value for that directory.
   302             self._policy_cache[dirname] = value
   315             self._policy_cache[dirname] = value
   303         return self._policy_cache[dirname]
   316         return self._policy_cache[dirname]
   304         
   317         
   305     def get_policy_filenames(self):
   318     def get_policy_filenames(self):