简体   繁体   English

在rpm安装过程中运行Python脚本

[英]running Python scripts as part of rpm install process

Are there any gotchas I should be aware of when running Python scripts from inside rpm install? 从rpm install内部运行Python脚本时,我应该注意一些陷阱吗?

Here's the gist of the problem. 这是问题的要点。 We created a custom RPM installer for deploying our Django app. 我们创建了一个自定义RPM安装程序来部署Django应用。 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. 在安装过程中,我要运行Django管理命令,该命令收集所有静态文件并将其复制到预定义的位置。 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: 因此,为了在RPM安装中运行它,我将以下内容添加到了规范文件中:

%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 我需要了解有关从RPM运行python脚本的任何特殊信息
  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. 我正在使用rpm命令的-vv选项从安装过程中获取详细的输出,但是一旦启动了python脚本,有没有一种方法可以进一步调试rpm内部的情况。

Thanks D. 感谢:D。

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

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. 您应该查看virtualenv( http://pypi.python.org/pypi/virtualenv ),然后将rpm捆绑到整个虚拟环境以及site-packages目录中,这样您所需的鸡蛋将可以在部署的系统,并且彩蛋将达到您的脚本所需的版本。 (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, 然后在%post部分中,从您的虚拟环境而不是系统python中调用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? 另请参阅: 在发行包中使用virtualenv部署Django?

I ended up moving the scripts from %post to %build. 我最终将脚本从%post移到%build。 That took care of the issue. 那解决了这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM