142 self.dbport = port and int(port) or None |
142 self.dbport = port and int(port) or None |
143 self.dbuser = source_config.get('db-user') |
143 self.dbuser = source_config.get('db-user') |
144 self.dbpasswd = source_config.get('db-password') |
144 self.dbpasswd = source_config.get('db-password') |
145 self.encoding = source_config.get('db-encoding', 'UTF-8') |
145 self.encoding = source_config.get('db-encoding', 'UTF-8') |
146 self.dbapi_module = db.get_dbapi_compliant_module(self.dbdriver) |
146 self.dbapi_module = db.get_dbapi_compliant_module(self.dbdriver) |
|
147 self.dbdriver_extra_args = source_config.get('db-extra-arguments') |
147 self.binary = self.dbapi_module.Binary |
148 self.binary = self.dbapi_module.Binary |
148 self.dbhelper = self.dbapi_module.adv_func_helper |
149 self.dbhelper = self.dbapi_module.adv_func_helper |
149 self.sqlgen = SQLGenerator() |
150 self.sqlgen = SQLGenerator() |
150 |
151 |
151 def get_connection(self, user=None, password=None): |
152 def get_connection(self, user=None, password=None): |
154 self.info('connecting to %s@%s for user %s', self.dbname, |
155 self.info('connecting to %s@%s for user %s', self.dbname, |
155 self.dbhost or 'localhost', user or self.dbuser) |
156 self.dbhost or 'localhost', user or self.dbuser) |
156 else: |
157 else: |
157 self.info('connecting to %s@%s', self.dbname, |
158 self.info('connecting to %s@%s', self.dbname, |
158 self.dbhost or 'localhost') |
159 self.dbhost or 'localhost') |
|
160 extra = {} |
|
161 if self.dbdriver_extra_args: |
|
162 extra = {'extra_args': self.dbdriver_extra_args} |
159 cnx = self.dbapi_module.connect(self.dbhost, self.dbname, |
163 cnx = self.dbapi_module.connect(self.dbhost, self.dbname, |
160 user or self.dbuser, |
164 user or self.dbuser, |
161 password or self.dbpasswd, |
165 password or self.dbpasswd, |
162 port=self.dbport) |
166 port=self.dbport, |
|
167 **extra) |
163 init_cnx(self.dbdriver, cnx) |
168 init_cnx(self.dbdriver, cnx) |
164 #self.dbapi_module.type_code_test(cnx.cursor()) |
169 #self.dbapi_module.type_code_test(cnx.cursor()) |
165 return cnx |
170 return cnx |
166 |
171 |
167 def backup_to_file(self, backupfile): |
172 def backup_to_file(self, backupfile): |
176 self.dbuser, backupfile, |
181 self.dbuser, backupfile, |
177 self.encoding, |
182 self.encoding, |
178 keepownership=False, |
183 keepownership=False, |
179 drop=drop): |
184 drop=drop): |
180 if os.system(cmd): |
185 if os.system(cmd): |
181 raise Exception('Failed command: %s' % cmd) |
186 print '-> Failed command: %s' % cmd |
|
187 if not confirm('Continue anyway?', default='n'): |
|
188 raise Exception('Failed command: %s' % cmd) |
182 |
189 |
183 def merge_args(self, args, query_args): |
190 def merge_args(self, args, query_args): |
184 if args is not None: |
191 if args is not None: |
185 args = dict(args) |
192 args = dict(args) |
186 for key, val in args.items(): |
193 for key, val in args.items(): |
239 # from a query result and so it is already encrypted |
246 # from a query result and so it is already encrypted |
240 if isinstance(value, Binary): |
247 if isinstance(value, Binary): |
241 value = value.getvalue() |
248 value = value.getvalue() |
242 else: |
249 else: |
243 value = crypt_password(value) |
250 value = crypt_password(value) |
|
251 value = self.binary(value) |
244 # XXX needed for sqlite but I don't think it is for other backends |
252 # XXX needed for sqlite but I don't think it is for other backends |
245 elif atype == 'Datetime' and isinstance(value, date): |
253 elif atype == 'Datetime' and isinstance(value, date): |
246 value = todatetime(value) |
254 value = todatetime(value) |
247 elif atype == 'Date' and isinstance(value, datetime): |
255 elif atype == 'Date' and isinstance(value, datetime): |
248 value = todate(value) |
256 value = todate(value) |