mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
inputs. In order to do the proper quoting around the identifier, different type, and literal, we introduced respective functions qtIdent, qtTypeIdent, qtLiteral in psycopg2 driver. Also, introduced them as the Jinja's custom filter for using it directly inside the templates. Also, created an utility - generate_keywords.py in order to generate keyword lists from the latest PostgreSQL installation.
62 lines
2.0 KiB
Python
62 lines
2.0 KiB
Python
##########################################################################
|
|
#
|
|
# pgAdmin 4 - PostgreSQL Tools
|
|
#
|
|
# Copyright (C) 2013 - 2015, The pgAdmin Development Team
|
|
# This software is released under the PostgreSQL Licence
|
|
#
|
|
# This allows us to generate to keywords.py for PostgreSQL for used by
|
|
# qtIdent and qtTypeIdent functions for scanning the keywords type.
|
|
#
|
|
# In order to generate keywords.py for specific version of PostgreSQL, put
|
|
# pg_config executable in the PATH.
|
|
#
|
|
##########################################################################
|
|
import re
|
|
import os
|
|
|
|
if __name__ == '__main__':
|
|
include_dir = os.popen('pg_config --includedir').read().rstrip()
|
|
version = os.popen('pg_config --version').read().rstrip()
|
|
|
|
keywords_file = open('keywords.py', 'w')
|
|
|
|
keywords_file.write("""##########################################################################
|
|
#
|
|
# pgAdmin 4 - PostgreSQL Tools
|
|
#
|
|
# Copyright (C) 2013 - 2015, The pgAdmin Development Team
|
|
# This software is released under the PostgreSQL Licence
|
|
#
|
|
##########################################################################
|
|
""")
|
|
keywords_file.write('# ScanKeyword function for ' + version)
|
|
keywords_file.write('\n\ndef ScanKeyword(key):')
|
|
keywords_file.write('\n keywordDict = {\n')
|
|
|
|
idx = 0
|
|
|
|
with open(include_dir + "/postgresql/server/parser/kwlist.h", "rb") as ins:
|
|
|
|
pattern = re.compile(r'"([^"]+)",\s*[^,]*\s*,\s*(.*)$')
|
|
keyword_types = [
|
|
u'UNRESERVED_KEYWORD', u'COL_NAME_KEYWORD',
|
|
u'TYPE_FUNC_NAME_KEYWORD', u'RESERVED_KEYWORD'
|
|
]
|
|
|
|
for line in ins:
|
|
line = line.decode().rstrip()
|
|
if line[0:11] == 'PG_KEYWORD(' and line[-1] == ')':
|
|
match = pattern.match(line[11:-1])
|
|
if idx != 0:
|
|
keywords_file.write(", ")
|
|
else:
|
|
keywords_file.write(" ")
|
|
keywords_file.write(
|
|
'"' + match.group(1) + u'": ' +
|
|
str(keyword_types.index(match.group(2)))
|
|
)
|
|
idx += 1
|
|
keywords_file.write('\n }\n')
|
|
keywords_file.write(' return (key in keywordDict and keywordDict[key]) or None')
|