473,766 Members | 2,055 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.co m>
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 1543
On 9 dic, 00:53, "Stuart D. Gathman" <stu...@bmsi.co mwrote:
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.co mwrote:
>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_d river 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_drive r import DNSLookup
else: raise Exception('Unkn own DNS driver')

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

--
Stuart D. Gathman <st****@bmsi.co m>
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_drive r import DNSLookup
else: raise Exception('Unkn own 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__,__em ail__,__version __

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

def DNSLookup(name, qtype,strict=Tr ue):
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_dri ver(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.co m>
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.co mwrote:
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
4929
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
2093
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 Layer (DDML) usage would be greatly appreciated. Jim Hubbard
0
1220
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, it will eventually cause the audio driver get uninstalled as well. Here are the steps to uninstall the filter driver: 1. Disable the target audio device. 2. Delete the filter name from "Upperfilters" key of the audio device in
0
3083
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 on Windows 2000 machines. I configured a connection pool data source using type 4 for a local test environment in WSAD 5.1.x, and a connection pool data source on the WebSphere Server too. Both data sources are accessing the same database.
3
27060
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 java.sql.SQLException: No suitable driver at java.sql.DriverManager.getConnection(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source) at Conn.main(Conn.java:44)
12
13772
by: Steve | last post by:
I wrote a simple virtual device driver int15.sys, Is C# support load the device driver from AP?
3
5951
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 using the following code in c# in the UI to create an event public static IntPtr OpenGrantedPacketEvent() { IntPtr objDriver = Driver.OpenDriver(); IntPtr objEvent = Win32.CreateEvent(IntPtr.Zero, false, false,
5
12871
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 will then be converted into HTML and saved. I want to write a parser through vb.net that uses the word object model and was wondering how this could be achieved? The problem i am running into is that i can not test whether the selected text is...
0
12067
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 '/CinemaBookingSystem' Application. -------------------------------------------------------------------------------- ERROR General error Unable to open registry key 'Temporary (volatile) Jet DSN for process
0
9568
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9404
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9959
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9837
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7381
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5279
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.