The get() is going to raise an error, and you're best off surrounding it with a
try/except and returning True outside the catch, and return False if the get
raises the AttributeError.

goose

On Tue, Oct 19, 2010 at 10:54:57AM -0400, Jeff Honey wrote:
> In an effort to do a rudimentary test before moving onto the next host, I've 
> nested one function inside another. I put a file on the host, reboot it, and 
> then test if I can pull it back down. When I can, move to the next host in 
> the loop.
> 
> ...in fabfile.py:
> <snip>
> def is_ready():
>  with settings(warn_only=True):
>   get('/tmp/ready.txt','~/')
> 
> def reboot():
>  for host in env.roledefs['test']:
>   with settings(host_string=host):
>    put('ready.txt','/tmp/')
>    run('shutdown -r now')
>    while not is_ready():
>     time.sleep(60)
>    return True
> </snip>
> 
> ...the resultant error:
> <snip>
> Traceback (most recent call last):
>   File "c:\python26\lib\site-packages\fabric\main.py", line 537, in main 
> commands[name](*args, **kwargs)
>   File "C:\Users\foo\Desktop\fabfile.py", line 41, in reboot while not 
> is_ready():
>   File "C:\Users\foo\Desktop\fabfile.py", line 30, in is_ready 
> get('/tmp/ready.txt','~/')
>   File "C:\Python26\lib\contextlib.py", line 34, in __exit__ 
> self.gen.throw(type, value, traceback)
>   File "C:\Python26\lib\contextlib.py", line 113, in nested yield vars
>   File "C:\Users\foo\Desktop\fabfile.py", line 30, in is_ready 
> get('/tmp/ready.txt','~/')
>   File "c:\python26\lib\site-packages\fabric\network.py", line 391, in 
> host_prompting_wrapper return func(*args, **kwargs)
>   File "c:\python26\lib\site-packages\fabric\operations.py", line 372, in get 
> _handle_failure(message=msg % remote_path, exception=e)
>   File "C:\Python26\lib\contextlib.py", line 153, in __exit__ 
> self.thing.close()
> AttributeError: 'NoneType' object has no attribute 'close'
> Disconnecting from host... done.
> </snip>
> 
> Am I even on the right track?
> --
>  ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
> ¤ kyoboku kazeoshi ¤
>  ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
> _______________________________________________
> Fab-user mailing list
> [email protected]
> http://lists.nongnu.org/mailman/listinfo/fab-user
---end quoted text---

_______________________________________________
Fab-user mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/fab-user

Reply via email to