[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Fab-user] Can't find in the docs, return codes
From: |
Jeff Forcier |
Subject: |
Re: [Fab-user] Can't find in the docs, return codes |
Date: |
Wed, 12 Jun 2013 14:58:58 -0700 |
I must not be following, why doesn't result.succeeded / result.failed
work for this use case? Or doing e.g. "if result.return_code not in
[0, 1]"?
See ~third paragraph off
http://docs.fabfile.org/en/1.6/api/core/operations.html#fabric.operations.run
On Wed, Jun 12, 2013 at 2:45 PM, Eric Brunson <address@hidden> wrote:
> I'm hoping to start a discussion of behavior that would aid in implementing
> flow control. I've only been using fabric for a couple of months, so maybe
> I just need some education on better coding patterns.
>
> What I'd like to be able to do is something like this:
>
> def remove_backups(path):
> with settings(warn_only=True), hide('warnings'):
> result = run('[ -d %s ]' % path)
> if ! result.error_code:
> with cd(path):
> run('rm *.bak')
>
> Or possibly:
>
> def remove_backups(path):
> try:
> run('[ -d %s ]' % path)
> except NonZeroExitCode:
> print("no backup dir")
> return
>
> with cd(path):
> run('rm *.bak')
>
>
> I end up having to do something like this:
>
> def remove_backups(path):
> with settings(warn_only=True), hide('stderr','warnings'):
> result = run('[ -d %s ] && echo true' % path)
> if result == 'true':
> run('rm *.bak')
>
>
> Which is less than pythonic.
>
> Has there ever been discussion of throwing exceptions or handling exit codes
> rather than the default "Abort unless otherwise instructed?" tactic as it
> currently exists? Constructing intelligent flow control gets really messy
> in the current implementation.
>
> Other than that, I've been using the crap out of the application and think
> it's great. Thanks for all the hard work.
>
> Sincerely,
> e.
>
>
>
>
> _______________________________________________
> Fab-user mailing list
> address@hidden
> https://lists.nongnu.org/mailman/listinfo/fab-user
>
--
Jeff Forcier
Unix sysadmin; Python/Ruby engineer
http://bitprophet.org