From 60d683297150bd1a44bf63827a69925d83c5f429 Mon Sep 17 00:00:00 2001 From: Nikhil Jain Date: Fri, 19 Mar 2021 19:37:58 +0530 Subject: [PATCH] fix the large file parsing in project sync --- awx/main/utils/ansible.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/awx/main/utils/ansible.py b/awx/main/utils/ansible.py index 577aeb3fd6..ece2553151 100644 --- a/awx/main/utils/ansible.py +++ b/awx/main/utils/ansible.py @@ -6,7 +6,6 @@ import codecs import re import os import logging -from itertools import islice from configparser import ConfigParser # Django @@ -82,14 +81,20 @@ def could_be_inventory(project_path, dir_path, filename): # Filter files that do not use a character set consistent with # Ansible inventory mainly + matched = False try: # only read through first 10 lines for performance - with codecs.open(inventory_path, 'r', encoding='utf-8', errors='ignore') as inv_file: - for line in islice(inv_file, 10): - if not valid_inventory_re.match(line): - return None + with open(inventory_path, encoding='utf-8', errors='ignore') as inv_file: + for i, line in enumerate(inv_file): + if i > 10: + break + elif valid_inventory_re.match(line): + matched = True + break except IOError: return None + if not matched: + return None return inventory_rel_path