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): |