Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get/put can not use ~ on Windows #1885

Open
klahnakoski opened this issue Sep 29, 2018 · 4 comments
Open

get/put can not use ~ on Windows #1885

klahnakoski opened this issue Sep 29, 2018 · 4 comments

Comments

@klahnakoski
Copy link

This command does not work on Windows; the command is invalid:

conn.put('~/my_data_file.txt',  '/home/ubuntu/data.txt')

It would be nice if it did work though

@SwampFalc
Copy link

'~' is a construct of bash: https://www.gnu.org/software/bash/manual/html_node/Tilde-Expansion.html

Which means it is not even guaranteed to work on every Linux installation out there, so expecting it to work on Windows is a real stretch.

Also note, Windows paths use '' and not '/'.

Try this:
conn.put('%HOMEPATH%\my_data_file.txt', '/home/ubuntu/data.txt')

@klahnakoski
Copy link
Author

Try this:
conn.put('%HOMEPATH%\my_data_file.txt', '/home/ubuntu/data.txt')

Yes, but that code will not work on my Linux machines.

Maybe I am asking for platform independent way to navigate a hierarchical filesystem:

  • directory separator (/)
  • path seperator (:)
  • home directory (~)
  • current directory (.)

There are other constants that would be nice, but I used rarely

  • temporary data location
  • application data location
  • program location
  • user documents location

@SwampFalc
Copy link

Remember that what fabric does is connect you straight to the machine. Whatever you try to do through Connection.run() or Connection.put(), needs to be aware of the machine it will run on.

Fabric does give YOU all the tools you need to build your own platform-agnostic tool. But the odds of finding such an abstraction layer already built for you are small. I mean, what if someone built such a thing but had decided to implement the Windows standard instead?

@jfklein13
Copy link

Agreeing with above, and adding that while it doesn't seem Fabric's job to do this, os.path.expanduser seems to do what you want: https://docs.python.org/3/library/os.path.html#os.path.expanduser

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants