[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Re[2]: [coldsync-hackers] Writing conduits that read more then oneDB.



On June 6, 2003 07:54 pm, Christophe Beauregard wrote:
> On Friday 06 June 2003 20:05, Izzy Blacklock wrote:
> > if !defined $HEADERS{ DBpath }
> > 	{
> > 	( $HEADERS{ DBpath } = $HEADERS{ InputDB }  ) =~  !(.*)/.*$!$1!;
> > 	}
> >
> > This is what I'm doing now.  I'd still like to be able to load it as a
> > default value in the hash above before the headers are processed though.
> > If anyone has suggestions of how this could be done, I'd love to here
> > them! ;)
>
> That's what I was thinking while following the thread.
>
> $HEADERS{InputDB} isn't set until StartConduit/ConduitMain runs, so
> anything you do before that is just wishful thinking. But
> StartConduit/ConduitMain rely on sane defaults in %HEADERS and you want
> DBpath mentioned so the -config command line works, so you want something
> useful as a default. Circular dependency, right?

You know, I think your right.  $HEADERS wont be filled at this point, so I 
can't use one value to set another in this case.  But assuming that this 
wasn't a problem, is it possible to do what I was trying to do?  Just In case 
I run into it again.

> What I'm wondering is why you'd even want to allow the user to define the
> path of the .pdb's? If they aren't all in the same location as InputDB,
> you're basically syncing Palm databases from somewhere that coldsync
> doesn't know anything about. That... doesn't seem right.

You do have a point.  My aim was just to be flexible.  Who knows what a user 
in the future might want to do with it.  One valid reason that someone might 
want this option is if they wanted to parse an old backup stored in a 
different location.  They could manually call the conduit with a script like 
this:

#!/bin/bash
echo 'Daemon: coldsync
Version: 2.1.2
InputDB: /my/palm/backup/TitraxNameDB.pdb
TitraxNoteDB: /my/palm/backup/TitraxNote.pdb 
File: ./titrax.txt
' | ./TitraxConduit conduit dump

> If you assume that all the databases are where InputDB is, then there's no
> reason why you need to fuss with trying to get the path into %HEADERS at
> all. $HEADERS{InputDB} will be set for you and that's all you need, right?
> Okay, maybe the database _names_ could be defined there, but the user has
> already configured that path in the "palm" section of the configuration...
>
> Er... which is also where $HEADER{PDA-Directory} is derived from, isn't it?
> Which would mean that the databases are all supposed to be in
> "$HEADER{PDA-Directory}/backup"?

I didn't know about PDA-Directory.  I'll poke around in the code a little 
more.  This may be an alternate way for me to get/set the DBpath I'm looking 
for.  For flexability, I still want a DBpath option available for the user 
though, but if they don't set it, I need to provide a sane default.

> So all $HEADER{InputDB} is useful for is as a database that has
> conveniently been opened for you by StartConduit:
> ---------------------------------------------------------------------------
>--------------- %HEADERS = (
>          File            =>      "./TitraxTestOutput.txt",
> );
>
> StartConduit('dump');
>
> my %pdbs;
>
> foreach( qw(Datebookdb TitraxNoteDB TitraxDataDB TitraxNameDB) ) {
> 	($pdbs{$_} = $PDB and next) if $PDB->{name} eq $_;
>
> 	$pdsb{$_} = new Palm::PDB;
> 	$pdbs{$_}->Load(  $HEADER{PDA-Directory} . "/backup/" . $_ . ".pdb" );
> }
>
> ---------------------------------------------------------------------------
>---------------

I like it! :)  That's a much more elegant way then creating a local scalar for 
each! :)  Of course I couldn't allow the user to specify different locations 
for each of the DB files this way.  But that would be a pretty far fetched 
need anyway.  Perhaps it would be enough just to allow them to specify an 
alternate location for the DB files.  Even then, if they provide an alternate 
location of the InputDB file, that would give me the alternate path, assuming 
all .pdbs are in the same location.

Excuse me for thinking out loud, but I think you might have something here, 
which has caused me to rethink my approach. :)

>
> I suppose you could allow the user to specify the names of all the
> databases in the config in which case you'd need to map your internal names
> to whatever the user specifies.
>
> But the gist of all that is you end up with four open databases each
> accessible as $pdbs{<dbname>}.
>
> If you want to write at the end of the conduit, you do need something like:
> ---------------------------------------------------------------------------
>--------------- foreach( values %pdbs ) {
> 	$_->Write( $HEADER{PDA-Directory} . "/backup/" . $_->{name} . ".pdb" );
> }
> ---------------------------------------------------------------------------
>---------------
>
> Anyhow, my two cents. I'm pretty new to this conduit thing myself.

That's OK, your obviousely more experienced with Perl then me.  I appreciate 
your feedback.  I think I may have learned something! ;)

...Izzy

-- 
This message was sent through the coldsync-hackers mailing list.  To remove
yourself from this mailing list, send a message to majordomo@thedotin.net
with the words "unsubscribe coldsync-hackers" in the message body.  For more
information on Coldsync, send mail to coldsync-hackers-owner@thedotin.net.