473,406 Members | 2,847 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Driver selection

The pyspf package [http://cheeseshop.python.org/pypi/pyspf/] can use
either pydns, or dnspython. The pyspf module has a simple driver
function, DNSLookup(), that defaults to the pydns version. It can be
assigned to a dnspython version, or to a test driver for in memory DNS.
Or you can modify the source to "from drivermodule import DNSLookup".

What is the friendliest way to make this configurable? Currently, users
are modifying the source to supply the desired driver. Yuck. I would
like to supply several drivers, and have a simple way to select one at
installation or run time.

--
Stuart D. Gathman <st****@bmsi.com>
Business Management Systems Inc. Phone: 703 591-0911 Fax: 703 591-6154
"Confutatis maledictis, flamis acribus addictis" - background song for
a Microsoft sponsored "Where do you want to go from here?" commercial.

Dec 9 '06 #1
5 1522
On 9 dic, 00:53, "Stuart D. Gathman" <stu...@bmsi.comwrote:
The pyspf package [http://cheeseshop.python.org/pypi/pyspf/] can use
either pydns, or dnspython. The pyspf module has a simple driver
function, DNSLookup(), that defaults to the pydns version. It can be
assigned to a dnspython version, or to a test driver for in memory DNS.
Or you can modify the source to "from drivermodule import DNSLookup".

What is the friendliest way to make this configurable? Currently, users
are modifying the source to supply the desired driver. Yuck. I would
like to supply several drivers, and have a simple way to select one at
installation or run time.
You can store the user's choice in a configuration file (like the ones
supported by ConfigParser).
Then you can put all the logic to select and import the right function
in a separate module, and export the DNSLookup name; make all the other
parts of the application say "from mymodule import DNSLookup"

--
Gabriel Genellina

Dec 9 '06 #2
On Fri, 08 Dec 2006 21:35:41 -0800, Gabriel Genellina wrote:
On 9 dic, 00:53, "Stuart D. Gathman" <stu...@bmsi.comwrote:
>Or you can modify the source to "from drivermodule import DNSLookup".

What is the friendliest way to make this configurable? Currently, users
are modifying the source to supply the desired driver. Yuck. I would
like to supply several drivers, and have a simple way to select one at
installation or run time.

You can store the user's choice in a configuration file (like the ones
supported by ConfigParser).
Then you can put all the logic to select and import the right function
in a separate module, and export the DNSLookup name; make all the other
parts of the application say "from mymodule import DNSLookup"
pyspf is a library, not an application. It would be nasty to make it have
a config file. We already have "from pydns_driver import DNSLookup" in
the pyspf module. If only users could import *for* a module from
*outside* the module. I suppose you can do something like this:

app.py:

import spf
# select dnspython driver for spf module
from spf.dnspython_driver import DNSLookup
spf.DNSLookup = DNSLookup
del DNSLookup

....

That is ugly. I'm looking for better ideas. Is there a clean way to make
a setdriver function? Used like this, say:

app.py:

import spf
spf.set_driver('dnspython')
....

Can a function replace itself? For instance, in spf.py, could DNSLookup
do this to provide a default:

def set_driver(d):
if d == 'pydns':
from pydns_driver import DNSLookup
elif d == 'dnspython':
from dnspython_driver import DNSLookup
else: raise Exception('Unknown DNS driver')

def DNSLookup(name,t):
from pydns_driver import DNSLookup
return DNSLookup(name,t)

--
Stuart D. Gathman <st****@bmsi.com>
Business Management Systems Inc. Phone: 703 591-0911 Fax: 703 591-6154
"Confutatis maledictis, flamis acribus addictis" - background song for
a Microsoft sponsored "Where do you want to go from here?" commercial.

Dec 9 '06 #3
At Saturday 9/12/2006 13:15, Stuart D. Gathman wrote:
>app.py:

import spf
spf.set_driver('dnspython')
...

Can a function replace itself? For instance, in spf.py, could DNSLookup
do this to provide a default:

def set_driver(d):
if d == 'pydns':
from pydns_driver import DNSLookup
elif d == 'dnspython':
from dnspython_driver import DNSLookup
else: raise Exception('Unknown DNS driver')

def DNSLookup(name,t):
from pydns_driver import DNSLookup
return DNSLookup(name,t)
The above code *almost* works, but DNSLookup is a local name inside
the function. Use the global statement.
As an example, see how getpass.py (in the standard library) manages
the various getpass implementations.
--
Gabriel Genellina
Softlab SRL

__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ˇgratis!
ˇAbrí tu cuenta ya! - http://correo.yahoo.com.ar
Dec 11 '06 #4
On Mon, 11 Dec 2006 20:59:27 -0300, Gabriel Genellina wrote:
The above code *almost* works, but DNSLookup is a local name inside
the function. Use the global statement.
As an example, see how getpass.py (in the standard library) manages
the various getpass implementations.
Ok, I have a working package:

