Permalink
Browse files

Update Python bindings to use the new config.xml format.

This creates a new DatabaseConfig class to manage access credentials for
the database, moving it out of DBCache.  DBCache (and MythDB) will still
continue to take the same arguments it did previously.  Both the old and
new format are supported, and old format files will be rewritten upon
successful connection to the database.  Files are now properly
pretty-printed when created.

This also converts everything over to absolute importing.

Fixes #10692.
  • Loading branch information...
wagnerrp committed May 7, 2012
1 parent 3cf139e commit a2f0333714242dbd8fb0f24c84f0d5dccbf3c4b4
@@ -1,5 +1,5 @@
-from logging import MythLog
-from exceptions import MythDBError
+from MythTV.logging import MythLog
+from MythTV.exceptions import MythDBError
from weakref import ref
@@ -16,11 +16,11 @@
def dbconnect(dbconn, log):
log(MythLog.DATABASE, MythLog.INFO,
'Spawning new database connection')
- db = MySQLdb.connect( user= dbconn['DBUserName'],
- host= dbconn['DBHostName'],
- passwd= dbconn['DBPassword'],
- db= dbconn['DBName'],
- port= dbconn['DBPort'],
+ db = MySQLdb.connect( user= dbconn.username,
+ host= dbconn.hostname,
+ passwd= dbconn.password,
+ db= dbconn.database,
+ port= dbconn.port,
use_unicode=True,
charset='utf8')
db.autocommit(True)
@@ -1,5 +1,5 @@
-from logging import MythLog
-from exceptions import MythDBError
+from MythTV.logging import MythLog
+from MythTV.exceptions import MythDBError
import os
@@ -16,11 +16,11 @@
def dbconnect(dbconn, log):
log(MythLog.DATABASE, MythLog.INFO,
'Spawning new database connection')
- db = oursql.connect( dbconn['DBHostName'],
- dbconn['DBUserName'],
- dbconn['DBPassword'],
- db= dbconn['DBName'],
- port= dbconn['DBPort'],
+ db = oursql.connect( dbconn.hostname,
+ dbconn.username,
+ dbconn.password,
+ db= dbconn.database,
+ port= dbconn.port,
use_unicode=True,
charset='utf8',
autoping=True,
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
"""Provides tweaked dict-type classes."""
-from exceptions import MythError
-from utility import datetime
+from MythTV.exceptions import MythError
+from MythTV.utility import datetime
from itertools import imap, izip
from datetime import date
@@ -1,12 +1,12 @@
# -*- coding: utf-8 -*-
"""Provides basic connection classes."""
-from static import SCHEMA_VERSION, PROTO_VERSION, PROTO_TOKEN, BACKEND_SEP
-from msearch import MSearch
-from logging import MythLog
-from exceptions import *
-from altdict import OrdDict
-from utility import deadlinesocket
+from MythTV.static import SCHEMA_VERSION, PROTO_VERSION, PROTO_TOKEN, BACKEND_SEP
+from MythTV.msearch import MSearch
+from MythTV.logging import MythLog
+from MythTV.exceptions import *
+from MythTV.altdict import OrdDict
+from MythTV.utility import deadlinesocket
from time import sleep, time
from select import select
@@ -120,8 +120,8 @@ def __init__(self, dbconn):
self.dbconn = dbconn
self._refs = {}
- self.log(MythLog.DATABASE, MythLog.INFO, "Attempting connection",
- '\n'.join(["'%s': '%s'" % (k,v) for k,v in dbconn.items()]))
+ self.log(MythLog.DATABASE, MythLog.INFO,
+ "Attempting connection: {0}".format(dbconn.ident))
try:
_Connection_Pool.__init__(self)
except:
@@ -611,17 +611,10 @@ def _request(self, path='', **keyvars):
def getConnectionInfo(self, pin=0):
"""Return dbconn dict from backend connection info."""
dbconn = {'SecurityPin':pin}
- conv = {'Host':'DBHostName', 'Port':'DBPort',
- 'UserName':'DBUserName','Password':'DBPassword',
- 'Name':'DBName'}
-
try:
- dat = self._request('Myth/GetConnectionInfo', Pin=pin).readJSON()
- for k,v in dat['ConnectionInfo']['Database'].items():
- if k in conv:
- dbconn[conv[k]] = v
+ dat = self._request('Myth/GetConnectionInfo', \
+ Pin='{0:0>4}'.format(pin)).readJSON()
+ return dat['ConnectionInfo']['Database']
except:
- raise
- pass
+ return {}
- return dbconn
Oops, something went wrong.

0 comments on commit a2f0333

Please sign in to comment.