Skip to content

Commit

Permalink
cleaning up status and log statements
Browse files Browse the repository at this point in the history
  • Loading branch information
PhillipsOwen committed Nov 8, 2022
1 parent aba9a68 commit 9b3fd17
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/archiver/rule_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@ def sweep_action(self, rule: RuleUtils.Rule) -> bool:
ret_val: bool = True
failed_met_criteria: int = 0

# init the entity count
entity_count = 0

# check to see if execution params are populated
validated = self.rule_utils.validate_criteria_definition(rule)

Expand All @@ -249,9 +252,6 @@ def sweep_action(self, rule: RuleUtils.Rule) -> bool:
# get a list of the contents of the source directory
entities = os.listdir(rule.source)

# save the count
entity_count = len(entities)

# for each item found
for entity in entities:
# save the path to the entity
Expand All @@ -266,6 +266,9 @@ def sweep_action(self, rule: RuleUtils.Rule) -> bool:

# if this is a directory operation perform the action type
if rule.data_type == DataType.DIRECTORY and S_ISDIR(entity_details.st_mode):
# increment the count
entity_count += 1

# does the entity meet criteria
if self.rule_utils.meets_criteria(rule, entity_details):
if rule.action_type == ActionType.SWEEP_MOVE:
Expand All @@ -278,12 +281,17 @@ def sweep_action(self, rule: RuleUtils.Rule) -> bool:
# remove the directory
ret_val = self.rule_utils.remove_directory(rule, entity)
else:
self.logger.debug('Rule action %s for data type: %s. %s -> %s failed to meet criteria.', rule.action_type, rule.data_type,
rule.source, entity)
self.logger.debug('%s data action %s: Entity %s failed to meet criteria in %s.', rule.data_type.name, rule.action_type.name,
entity, rule.source)

# increment the failed criteria counter
failed_met_criteria += 1

# if this is a file operation perform the action type
elif rule.data_type == DataType.FILE and not S_ISDIR(entity_details.st_mode):
# increment the count
entity_count += 1

# does the entity meet criteria
if self.rule_utils.meets_criteria(rule, entity_details):
if rule.action_type == ActionType.SWEEP_MOVE:
Expand All @@ -296,12 +304,15 @@ def sweep_action(self, rule: RuleUtils.Rule) -> bool:
# remove the directory
ret_val = self.rule_utils.remove_file(rule, entity)
else:
self.logger.debug('Rule action %s for data type: %s: %s -> %s failed to meet criteria.', rule.action_type, rule.data_type,
rule.source, entity)
self.logger.debug('%s data action %s: Entity %s failed to meet criteria in %s.', rule.data_type.name, rule.action_type.name,
entity, rule.source)

# increment the failed criteria counter
failed_met_criteria += 1

# if there were any that failed report the details
if failed_met_criteria > 0:
self.logger.debug("Rule action %s for data type: %s. %s of %s entity(ies) failed to meet criteria.", rule.action_type, rule.data_type,
self.logger.debug("%s data action %s result: %s of %s entity(ies) failed to meet criteria.", rule.data_type.name, rule.action_type.name,
failed_met_criteria, entity_count)

# return to the caller
Expand Down

0 comments on commit 9b3fd17

Please sign in to comment.