imgserv has a new usecase, John is reading config file
(host/port/user/password), and adds database name.
While we could probably tweak imgserv to avoid that
(because he is only working with one database at the
moment), I do think it is a generic use case: there is
nothing wrong with defining host/port/credentials in
a file, and connecting to different databases using
the file + db name, right?
Our API does not support it now, and I want to avoid
disassembling / assembling URLs.
We now have
https://github.com/lsst/db/blob/tickets/DM-2299/python/lsst/db/engineFactory.py
How about tweaking getEngineFromFile as follows (pseudo, untested code):
def getEngineFromFile(fileName, urlExtras):
if fileName.startswith('~'):
fileName = os.path.expanduser(fileName)
parser = ConfigParser()
parser.readfp(open(fileName), fileName)
try:
options = dict(parser.items("database"))
except NoSectionError:
log.error("File %s does not contain section 'database'" % fileName)
raise
if urlExtras:
url = URL.make_url(options['url'])
if urlExtras.host:
url.host = urlExtras.host
if urlExtras.port:
url.port = urlExtras.port
if urlExtras.user:
url.user = urlExtras.user
if urlExtras.password:
url.password = urlExtras.password
if urlExtras.database:
url.database = urlExtras.database
options.url = url
return sqlalchemy.create_engine(options, "")
and then we could just call:
getEngineFromFile(
"myFile.ini",
URL(drivername="mysql+mysqldb", database = "mydb"))
(BTW, I don't like that we have to specify driver name here)
(docs for URL:
https://github.com/zzzeek/sqlalchemy/blob/master/lib/sqlalchemy/engine/url.py)
Thoughts?
Jacek
########################################################################
Use REPLY-ALL to reply to list
To unsubscribe from the QSERV-L list, click the following link:
https://listserv.slac.stanford.edu/cgi-bin/wa?SUBED1=QSERV-L&A=1
|