2017-03-16 09:27:55 -05:00
|
|
|
##########################################################################
|
|
|
|
#
|
|
|
|
# pgAdmin 4 - PostgreSQL Tools
|
|
|
|
#
|
2018-01-05 04:42:49 -06:00
|
|
|
# Copyright (C) 2013 - 2018, The pgAdmin Development Team
|
2017-03-16 09:27:55 -05:00
|
|
|
# This software is released under the PostgreSQL Licence
|
|
|
|
#
|
|
|
|
##########################################################################
|
2017-01-30 05:25:02 -06:00
|
|
|
from flask.templating import DispatchingJinjaLoader
|
|
|
|
from jinja2 import TemplateNotFound
|
|
|
|
|
|
|
|
|
|
|
|
class VersionedTemplateLoader(DispatchingJinjaLoader):
|
|
|
|
def get_source(self, environment, template):
|
2017-08-25 07:23:03 -05:00
|
|
|
template_path_parts = template.split("#", 3)
|
2017-01-30 05:25:02 -06:00
|
|
|
|
2017-08-25 07:23:03 -05:00
|
|
|
postgres_versions = (
|
2017-06-12 06:53:09 -05:00
|
|
|
{'name': "10_plus", 'number': 100000},
|
2017-01-30 05:25:02 -06:00
|
|
|
{'name': "9.6_plus", 'number': 90600},
|
|
|
|
{'name': "9.5_plus", 'number': 90500},
|
|
|
|
{'name': "9.4_plus", 'number': 90400},
|
|
|
|
{'name': "9.3_plus", 'number': 90300},
|
|
|
|
{'name': "9.2_plus", 'number': 90200},
|
2017-01-30 11:02:55 -06:00
|
|
|
{'name': "9.1_plus", 'number': 90100},
|
|
|
|
{'name': "9.0_plus", 'number': 90000},
|
2017-02-01 03:57:45 -06:00
|
|
|
{'name': "default", 'number': 0}
|
2017-01-30 05:25:02 -06:00
|
|
|
)
|
|
|
|
|
2017-08-25 07:23:03 -05:00
|
|
|
gpdb_versions = (
|
|
|
|
{'name': "gpdb_5.0_plus", 'number': 80323},
|
2018-01-23 04:41:36 -06:00
|
|
|
{'name': "5_plus", 'number': 80323},
|
2017-08-25 07:23:03 -05:00
|
|
|
{'name': "default", 'number': 0}
|
|
|
|
)
|
|
|
|
|
|
|
|
server_versions = postgres_versions
|
2017-01-30 05:25:02 -06:00
|
|
|
if len(template_path_parts) == 1:
|
2018-01-31 07:58:55 -06:00
|
|
|
return super(VersionedTemplateLoader, self).get_source(
|
|
|
|
environment, template
|
|
|
|
)
|
2017-08-25 07:23:03 -05:00
|
|
|
|
|
|
|
if len(template_path_parts) == 4:
|
2018-01-31 07:58:55 -06:00
|
|
|
path_start, server_type, specified_version_number, file_name = \
|
|
|
|
template_path_parts
|
2017-08-25 07:23:03 -05:00
|
|
|
if server_type == 'gpdb':
|
|
|
|
server_versions = gpdb_versions
|
2017-01-30 05:25:02 -06:00
|
|
|
else:
|
2018-01-31 07:58:55 -06:00
|
|
|
path_start, specified_version_number, file_name = \
|
|
|
|
template_path_parts
|
2017-08-25 07:23:03 -05:00
|
|
|
|
|
|
|
for server_version in server_versions:
|
|
|
|
if server_version['number'] > int(specified_version_number):
|
|
|
|
continue
|
|
|
|
|
2018-01-31 07:58:55 -06:00
|
|
|
template_path = path_start + '/' + \
|
|
|
|
server_version['name'] + '/' + file_name
|
2018-02-09 05:54:42 -06:00
|
|
|
|
2017-08-25 07:23:03 -05:00
|
|
|
try:
|
2018-01-31 07:58:55 -06:00
|
|
|
return super(VersionedTemplateLoader, self).get_source(
|
|
|
|
environment, template_path
|
|
|
|
)
|
2017-08-25 07:23:03 -05:00
|
|
|
except TemplateNotFound:
|
|
|
|
continue
|
|
|
|
raise TemplateNotFound(template)
|