1
votes

We have Wirecloud installed on our own server, using the Docker image on Docker Hub (latest = 0.9.1). Using the instructions here: https://wirecloud.readthedocs.io/en/latest/development/platform/themes/ we tried to follow the 'Basic themes' section. But is it is not clear where the theme should be placed on the file system.

 1. created the directory structure in the example 
 2. created a file __init__.py with one line: parent = "wirecloud.defaulttheme" 
 3. created a file _variables.scss and pasted the example into it. Put the file in babblerTheme/static/css/ 
 4. created a header.png image and placed it in babblerTheme/static/images/logos/ 
 5. Then updated settings.py with the name of our basic theme with the setting: THEME_ACTIVE = "babblerTheme" 
 6. Then ran python manage.py collectstatic --noinput

we get the error:

...File "/usr/local/lib/python2.7/site-packages/wirecloud/platform/themes.py", line 82, in get_theme_metadata' raise ValueError("%s is not a valid WireCloud theme" % theme_name) ValueError: babblerTheme is not a valid WireCloud theme

We tried putting the theme directory in the following places without any luck:

/opt/wirecloud_instance/wirecloud_instance/babblerTheme
/opt/wirecloud_instance/babblerTheme
/usr/local/lib/python2.7/site-packages/wirecloud/babblerTheme

All three places, same uninformative error.

This should be really easy, but i already spent more than half a day on it. I can work around this bug by changing the contents of the default theme, but i expect that will lead to problems when upgrading Wirecloud.

What should we be doing to get Wirecloud to pick up our custom theme?

2
Copied the /usr/local/lib/python2.7/site-packages/wirecloud/defaulttheme directory to /usr/local/lib/python2.7/site-packages/wirecloud/babblerTheme. Then updated settings.py with the setting: THEME_ACTIVE = "wirecloud.babblerTheme". This seems to make stuff happen. But only after doing "python manage.py collectstatic --noinput" and restarting the server using "apachectl restart". Will try with a minimal theme later. - Robin

2 Answers

1
votes

I have followed your steps and they are working, I do not get the error you were reporting. I have used a clean container and one script for replying your steps:

$ docker run -dP --name wirecloud_test_latest fiware/wirecloud:latest
47ca7b90c7bf85401eeb7bd4c915d560eb9d2bdcb543fb365fa900934a10812f

$ docker cp test_script.sh wirecloud_test_latest:/opt/wirecloud_instance/test_script.sh

$ docker exec -it wirecloud_test_latest /bin/bash
root@47ca7b90c7bf:/opt/wirecloud_instance# su wirecloud
wirecloud@47ca7b90c7bf:/opt/wirecloud_instance# bash test_script.sh
.....
wirecloud@47ca7b90c7bf:/opt/wirecloud_instance# exit
root@47ca7b90c7bf:/opt/wirecloud_instance# apache2ctl graceful
root@47ca7b90c7bf:/opt/wirecloud_instance# exit

Result:

WireCloud with the theme applied

Anyway, it is clear that WireCloud was failing to provide a good error message when trying to load invalid/missing themes, so I have created a ticket to fix an improve those cases. We have also updated the documentation about how to create new themes and we have added some sections to the docker image docs. Take into account that the docker images create a volumen at /opt/wirecloud_instance so, although you solved your problems by placing your theme into /usr/local/lib/python2.7/site-packages/, the best location is /opt/wirecloud_instance/babblerTheme.

Thanks for your time on using WireCloud and reporting these problems :).

Note

Never modify the site-packages nor the dist-packages folders created by virtualenvand the standard python packages. Those folders are no meant to be edited manually and your changes will be lost if you upgrade or remove WireCloud (e.g. by using pip).

Moreover, if you do this using docker, you will lost any change made after pulling a new version of the WireCloud image.

0
votes

Solved!!

Step 1

wirecloud needs you to add everything after /usr/local/lib/python2.7/site-packages/ in python dot separated filename format.

So if your custom theme is in /usr/local/lib/python2.7/site-packages/wirecloud/mytheme directory

then settings.py needs the entry: THEME_ACTIVE = "wirecloud.mytheme" for wirecloud to pick up the mytheme theme on startup.

Step 2

Make sure the command python manage.py collectstatic --noinput is executed on startup, just before restarting the apache webserver. I accomplished this in my custom docker image by changing the docker-entrypoint.sh startup file as follows:

#!/bin/bash

sed -i "s/SECRET_KEY = 'TOCHANGE_SECRET_KEY'/SECRET_KEY = '$(python -c "from django.utils.crypto import get_random_string; import re;  print(re.escape(get_random_string(50, 'abcdefghijklmnopqrstuvwxyz0123456789%^&*(-_=+)')))")'/g" /opt/wirecloud_instance/wirecloud_instance/settings.py

echo ===> migrating python modules with python manage.py migrate
python /opt/wirecloud_instance/manage.py migrate # Apply database migrations
python /opt/wirecloud_instance/manage.py collectstatic --noinput # Collect static files

# Start apache processes in foreground
/usr/sbin/apache2ctl graceful-stop
exec /usr/sbin/apache2ctl -D FOREGROUND

Note: the order of the python commands is important. The line with collectstatic needs to run last, otherwise the static resources are NOT served to browsers.

Wirecloud developers, please update the documentation, if only with a logfile of performing a minor change on a docker image. This was too painful!