spf/
__init__.py
pyspf.py
pydns.py
dnspython.py

__init__.py:
from pyspf import *
from pyspf import __author__,__email__,__version__

def set_dns_driver(f):
global DNSLookup
DNSLookup = f
pyspf.DNSLookup = f

def DNSLookup(name,qtype,strict=True):
import pydns
return DNSLookup(name,qtype,strict)

set_dns_driver(DNSLookup)

Importing a driver module activates that driver.
For instance, in pydns.py:

import DNS # http://pydns.sourceforge.net
import spf

....
def DNSLookup(...):
...

spf.set_dns_driver(DNSLookup)

NOW, this is all very nice and modular. BUT, the original module was a
single file, which could be run as a script as well as imported as a
module. The script features provided useful command line functionality.
(Using if __name__ == '__main__':). Now that 'spf' is a package, the
command line feature is gone! Even using -m, I get:

python2.4 -m spf
python2.4: module spf has no associated file

Looking at getpass.py as advised, I see they put all the drivers in the
module. I could do that with spf.py, I suppose. But I like how with the
package, the driver code is not loaded unless needed.

One other idea I had was an arrangement like this:

SPF/
pydns.py
dnspython.py

spf.py

This would keep the module as a single file usable from the command line,
but still make driver available as separately loaded modules.

So which of the three options,

1) single file module with all drivers, ala getpass
2) package that cannot be run directly from command line
3) single file module with associated driver package

is the most pythonic?
--
Stuart D. Gathman <st****@bmsi.com>
Business Management Systems Inc. Phone: 703 591-0911 Fax: 703 591-6154
"Confutatis maledictis, flamis acribus addictis" - background song for
a Microsoft sponsored "Where do you want to go from here?" commercial.

Dec 16 '06 #5
On 16 dic, 12:28, "Stuart D. Gathman" <stu...@bmsi.comwrote:
NOW, this is all very nice and modular. BUT, the original module was a
single file, which could be run as a script as well as imported as a
module. The script features provided useful command line functionality.
(Using if __name__ == '__main__':). Now that 'spf' is a package, the
command line feature is gone! Even using -m, I get:
Yes, a little sacrifice...
Looking at getpass.py as advised, I see they put all the drivers in the
module. I could do that with spf.py, I suppose. But I like how with the
package, the driver code is not loaded unless needed.
That's good.
One other idea I had was an arrangement like this:

SPF/
pydns.py
dnspython.py

spf.py

This would keep the module as a single file usable from the command line,
but still make driver available as separately loaded modules.

So which of the three options,

1) single file module with all drivers, ala getpass
You've already seen that it's not a good option. getpass is different
in the sense that only one version should be available in a given
system, so it keeps trying alternatives until a candidate is found.
2) package that cannot be run directly from command line
3) single file module with associated driver package
I think that keeping demo/application code separate from the library
would be a good thing.
So, keep your library inside a package, and provide some external
scripts as example, demo, whatever.
You can instruct distutils to install each thing in the right place.

--
Gabriel Genellina

Dec 17 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Philip | last post by:
Hi, i'am looking for a db2 driver for windows the DB2 servers runs on as400 if that makes any difference. Thanks, Philip
3
by: Jim Hubbard | last post by:
My own searches have proven to be of little help in understanding the implementation of this technology (available since Win98). Any information that you could share on Display Driver Management...
0
by: CS Loh | last post by:
Hi, I install a filter driver through INF file to a 3rd party audio device (with driver). The filter driver works well on the 3rd party driver. However upon uninstallation of the filter driver,...
0
by: Bing | last post by:
Hi, I am configuring the same DB2 v8.1 JDBC universal driver (db2jcc.jar and db2jcc_license_cisuz.jar) from DB2 SP5 fix pack under WSAD 5.1.x environment and WebSphere application Server 5.0.2...
3
by: Rakesh | last post by:
Hi, I want to get connection to a DB2 database using the driver COM.ibm.db2.jdbc.DB2XADataSource. I have also included 'db2java.zip' in the classpath. However I am getting the exception ...
12
by: Steve | last post by:
I wrote a simple virtual device driver int15.sys, Is C# support load the device driver from AP?
3
by: bb | last post by:
I have a windows network device driver written in c++ and a user interface im porting to c#, my problem is i dont seem to be getting notified of the event calls from the driver to the c# app im...
5
by: STeve | last post by:
Hey guys, I currently have a 100 page word document filled with various "articles". These articles are delimited by the Style of the text (IE. Heading 1 for the various titles) These articles...
0
by: bazzer | last post by:
hey, im trying to access a microsoft access database from an ASP.NET web application in visual basic 2003.NET. i get the following error when i try running it: Server Error in...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.