0

Are there any gotchas I should be aware of when running Python scripts from inside rpm install?

Here's the gist of the problem. We created a custom RPM installer for deploying our Django app. As part of the installation process I want to run a Django management command that collects all static files and copies them into a predefined location. Here's what this looks like when run manually from a command line:

$ python2.6 manage.py collectstatic --noinput
/usr/lib/python2.6/site-packages/reversion/__init__.py:31: UserWarning: django-reversion 1.5 is intended for use with django 1.3.0. You are running django 1.3.1, so some features, such as admin integration, may not work. Please see https://github.com/etianen/django-reversion/wiki/Compatible-Django-Versions
  "django_version": format_version(django.VERSION[:3]),
Copying '/usr/lib/python2.6/site-packages/django/contrib/admin/media/img/gis/move_vertex_on.png'
Copying '/usr/lib/python2.6/site-packages/django/contrib/admin/media/img/gis/move_vertex_off.png'
Copying '/usr/lib/python2.6/site-packages/django/contrib/admin/media/img/admin/icon_clock.gif'
Copying '/usr/lib/python2.6/site-packages/django/contrib/admin/media/img/admin/arrow-down.gif'
Copying '/usr/lib/python2.6/site-packages/django/contrib/admin/media/img/admin/inline-restore.png'
...

So to run this as part of the RPM install I added the following to the spec file:

%post
# collect static files
pushd .
cd %{installpath}/src/app/
%{__python} manage.py collectstatic --noinput --settings=settings_prod
popd

The problem is that when I run this, I can see the task being kicked off:

 sudo rpm -U app-0.2.8.18889M-1.x86_64.rpm -vv 

 ...
+ pushd .
/ /
+ cd /opt/qpsi/app/src/app/
+ /usr/bin/python2.6 manage.py collectstatic --noinput --settings=settings_prod
/usr/lib/python2.6/site-packages/reversion/__init__.py:31: UserWarning: django-reversion 1.5 is intended for use with django 1.3.0. You are running django 1.3.1, so some features, such as admin integration, may not work. Please see https://github.com/etianen/django-reversion/wiki/Compatible-Django-Versions
  "django_version": format_version(django.VERSION[:3]),
There is no South database module 'south.db.oracle' for your database. Please either choose a supported database, check for SOUTH_DATABASE_ADAPTER[S] settings, or remove South from INSTALLED_APPS.
+ popd

But there is no expected list of files being copied in the output and the static directory isn't actually being populated.

So the questions are:

  1. Is there anything special about running python scripts from RPM that I need to be aware of
  2. I'm using -vv option of the rpm command to get verbose output from the install process, but is there a way to further debug what's going on inside of rpm once the python script gets kicked off.

Thanks D.

3 Answers 3

0

How about just symlinking them ...

%post
#Configure django admin media if it hasn't already been:
[ -d /path/to/new/media ] || ln -s /usr/lib/python2.6/site-packages/django/contrib/admin/media/ /path/to/new/media
Sign up to request clarification or add additional context in comments.

1 Comment

I'm taking advantage of Django 1.3's new way of handling static files, so I don't think this is a necessary step. I don't have any issues with admin media when I run collectstatic manually.
0

You should look at virtualenv (http://pypi.python.org/pypi/virtualenv), and then have your rpm bundle the entire virtual environment, along with the site-packages directory, so the eggs you need will be available on the deployed system, and that the eggs will be at the version your script requires. (In the case above, it sounds like the south version may be different from what you expect).

Then in the %post section, call the python from your virtual environment instead of the system python,

The missing egg problem will be pretty easy to see, but debugging problems due to differing egg versions can be pretty subtle.

See also: Deploying Django with virtualenv inside a distribution package?

Comments

0

I ended up moving the scripts from %post to %build. That took care of the issue.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.