[TransWarp] input-driven application

Phillip J. Eby pje at telecommunity.com
Fri May 16 19:40:02 EDT 2003


At 11:03 PM 5/16/03 +0300, alexander smishlajev wrote:

>perhaps.  there is no problem with complete application assembling the 
>whole chain: as far as i understand, the main component may just pass 
>file-like objects as a keyword arguments of the AbstractCommand 
>constructor for ILC and OLC objects.
>
>but since those ILC and OLC objects are theoretically runnable by 
>themselves from the command line, i'd like to have some machinery allowing 
>to run them via 'peak' bootstrapper, with 'linkin' and 'linkout' given in 
>commandline options as either disk files or (in shells more advanced than 
>command.com) file descriptor numbers.

Ah.  Well, then the thing to do is to define the 'linkin' or 'linkout' as 
Once bindings that figure out what they should be linked to, by parsing 
command line options supplied in self.argv.  Sort of like this:

class ILC(commands.AbstractCommand):

    def parsedArgs(self,d,a):
        # code that parses 'self.argv' and returns
        # a dictionary of argument info, optionally
        # getting default values from peak.config properties

    parsedArgs = binding.Once(parsedArgs)

    def linkin(self,d,a):
        return open(self.parsedArgs['linkin_file'],'r')

    linkin = binding.Once(linkin)

Now, if your 'linkin' attribute hasn't been assigned by the time it's 
needed, the linkin method will run, calling the parsedArgs method if it 
hasn't been invoked (or overridden by the creating application), and voila, 
everything's ready to go.

I would actually like to supply a default mechanism at some point for doing 
all this, but I haven't really needed it myself yet.  So I'm not sure if 
I'd rather use getopt or optparse, but I do know I'd like for subclasses to 
automatically inherit options defined in superclasses, unless 
overridden.  Anyway, there are many considerations to look at in adding 
such a thing to the framework, but for a specific application certainly you 
can take your pick and use whatever argument parsing mechanism you like.




More information about the PEAK mailing list