Discussion:
[Fab-user] lcd seems broken
Paul Hoffman
2015-09-29 18:14:40 UTC
Permalink
...but maybe it is just me.

print(os.getcwd())
with lcd("/usr/bin"):
print(os.getcwd())

...prints the same location name twice, and it is clear that the cd didn't
happen.

print(os.getcwd())
with lcd("/does/not/exist"):
print(os.getcwd())

...prints the same location name twice. lcd doesn't throw an error, which I
would have thought it would.

Is this what is expected?

--Paul Hoffman
Ronan Amicel
2015-09-30 21:24:43 UTC
Permalink
Hi,

Try this:

with lcd('/tmp'):
local('pwd')

And this:

with lcd('/non/existing'):
local('pwd')

Hope this helps.
Post by Paul Hoffman
...but maybe it is just me.
print(os.getcwd())
print(os.getcwd())
...prints the same location name twice, and it is clear that the cd didn't
happen.
print(os.getcwd())
print(os.getcwd())
...prints the same location name twice. lcd doesn't throw an error, which I
would have thought it would.
Is this what is expected?
--Paul Hoffman
_______________________________________________
Fab-user mailing list
https://lists.nongnu.org/mailman/listinfo/fab-user
Brandon Whaley
2015-09-30 21:32:44 UTC
Permalink
lcd is intended to modify the local() call (and maybe get, put, et al? I
haven't tested). It does not actually change the cwd afaik.
Post by Paul Hoffman
from fabric.api import local, lcd
print fabric.api.local('pwd', capture=True)
[localhost] local: pwd
/home/redkrieg/projects/fabric
... print fabric.api.local('pwd', capture=True)
...
[localhost] local: pwd
/usr/bin
Post by Paul Hoffman
...but maybe it is just me.
print(os.getcwd())
print(os.getcwd())
...prints the same location name twice, and it is clear that the cd didn't
happen.
print(os.getcwd())
print(os.getcwd())
...prints the same location name twice. lcd doesn't throw an error, which
I would have thought it would.
Is this what is expected?
--Paul Hoffman
_______________________________________________
Fab-user mailing list
https://lists.nongnu.org/mailman/listinfo/fab-user
Peter Sanchez
2015-09-30 21:48:12 UTC
Permalink
Yes. It's expected. Fabric doesn't evaluate the context until a fabric
"command" is actually run. See:

https://github.com/fabric/fabric/blob/master/fabric/context_managers.py#L309
Post by Paul Hoffman
...but maybe it is just me.
print(os.getcwd())
print(os.getcwd())
...prints the same location name twice, and it is clear that the cd didn't
happen.
print(os.getcwd())
print(os.getcwd())
...prints the same location name twice. lcd doesn't throw an error, which
I would have thought it would.
Is this what is expected?
--Paul Hoffman
_______________________________________________
Fab-user mailing list
https://lists.nongnu.org/mailman/listinfo/fab-user
Paul Hoffman
2015-09-30 22:41:31 UTC
Permalink
Thanks, that makes sense. Well, it's completely weird from a programming
standpoint, but once explained, I can see where it might be useful.

--Paul Hoffman
Post by Peter Sanchez
Yes. It's expected. Fabric doesn't evaluate the context until a fabric
https://github.com/fabric/fabric/blob/master/fabric/context_managers.py#L309
Post by Paul Hoffman
...but maybe it is just me.
print(os.getcwd())
print(os.getcwd())
...prints the same location name twice, and it is clear that the cd
didn't happen.
print(os.getcwd())
print(os.getcwd())
...prints the same location name twice. lcd doesn't throw an error, which
I would have thought it would.
Is this what is expected?
--Paul Hoffman
_______________________________________________
Fab-user mailing list
https://lists.nongnu.org/mailman/listinfo/fab-user
Issa Ashwash
2015-09-30 21:42:36 UTC
Permalink
This context manager is identical to cd
<http://docs.fabfile.org/en/1.10/api/core/context_managers.html#fabric.context_managers.cd>,
except that it changes a different env var (lcwd, instead of cwd) and
thus only affects the invocation of local
<http://docs.fabfile.org/en/1.10/api/core/operations.html#fabric.operations.local> and
the local arguments to get
<http://docs.fabfile.org/en/1.10/api/core/operations.html#fabric.operations.get>
/put
<http://docs.fabfile.org/en/1.10/api/core/operations.html#fabric.operations.put>
.
From
http://docs.fabfile.org/en/1.10/api/core/context_managers.html#fabric.context_managers.lcd

If you use local('pwd'), it will reflect the change.
Post by Ronan Amicel
local('pwd')
[localhost] local: pwd
/home/issa
''
... local('pwd')
...
[localhost] local: pwd
/usr/bin
''
...but maybe it is just me.
print(os.getcwd())
print(os.getcwd())
...prints the same location name twice, and it is clear that the cd didn't
happen.
print(os.getcwd())
print(os.getcwd())
...prints the same location name twice. lcd doesn't throw an error, which
I would have thought it would.
Is this what is expected?
--Paul Hoffman
_______________________________________________
Fab-user mailing list
https://lists.nongnu.org/mailman/listinfo/fab-user
Loading...