Created
January 23, 2014 03:09
-
-
Save tkdchen/8572180 to your computer and use it in GitHub Desktop.
collect static files in SPEC
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Predefinition before doing anything | |
project_lib=${RPM_BUILD_ROOT}%{python_sitelib}/%{pkg_name} | |
product_module=${project_lib}/%{pkg_name}/product_settings.py | |
product_module_bak=${product_module}.bak | |
static_root=${RPM_BUILD_ROOT}%{_datadir}/%{pkg_name}/static/ | |
# Add all app names whose static files are needed to be collected | |
# Just enter what you write in settings.py | |
apps_static_collected_from="" | |
cp $product_module $product_module_bak | |
echo "STATIC_ROOT = '${static_root}'" >> ${product_module} | |
# Construct and overwrite INSTALLED_APPS to collect static files from all | |
# necessary apps. | |
apps_list="'django.contrib.admin', 'django.contrib.staticfiles'" | |
for app in ${apps_static_collected_from} | |
do | |
apps_list="${apps_list},'${app}'," | |
done | |
echo "INSTALLED_APPS = ( ${apps_list} )" >> ${product_module} | |
# Overwrite database configuration to avoid communicating with real database, | |
# since collecting static does not need any database operations. | |
echo "DATABASES['default']['ENGINE'] = 'django.db.backends.sqlite3'" >> ${product_module} | |
echo "DATABASES['default']['NAME'] = ':memory:'" >> ${product_module} | |
django_admin_bins="/usr/bin/django-admin /usr/bin/django-admin.py" | |
for cmd in ${django_admin_bins} | |
do | |
if [ -e "$cmd" ] | |
then | |
${cmd} collectstatic \ | |
--pythonpath=`dirname ${project_lib}` \ | |
--settings=%{pkg_name}.product_settings \ | |
--noinput | |
static_collected=1 | |
break | |
fi | |
done | |
if [ ! -v static_collected ] | |
then | |
echo "Cannot find either django-admin or django-admin.py" | |
exit 1 | |
fi | |
mv ${product_module_bak} ${product_module} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment