problems with DBM nonuniformity

Jason R. Mastaler jason-dated-1007772335.65c4ac at mastaler.com
Fri Nov 30 01:45:34 CET 2001


I'm having some trouble with one of my applications due to how DBM
implementations vary across UNIX platforms.

This app will read a DBM file when it finds a line such as this in its
"filter file":

  from-dbm ~/.tmda/lists/whitelist.db ok

It uses the anydbm module to open "whitelist.db" and goes from there.
This works fine.  However, I'd like to support an automatic DBM
regeneration feature that works like this:

Given the above filter line, if the user turns on this feature, the
application will look for a textfile in the same directory called
"whitelist" and compare its timestamp to that of "whitelist.db".  If
"whitelist.db" either doesn't exist or the modification date of
"whitelist" is more recent, "whitelist.db" will be regenerated using
anydbm, and then read.  The idea is similar to how ".pyc" file
auto-generation works.

Here is the problem.  Depending on the platform, the "whitelist.db"
DBM may be composed of one or more files of different names.

On Linux, "whitelist.db" = whitelist.db when the default module is
dbhash, so there is no problem:

% python -c "import anydbm;wl = anydbm.open('whitelist.db','c')" 
% ls -l whitelist*
-rw-------    1 jasonrm  acl         16384 Nov 29 17:15 whitelist.db

However on Solaris for example (default module of dbm):

% python -c "import anydbm;wl = anydbm.open('whitelist.db','c')" 
% ls -l whitelist*
-rw-------   1 jason    users           0 Nov 29 19:13 whitelist.db.dir
-rw-------   1 jason    users           0 Nov 29 19:13 whitelist.db.pag

Under Linux, the dbm module acts differently, adding a '.db' suffix to
the given filename:

% python -c "import dbm;wl = dbm.open('whitelist.db','c')"
% ls -l whitelist*
-rw-------    1 jasonrm  acl         16384 Nov 29 17:21 whitelist.db.db

So, I can't rely on comparing "whitelist" with "whitelist.db" filename
to filename since the latter might not exist.

There are probably even more discrepancies that I haven't found, but I
hope you can see my dilemma.  There is no uniformity in file naming
when using anydbm, or when using the same DBM module across different
platforms.

Does anyone have some suggestions on how I might support this feature
in a cross-platform, and generic fashion?

Thanks.

-- 
(TMDA - http://tmda.sourceforge.net)
(Python-based SPAM reduction system)




More information about the Python-list mailing list