-
Notifications
You must be signed in to change notification settings - Fork 553
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c6c5f04
commit 2791a30
Showing
2 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import subprocess | ||
|
||
IGNORED = [ | ||
"OR", | ||
"REPLACE", | ||
"DEFAULT", | ||
"UNIQUE", | ||
"TRUSTED", | ||
"PROCEDURAL", | ||
"TEMP", | ||
"TEMPORARY", | ||
"UNLOGGED", | ||
"GLOBAL", | ||
"LOCAL", | ||
"CONSTRAINT", | ||
"RECURSIVE", | ||
"WORK", | ||
"TRANSACTION", | ||
"SESSION", | ||
] | ||
|
||
|
||
def try_man(page): | ||
try: | ||
subprocess.run( | ||
f"man -I 7 {page}", shell=True, check=True, universal_newlines=True | ||
Check warning Code scanning / CodeQL Unsafe shell command constructed from library input Medium
This f-string which depends on
library input Error loading related location Loading shell command Error loading related location Loading |
||
) | ||
return True | ||
except subprocess.CalledProcessError: | ||
return False | ||
|
||
|
||
def man(query): | ||
words = query.strip().split()[:6] | ||
words = map(lambda e: e.upper(), words) | ||
words = list(filter(lambda e: e not in IGNORED, words)) | ||
if not words: | ||
return True | ||
if words[0] == "RELEASE": | ||
words.insert(1, "SAVEPOINT") | ||
for i in [2, 1, 3, 4]: | ||
if try_man("_".join(words[0 : i + 1])): | ||
return True | ||
return False |