# $SnapHashLicense:
#
# SnapLogic - Open source data services
#
# Copyright (C) 2008 - 2009, SnapLogic, Inc. All rights reserved.
#
# See http://www.snaplogic.org for more information about
# the SnapLogic project.
#
# This program is free software, distributed under the terms of
# the GNU General Public License Version 2. See the LEGAL file
# at the top of the source tree.
#
# "SnapLogic" is a trademark of SnapLogic, Inc.
#
#
# $
# $Id: ConnectionPostgreSQL.py 10330 2009-12-24 22:13:38Z grisha $
"""
PostgreSQL Connection component
"""
from snaplogic.common import version_info
from snaplogic.components.DBConnection import DBConnection
import snaplogic.cc.prop as prop
from snaplogic.snapi_base import keys
class ConnectionPostgreSQL(DBConnection):
"""
This class implements the PostgreSQL Connection component.
"""
api_version = '1.0'
component_version = '1.4'
component_description = "This component specifies PostgreSQL connection information."
component_label = "DB Connection - PostgreSQL"
component_doc_uri = "https://www.snaplogic.org/trac/wiki/Documentation/%s/ComponentRef/ConnectionPostgreSQL" % \
version_info.doc_uri_version
PG_ALLOWED_CHARSETS = ["UTF8", "BIG5", "EUC_CN", "EUC_JP", "EUC_KR", "EUC_TW",
"GB18030", "GBK", "ISO_8859_5", "ISO_8859_6", "ISO_8859_7", "ISO_8859_8", "JOHAB", "KOI8", "LATIN1",
"LATIN2", "LATIN3", "LATIN4", "LATIN5", "LATIN6", "LATIN7", "LATIN8", "LATIN9", "LATIN10", "MULE_INTERNAL",
"SJIS", "UHC", "WIN866", "WIN874", "WIN1250", "WIN1251", "WIN1252", "WIN1253", "WIN1254", "WIN1255",
"WIN1256", "WIN1257", "WIN1258"]
def _add_props_1_3(self):
self.set_property_def('db_charset',
prop.SimpleProp('Character set',
'string',
"""Character set to use. Changing this from the default value is discouraged,
because we ask PostgreSQL to handle it and return data in UTF-8. This is only provided for the case
when SQL_ASCII server encoding (which is discouraged by Postgres:
http://www.postgresql.org/docs/8.2/static/multibyte.html is used.""",
{ 'lov' : ConnectionPostgreSQL.PG_ALLOWED_CHARSETS },
True))
self.set_property_value('db_charset', 'UTF8')
self._set_cats()
def _add_props_1_1(self):
self.set_property_def('db_host',
prop.SimpleProp('Host',
"string",
"Hostname of PostgreSQL server",
None,
True))
self.set_property_def('db_database',
prop.SimpleProp('Database',
"string",
"PostgreSQL database",
None,
True))
self.set_property_value('db_database', 'postgres')
self.set_property_def('db_port',
prop.SimpleProp('Port',
"number",
"Port on which PostgreSQL is listening",
None,
True))
self.set_property_value('db_port', 5432)
def create_resource_template(self):
self._add_props_1_1()
self.set_property_def('db_user',
prop.SimpleProp('DB Username',
"string",
"PostgreSQL username",
None,
True))
self.set_property_def('db_password',
prop.SimpleProp('DB Password',
"string",
"Password",
{keys.CONSTRAINT_OBFUSCATE : 0}))
self._add_props_1_3()
def upgrade_1_0_to_1_1(self):
"""
Upgrade resource from version 1.0 to version 1.1:
1. Use host and database instead of DSN string as per ticket #1700
2. Add ability to specify port
"""
self._add_props_1_1()
dsn = self.get_property_value("db_dsn")
self.del_property_def("db_dsn")
comp_user = self.get_property_value('db_user')
comp_password = self.get_property_value('db_password')
port = None
host = None
base = None
if dsn is not None:
# This logic is the same as in the connect method of
# pgdb
params = dsn.split(':')
try:
host = params[0]
base = params[1]
user = params[2]
password = params[3]
opt = params[4]
tty = params[5]
except:
pass
if host:
self.set_property_value('db_host', host)
if base:
self.set_property_value('db_database', base)
if port:
self.set_property_value('db_port', port)
if not comp_user and user:
self.set_property_value("db_user", user)
if not comp_password and password:
self.set_property_value("db_password", password)
def upgrade_1_1_to_1_2(self):
"""
Upgrade resource from version 1.1 to version 1.2:
password property no longer required
"""
saved_password = self.get_property_value('db_password')
self.set_property_def('db_password',
prop.SimpleProp('DB Password',
"string",
"Password",
{keys.CONSTRAINT_OBFUSCATE : 0}))
self.set_property_value('db_password', saved_password)
def upgrade_1_2_to_1_3(self):
"""
Adds the charset property, and sets categories
"""
self._add_props_1_3()
def upgrade_1_3_to_1_4(self):
"""
No-op upgrade only to change component doc URI during the upgrade
which will be by cc_info before calling this method.
"""
pass
|