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

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

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

Comments

Projects
None yet
4 participants
@bitprophet
Member

bitprophet commented Aug 19, 2011

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

@ghost ghost assigned bitprophet Aug 19, 2011

@bitprophet

This comment has been minimized.

Show comment
Hide comment
@bitprophet

bitprophet Aug 19, 2011

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

Member

bitprophet commented Aug 19, 2011

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

This comment has been minimized.

Show comment
Hide comment
@bitprophet

bitprophet Aug 19, 2011

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

Member

bitprophet commented Aug 19, 2011

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

This comment has been minimized.

Show comment
Hide comment
@bitprophet

bitprophet Aug 19, 2011

Member

Dmitry Guyvoronsky (dreamiurg) posted:


Jeff, please pull my changes to fix this issue


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

Member

bitprophet commented Aug 19, 2011

Dmitry Guyvoronsky (dreamiurg) posted:


Jeff, please pull my changes to fix this issue


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

@bitprophet

This comment has been minimized.

Show comment
Hide comment
@bitprophet

bitprophet Aug 19, 2011

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

Member

bitprophet commented Aug 19, 2011

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

@joekiller

This comment has been minimized.

Show comment
Hide comment
@joekiller

joekiller Apr 26, 2013

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'

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

This comment has been minimized.

Show comment
Hide comment
@bitprophet

bitprophet Apr 29, 2013

Member

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

Member

bitprophet commented Apr 29, 2013

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

This comment has been minimized.

Show comment
Hide comment
@bitprophet

bitprophet Apr 29, 2013

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!

Member

bitprophet commented Apr 29, 2013

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

This comment has been minimized.

Show comment
Hide comment
@joekiller

joekiller Apr 29, 2013

This fix also worked for me. Thank you!

This fix also worked for me. Thank you!

@dperetti

This comment has been minimized.

Show comment
Hide comment
@dperetti

dperetti May 30, 2013

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.)

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

This comment has been minimized.

Show comment
Hide comment
@bitprophet

bitprophet Jun 8, 2013

Member

@dperetti - see #912 thanks!

Member

bitprophet commented Jun 8, 2013

@dperetti - see #912 thanks!

@atleta

This comment has been minimized.

Show comment
Hide comment
@atleta

atleta 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.

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