LISTSERV mailing list manager LISTSERV 16.5

Help for QSERV-L Archives


QSERV-L Archives

QSERV-L Archives


QSERV-L@LISTSERV.SLAC.STANFORD.EDU


View:

Message:

[

First

|

Previous

|

Next

|

Last

]

By Topic:

[

First

|

Previous

|

Next

|

Last

]

By Author:

[

First

|

Previous

|

Next

|

Last

]

Font:

Proportional Font

LISTSERV Archives

LISTSERV Archives

QSERV-L Home

QSERV-L Home

QSERV-L  September 2015

QSERV-L September 2015

Subject:

Re: new use case for getEngineFrom

From:

"Salnikov, Andrei A." <[log in to unmask]>

Reply-To:

General discussion for qserv (LSST prototype baseline catalog)

Date:

Fri, 18 Sep 2015 16:47:41 +0000

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (1 lines)

Hi Jacek,

I'm not sure that we should support all possible use cases.
That method is a convenience method and it's not that complicated,
it should be possible to implement something similar in client
code which does something non-conventional. Still if you want to 
do it I would not use URL instance to pass overrides to the method,
URL class is not designed to provide only individual pieces, it's
supposed to be complete URL. I'd probably just pass a dictionary
with keywords:

def getEngineFromFile(fileName, overrides={}):
    ....

getEngineFromFile("myFile.ini", overrides=dict(database="mydb"))


or even better specify overrides as regular keyword parameters:

def getEngineFromFile(fileName,
                      drivername=None,
                      username=None,
                      password=None,
                      host=None,
                      port=None,
                      database=None,
                      query=None):
    ...


getEngineFromFile("myFile.ini", database="mydb")

Cheers,
Andy


Becla, Jacek wrote on 2015-09-17:
> 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/ur
> l .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

Top of Message | Previous Page | Permalink

Advanced Options


Options

Log In

Log In

Get Password

Get Password


Search Archives

Search Archives


Subscribe or Unsubscribe

Subscribe or Unsubscribe


Archives

March 2018
February 2018
January 2018
December 2017
August 2017
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
December 2013
November 2013
October 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
December 2012

ATOM RSS1 RSS2



LISTSERV.SLAC.STANFORD.EDU

Secured by F-Secure Anti-Virus CataList Email List Search Powered by the LISTSERV Email List Manager

Privacy Notice, Security Notice and Terms of Use