Skip to content

Commit

Permalink
Fixing word finder with regular expresions
Browse files Browse the repository at this point in the history
  • Loading branch information
wilo087 committed Aug 5, 2021
1 parent a80f6ea commit f6bda12
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
19 changes: 9 additions & 10 deletions cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,23 +297,22 @@ def migrate(dry_run, force, name=None, types=None):
group = list(filter(lambda d: d['name'] in [name], group))

# For each script in group
for item in group:
for item in group:

if item['type'] == 'UNKNOW':
item['status'] == 'NOT EXCUTED'
infoScript.add_row([item['name'], groupID, item['type'], item['status'], item['output']])
continue

# Before excute the script, we have to checkout if special keywords exist
if not force:
wordInScripts = files.checkWordsInFile(wordList=disallowed_keywords, path=item['path'])
if wordInScripts:
item['output'] = "Please, user -f flag or remove the following DDL instructions: %s " % ', '.join(wordInScripts)
item['status'] = 'BLOCKED'

failedGroups.append(groupID)
infoScript.add_row([item['name'], groupID, item['type'], item['status'], item['output']])
continue
wordInScripts = files.checkWordsInFile(wordList=disallowed_keywords, path=item['path'])
if wordInScripts and not force:
item['output'] = "Please, user -f flag or remove the following DDL instructions: %s " % ', '.join(wordInScripts)
item['status'] = 'BLOCKED'

failedGroups.append(groupID)
infoScript.add_row([item['name'], groupID, item['type'], item['status'], item['output']])
continue

# Is the object group exist on failed group, avoid it.
if groupID in failedGroups and not force:
Expand Down
8 changes: 5 additions & 3 deletions pladmin/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,11 +384,13 @@ def checkWordsInFile(self, wordList, path):
wordScripts = []
fContent = open(path, 'r')
content = str(fContent.read())


for word in wordList:
lowers = content.count(word.lower())
uppers = content.count(word.upper())
if lowers + uppers:
my_regex = r"\b(" + word + r")\b"
matchWord = re.search(my_regex, content, re.I)

if matchWord:
wordScripts.append(word)

fContent.close()
Expand Down

0 comments on commit f6bda12

Please sign in to comment.