[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Fab-user] external role definitions
From: |
Jeff Forcier |
Subject: |
Re: [Fab-user] external role definitions |
Date: |
Tue, 14 Dec 2010 12:03:59 -0500 |
Hi Michael,
Apologies for the long delay, been busy :(
I just made a ticket for this to keep it from getting buried in my inbox:
http://code.fabfile.org/issues/show/266
I'll need more time to think about how I see the feature fitting into
Fabric overall, but the overall concept (an easy way to fill the
roledefs from external sources instead of defining it in Python) is
definitely something I think we should have eventually.
I'd expect to be looking at this for Fab 1.1 or 1.2 when we start
doing more serious work with OO tasks/roles/hosts/etc, as it fits
neatly into that sort of effort.
Best,
Jeff
On Fri, Nov 19, 2010 at 4:53 AM, Michael Gliwinski
<address@hidden> wrote:
> On Friday 19 Nov 2010 02:41:28 Jeff Forcier wrote:
>> Hey Michael,
>>
>> As Morgan said, we'd love to see what you have, for sure! A couple
>> additional points below.
>
> OK, I don't have it anywhere public, it's really just few lines of code, so
> pasted them below.
>
> [...]
>> I'm not sure how much of the Fab source you peeked at, but roledefs
>> are already lazy, so hopefully your load_from() method is just
>> populating the dict values with callables -- that's all that should be
>> necessary for this aspect of your setup to work, off the top of my
>> head.
>
> Yes, I knew about that, but in this case I'm actually loading the whole dict
> instead of each role individually. I think it would actually be more
> complicated to try to split it, but see below.
>
> [...]
>> That's certainly valid. Part of me says the feature is a bit on the
>> esoteric side, but on the other hand I've always been a fan of adding
>> "power user" features provided the common use case isn't compromised
>> and said feature doesn't add significant complexity. Based on your
>> description, your change probably passes both those tests :)
>
> Well, my use case probably is, but I'm thinking that this can be used for as
> simple thing as just separating role definitions into another file.
>
>> Let us know where we can check it out and I'm sure we can offer
>> further advice/questions/etc, and if it looks good I'll definitely add
>> a ticket for figuring out how best to include it.
>
> Well, here goes (stripped most docstrings for brevity):
>
>
> from os import path
>
> import contextlib
> import functools
> import urllib2
> import urlparse
>
> import yaml
>
> def urlopen(url, *args, **kwargs):
> """Open URL and return a file-like object for its resource.
>
> This is just a wrapper for urllib2.urlopen to handle local paths (URLs
> without scheme) and make the returned object behave like a context
> manager.
> """
> if not urlparse.urlsplit(url).scheme:
> url = 'file://' + path.abspath(path.normpath(path.expanduser(url)))
> return contextlib.closing(urllib2.urlopen(url, *args, **kwargs))
>
> class RoleDefs(dict):
> _loaded = False
> _sources = None
>
> def load_from(self, sources):
> if isinstance(sources, basestring) \
> or not hasattr(sources, '__iter__'):
> sources = [sources]
> self._sources = sources
>
> address@hidden
> def source_loader(url):
> with urlopen(url, 'r') as fp:
> return yaml.load(fp)
>
> def __missing__(self, key):
> if self._loaded or not self._sources: raise KeyError(key)
> self._loaded = True
> sources = list(self._sources)
> while sources:
> src = sources.pop(0)
> loader = src
> if not callable(src):
> loader = functools.partial(self.source_loader, src)
> try:
> self.update(loader())
> break
> except Exception:
> if not sources: raise KeyError(key)
> return self[key]
>
>
> --
> Michael Gliwinski
> Henderson Group Information Services
> 9-11 Hightown Avenue, Newtownabby, BT36 4RT
> Phone: 028 9034 3319
>
> **********************************************************************************************
> The information in this email is confidential and may be legally privileged.
> It is intended solely for the addressee and access to the email by anyone
> else is unauthorised.
> If you are not the intended recipient, any disclosure, copying, distribution
> or any action taken or omitted to be taken in reliance on it, is prohibited
> and may be unlawful.
> When addressed to our clients, any opinions or advice contained in this
> e-mail are subject to the terms and conditions expressed in the governing
> client engagement leter or contract.
> If you have received this email in error please notify address@hidden
>
> John Henderson (Holdings) Ltd
> Registered office: 9 Hightown Avenue, Mallusk, County Antrim, Northern
> Ireland, BT36 4RT.
> Registered in Northern Ireland
> Registration Number NI010588
> Vat No.: 814 6399 12
> *********************************************************************************
>
>
> _______________________________________________
> Fab-user mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/fab-user
>
--
Jeff Forcier
Unix sysadmin; Python/Ruby engineer
http://bitprophet.org
- Re: [Fab-user] external role definitions,
Jeff Forcier <=