fabric.contrib.files.upload_template should respect lcd() and template_dir #328

Closed
bitprophet opened this Issue Aug 19, 2011 · 11 comments

Projects

None yet

4 participants

@bitprophet
Member

Description

upload_template respects template_dir only if jinja2 is used, otherwise it simply tries to open file in current dir:

with open(filename) as inputfile:
text = inputfile.read()
if context:
text = text % context


Originally submitted by Dmitry Guyvoronsky (dreamiurg) on 2011-03-26 at 06:44pm EDT

@bitprophet bitprophet was assigned Aug 19, 2011
@bitprophet
Member

Jeff Forcier (bitprophet) posted:


template_dir is only supposed to apply to Jinja templates. Otherwise it expects a regular (relative or absolute, as it's used with open()) file path with no concept of a template directory.

I could see the argument for it supporting lcd however.


on 2011-03-26 at 08:57pm EDT

@bitprophet
Member

Dmitry Guyvoronsky (dreamiurg) posted:


Agree. I think docs should be a bit more clear then about template_dir + Jinja templates.


on 2011-03-26 at 10:20pm EDT

@bitprophet
Member

Dmitry Guyvoronsky (dreamiurg) posted:


Jeff, please pull my changes to fix this issue


on 2011-03-27 at 05:19pm EDT

@bitprophet
Member

Jeff Forcier (bitprophet) posted:


lcd() is in 1.x and up, so this should be reassigned, not sure why it's on 0.9.x.


on 2011-04-29 at 02:56pm EDT

@bitprophet bitprophet closed this Mar 14, 2013
@joekiller
Contributor

So was this ever fixed? I'm using 1.6 and I try:

with lcd("/dir/that/contains/template"):
    upload_template('node.ptl', '/tmp/chef/node.json', context=env_context)

And the error:

  File "lib/python2.7/site-packages/fabric/contrib/files.py", line 108, in upload_template
    with open(filename) as inputfile:
IOError: [Errno 2] No such file or directory: 'node.ptl'
@bitprophet
Member

Yea this looks broken now to me. Not sure how that happened, I'm assuming it was fixed at some point.

@bitprophet bitprophet reopened this Apr 29, 2013
@bitprophet
Member

Fixed, tested locally, works OK for me. Pushed to the 1.6 and master branches if you're willing to take a prerelease look, @joekiller. Thanks a lot for the catch!

@joekiller
Contributor

This fix also worked for me. Thank you!

@dperetti

Not sure if that was intentional, but I think this fix broke my scripts. :-)
I'm using jinja but not template_dir.
This used to work in 1.6.0 :

        upload_template(filename='deployment/supervisor/gunicorn.conf',
                        destination="/etc/supervisor/conf.d/%(project_user)s.conf" % env,
                        use_jinja=True,
                        context=env,
                        use_sudo=True,
                        backup=False)

But in 1.6.1, I now get : AttributeError: 'NoneType' object has no attribute 'startswith'.

It looks like using jinja, template_dir is now required (whereas the doc still states : Templates will be loaded from the invoking user's current working directory by default, or from template_dir if given.)

@bitprophet
Member

@dperetti - see #912 thanks!

@atleta
atleta commented Jun 18, 2014

Still broken in 1.9.0:

If using mirror_local_mode then breaks whether using jinja or not:
File ".../env/local/lib/python2.7/site-packages/fabric/contrib/files.py", line 109, in upload_template
mode = os.stat(filename).st_mode
OSError: [Errno 2] No such file or directory: '....'

The problem is that theabove line doesn't apply the lcd. Created a fix (one liner) and a test case that does break without the fix and passes with it. Creating a pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment