1

我们在自己的服务器上安装了 Wirecloud,使用 Docker Hub 上的 Docker 映像(最新版本 = 0.9.1)。使用此处的说明:https ://wirecloud.readthedocs.io/en/latest/development/platform/themes/我们尝试遵循“基本主题”部分。但是目前还不清楚主题应该放在文件系统的哪个位置。

 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

我们得到错误:

...文件“/usr/local/lib/python2.7/site-packages/wirecloud/platform/themes.py”,第 82 行,在 get_theme_metadata 中引发 ValueError(“%s 不是有效的 WireCloud 主题”% theme_name ) ValueError: babblerTheme 不是有效的 WireCloud 主题

我们尝试将主题目录放在以下位置,但没有任何运气:

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

所有三个地方,同样的无信息错误。

这应该很容易,但我已经花了大半天的时间。我可以通过更改默认主题的内容来解决这个错误,但我希望在升级 Wirecloud 时会出现问题。

我们应该怎么做才能让 Wirecloud 选择我们的自定义主题?

4

2 回答 2

1

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.

于 2016-05-19T19:08:21.703 回答
0

解决了!!

步骤1

Wirecloud 需要您在 /usr/local/lib/python2.7/site-packages/ 之后以 python 点分隔文件名格式添加所有内容。

因此,如果您的自定义主题位于 /usr/local/lib/python2.7/site-packages/wirecloud/mytheme 目录中

然后 settings.py 需要条目: THEME_ACTIVE = "wirecloud.mytheme" 以便在启动时获取 mytheme 主题。

第2步

确保命令 python manage.py collectstatic --noinput 在启动时执行,就在重新启动 apache 网络服务器之前。我通过更改 docker-entrypoint.sh 启动文件在我的自定义 docker 映像中完成了此操作,如下所示:

#!/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

注意:python 命令的顺序很重要。带有 collectstatic 的行需要最后运行,否则静态资源不会提供给浏览器。

Wirecloud 开发人员,请更新文档,如果仅使用对 docker 映像执行微小更改的日志文件。这太痛苦了!

于 2016-05-17T18:39:29.317 回答