<s> from fabric . utils import abort , indent <EOL> from fabric import state <EOL> class _Dict ( dict ) : <EOL> pass <EOL> def _crawl ( name , mapping ) : <EOL> """<STR_LIT>""" <EOL> key , _ , rest = name . partition ( '<STR_LIT:.>' ) <EOL> value = mapping [ key ] <EOL> if not rest : <EOL> return value <EOL> return _crawl ( rest , value ) <EOL> def crawl ( name , mapping ) : <EOL> try : <EOL> result = _crawl ( name , mapping ) <EOL> if isinstance ( result , _Dict ) : <EOL> if getattr ( result , '<STR_LIT:default>' , False ) : <EOL> result = result . default <EOL> else : <EOL> result = None <EOL> return result <EOL> except ( KeyError , TypeError ) : <EOL> return None <EOL> def merge ( hosts , roles , exclude , roledefs ) : <EOL> """<STR_LIT>""" <EOL> bad_roles = [ x for x in roles if x not in roledefs ] <EOL> if bad_roles : <EOL> abort ( "<STR_LIT>" % ( <EOL> indent ( bad_roles ) <EOL> ) ) <EOL> if isinstance ( hosts , basestring ) : <EOL> hosts = [ hosts ] <EOL> role_hosts = [ ] <EOL> for role in roles : <EOL> value = roledefs [ role ] <EOL> if isinstance ( value , dict ) : <EOL> value = value [ '<STR_LIT>' ] <EOL> if callable ( value ) : <EOL> value = value ( ) <EOL> role_hosts += value <EOL> cleaned_hosts = [ x . strip ( ) for x in list ( hosts ) + list ( role_hosts ) ] <EOL> all_hosts = cleaned_hosts <EOL> if state . env . dedupe_hosts : <EOL> deduped_hosts = [ ] <EOL> for host in cleaned_hosts : <EOL> if host not in deduped_hosts and host not in exclude : <EOL> deduped_hosts . append ( host ) <EOL> all_hosts = deduped_hosts <EOL> return all_hosts <EOL> def parse_kwargs ( kwargs ) : <EOL> new_kwargs = { } <EOL> hosts = [ ] <EOL> roles = [ ] <EOL> exclude_hosts = [ ] <EOL> for key , value in kwargs . iteritems ( ) : <EOL> if key == '<STR_LIT:host>' : <EOL> hosts = [ value ] <EOL> elif key == '<STR_LIT>' : <EOL> hosts = value <EOL> elif key == '<STR_LIT>' : <EOL> roles = [ value ] <EOL> elif key == '<STR_LIT>' : <EOL> roles = value <EOL> elif key == '<STR_LIT>' : <EOL> exclude_hosts = value <EOL> else : <EOL> new_kwargs [ key ] = value <EOL> return new_kwargs , hosts , roles , exclude_hosts </s>
