Suggest design to accomodate non-unix platforms ?

Dan Stromberg drsalists at gmail.com
Thu Apr 19 18:35:58 EDT 2012


On Wed, Apr 18, 2012 at 5:16 PM, Miki Tebeka <miki.tebeka at gmail.com> wrote:
> > So I'm interested in suggestions/examples where a user can update a
> > config file to specify by which means they want (in this case) the ssh
> > functionality to be supplied.
> You can do something like that (it's called a factory):
>> COMMANDS = {
> 'win32': 'win32 command goes here',
> 'linux2': 'linux command goes here',
> 'darwin': 'OSX command goes here',
> }
> def get_command():
> return COMMANDS.get(sys.platform)
>
I'd actually suggest that you not do this.
It's too analogous to the old way of making things portable: #ifdef and
#define all over, EG:
#ifdef win32
#define thinga
#define thingb
#define thingc
#endif
#ifdef linux32
#define otherthinga
#define otherthingb
#define otherthingc
#endif
It's not nearly as adaptive as scaning $PATH for ssh, falling back on putty
if necessary - this is analogous to GNU autoconf. You'd probably have a
small class you genericize this with - with one instance for each such
executable that might be different from one OS to another. You could
probably just pass __init__ a list of possible commands to try, and then
have a __call__ method.
That way when Haiku takes the world by storm, your porting effort should be
smaller. ^_^ (Or something. I really, really hope that Windows, OS/X and
Linux won't be the only major OS's for all time)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20120419/be7dc6a8/attachment-0001.html>


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /