| Home | Trees | Indices | Help |
|
|---|
|
|
1 ############################################################################
2 # gmLoginInfo - a class to encapsulate Postgres login information
3 ############################################################################
4 # $Source: /home/ncq/Projekte/cvs2git/vcs-mirror/gnumed/gnumed/client/pycommon/gmLoginInfo.py,v $
5 # $Id: gmLoginInfo.py,v 1.17 2008-11-20 18:43:01 ncq Exp $
6 __version__ = "$Revision: 1.17 $"
7 __author__ = "H. Herb <hherb@gnumed.net>, I. Haywood <i.haywood@ugrad.unimelb.edu.au>"
8 __license__ = 'GPL v2 or later (details at http://www.gnu.org)'
9
10 import logging
11
12 _log = logging.getLogger('gm.db')
13 _log.info(__version__)
14 #====================================================================
16 """a class to encapsulate Postgres login information to default database"""
17
18 # private variables
19 # user = ''
20 # password = ''
21 # host = ''
22 # port = 5432
23 # database = ''
24 #------------------------------------------
26 self.user = user
27 self.password = password
28 self.host = host
29 self.port = port
30 self.database = database
31 #------------------------------------------
34
36 self.__port = int(value)
37
38 port = property(_get_port, _set_port)
39 #------------------------------------------
41 return (
42 self.GetUser(),
43 self.GetPassword(),
44 self.GetHost(),
45 self.GetPort(),
46 self.GetDatabase(),
47 self.GetProfile()
48 )
49 #------------------------------------------
51 # don't hand out passwords just like that
52 info = "host:port=%s:%s, db=%s, user=%s, pw=??" % (
53 self.GetHost(),
54 str(self.GetPort()),
55 self.GetDatabase(),
56 self.GetUser()
57 )
58 return info
59 #------------------------------------------
61 host = self.GetHost()
62 port = str(self.GetPort())
63 # for local UNIX domain sockets connections: leave host/port empty
64 # IH: *PLEASE* option of local TCP/IP connection must be available
65 # if host in ['', 'localhost']:
66 # host = ""
67 if host == '':
68 port = ''
69 dsn = "%s:%s:%s:%s" % (
70 host,
71 self.GetDatabase(),
72 self.GetUser(),
73 self.GetPassword()
74 )
75 host_port = "%s:%s" % (host, port)
76 return dsn, host_port
77 #------------------------------------------
79 dsn_parts = []
80
81 if self.database.strip() != '':
82 dsn_parts.append('dbname=%s' % self.database)
83
84 if self.host.strip() != '':
85 dsn_parts.append('host=%s' % self.host)
86
87 dsn_parts.append('port=%s' % self.port)
88
89 if self.user.strip() != '':
90 dsn_parts.append('user=%s' % self.user)
91
92 if self.password.strip() != '':
93 dsn_parts.append('password=%s' % self.password)
94
95 return ' '.join(dsn_parts)
96 #------------------------------------------
98 host = self.GetHost()
99 port = str(self.GetPort())
100 # for local UNIX domain sockets connections: leave host/port empty
101 # if host in ['', 'localhost']:
102 # host = ''
103 if host == '':
104 port = ''
105 dsn = "%s:%s:%s:%s:%s" % (
106 host,
107 port,
108 self.GetDatabase(),
109 self.GetUser(),
110 self.GetPassword()
111 )
112 return dsn
113 #------------------------------------------
116 #------------------------------------------
119 #------------------------------------------
122 #------------------------------------------
125 #------------------------------------------
128 #------------------------------------------
131 #------------------------------------------
133 try:
134 port = int (port)
135 except ValueError:
136 _log.warning("tried to set port to '%s', set to -1" % port)
137 port = -1
138 self.port = port
139 #------------------------------------------
141 return self.port
142 #------------------------------------------
145 #------------------------------------------
148 #------------------------------------------
150 "clears all connection information regarding user, password etc."
151
152 self.user = "guest"
153 self.password = ""
154 self.host = ''
155 self.port = 5432
156 self.database = "gnumed_v9"
157 self.__profile = 'default'
158
159 #====================================================================
160 if __name__ == "__main__" :
161 print "Please somebody write a module test function here!"
162
163 #====================================================================
164 # $Log: gmLoginInfo.py,v $
165 # Revision 1.17 2008-11-20 18:43:01 ncq
166 # - better logger name
167 #
168 # Revision 1.16 2008/01/07 19:49:12 ncq
169 # - bump db version
170 #
171 # Revision 1.15 2007/12/12 16:17:15 ncq
172 # - better logger names
173 #
174 # Revision 1.14 2007/12/11 14:30:44 ncq
175 # - std logging
176 #
177 # Revision 1.13 2007/10/22 12:37:59 ncq
178 # - default db change
179 #
180 # Revision 1.12 2007/06/11 20:23:45 ncq
181 # - bump database version
182 #
183 # Revision 1.11 2007/04/02 14:31:17 ncq
184 # - v5 -> v6
185 #
186 # Revision 1.10 2007/03/08 11:36:45 ncq
187 # - starting to simplify
188 #
189 # Revision 1.9 2007/02/06 12:08:39 ncq
190 # - upgrade to gnumed_v5
191 #
192 # Revision 1.8 2006/10/08 15:10:51 ncq
193 # - add comment on cBorg
194 #
195 # Revision 1.7 2006/09/21 19:46:38 ncq
196 # - attributes should really be .something, not .__something
197 # - change default to "gnumed_v3"
198 # - add get_psycopg2_dsn() but will go again
199 #
200 # Revision 1.6 2006/05/24 12:50:21 ncq
201 # - now only empty string '' means use local UNIX domain socket connections
202 #
203 # Revision 1.5 2006/02/26 18:33:00 ncq
204 # - change default to gnumed_v2
205 #
206 # Revision 1.4 2004/09/13 09:32:21 ncq
207 # - remove support for tty/backend opts, we never used them, they
208 # are only documented for old PostgreSQL versions, so axe them
209 #
210 # Revision 1.3 2004/07/17 20:54:50 ncq
211 # - remove user/_user workaround
212 #
213 # Revision 1.2 2004/04/21 14:27:15 ihaywood
214 # bug preventing backendlistener working on local socket connections
215 #
216 # Revision 1.1 2004/02/25 09:30:13 ncq
217 # - moved here from python-common
218 #
219 # Revision 1.17 2003/11/17 10:56:36 sjtan
220 #
221 # synced and commiting.
222 #
223 # Revision 1.1 2003/10/23 06:02:39 sjtan
224 #
225 # manual edit areas modelled after r.terry's specs.
226 #
227 # Revision 1.16 2003/09/17 11:15:39 ncq
228 # - make local TCP/IP available for all DBA types
229 #
230 # Revision 1.15 2003/09/17 03:00:59 ihaywood
231 # support for local inet connections
232 #
233 # Revision 1.14 2003/08/17 17:58:09 ncq
234 # - whitespace fix
235 #
236 # Revision 1.13 2003/06/26 02:31:23 ihaywood
237 # Fix for non-integer port values
238 #
239 # Revision 1.12 2003/06/16 09:52:04 ncq
240 # - really make local connections go via sockets
241 #
242 # Revision 1.11 2003/06/14 22:41:30 ncq
243 # - leave host/port blank for UNIX domain socket authentication data
244 #
245 # Revision 1.10 2003/05/17 17:26:37 ncq
246 # - start clean up of _user/user mess:
247 # - introduce __ro/rw_user
248 # - add "readonly" parameter to GetUser(), Get*_DSN() and SetUser()
249 # - make SetUser()/Get* smart about old style use, log warning
250 #
251 # Revision 1.9 2003/01/16 14:45:03 ncq
252 # - debianized
253 #
254 # Revision 1.8 2003/01/04 09:34:16 ncq
255 # - missing self. in GetDBAPI_DSN
256 #
257 # Revision 1.7 2003/01/04 09:05:17 ncq
258 # - added CVS tracking keywords
259 #
260
261
262 # old change log:
263 # 01.06.2001 hherb initial implementation
264 # 26.10.2001 hherb comments added
265 # 08.02.2001 hherb made DB API 2.0 compatible
266
| Home | Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1 on Mon Dec 5 03:59:55 2011 | http://epydoc.sourceforge.net |