Merge lp:~widelands-dev/widelands-website/add_DISPLAY_to_update_help into lp:widelands-website

Proposed by kaputtnik
Status: Rejected
Rejected by: kaputtnik
Proposed branch: lp:~widelands-dev/widelands-website/add_DISPLAY_to_update_help
Merge into: lp:widelands-website
Diff against target: 29 lines (+12/-0)
1 file modified
wlhelp/management/commands/update_help.py (+12/-0)
To merge this branch: bzr merge lp:~widelands-dev/widelands-website/add_DISPLAY_to_update_help
Reviewer Review Type Date Requested Status
Widelands Developers Pending
Review via email: mp+295756@code.launchpad.net

Description of the change

Use DISPLAY=:1 for update_help.py because wl_map_object_info needs access to the x-server on DISPLAY:1. So

./manage.py update_help

runs without setting the environment variable before by hand.

To post a comment you must log in.
Revision history for this message
SirVer (sirver) wrote :

I suggest crashing if DISPLAY is unset and instead make sure it is set correctly in the cron script that will trigger this run. The proposed change is fine as well, but if we ever need to shell out to another graphical process again, we have to repeat the hack. The cron script is where all commands are triggered, so it seems a better place for it, IMHO.

Right now all django commands are run through /etc/cron.daily/django_regular_commands.

Revision history for this message
kaputtnik (franku) wrote :

I am not sure if unsetting DISPLAY is needed at all.

The cron script runs only the commands for the productive website, as i can see. I try it this evening to update the productive website and set the environment variable in the cron script.

Revision history for this message
kaputtnik (franku) wrote :

After i wrote you the PN a few days ago i have reverted the changes to /etc/cron.daily/django_regular_commands. I couldn't get it to work.

I have managed now to update the help by hand, except the update_help_pdf. The latter one complains about "Operation not permitted:" when writing the pdf (i don't know why, the file permissions seems to be ok). Trying to run the script as user www-data fails also.

So the current state is:
1. The Encyclopedia on the website is fine now
2. The economy graph pdf files are not updated/correct
3. There is currently no method available to get the help updated through a cron-job

What to do?

The proposed branch where tested on the alpha site and i think these changes are currently the only ones which should work for updating the help through a cron-job. Regarding unsetting DISPLAY i think it is not really needed, because setting/unsetting it through os.environ works not globally... but i haven't test it right now though.

The other possibility is to make a button/link on the encyclopedia main page to update the help. But running a cronjob is definitely better.

Revision history for this message
GunChleoc (gunchleoc) wrote :

There must be a configuration error with the paths somewhere - the "w" in "wlhelp" is missing for the image path links on the live website. I did a grep over trunk and didn't find any errors there, so it must be a configuration issue.

Expected link:
https://wl.widelands.org/wlmedia/wlhelp/img/atlanteans/atlanteans_headquarters/menu.png

Actual link:
https://wl.widelands.org/wlmedia/lhelp/img/atlanteans/atlanteans_headquarters/menu.png

Thanks for doing all this work - I'm a bit MIA right now, because the Gaelic Wikipedia urgently needs my help with some user interface stuff.

Revision history for this message
kaputtnik (franku) wrote :

Uhh i didn't checked if the output is really good :-( Thanks for looking into this.

I think i have found it... The MEDIA_ROOT path contained double slashes. I don't know why, but this causes the slice in line 154 of update_help.py to cut too many chars:

return '%s%s' % (MEDIA_URL, new_name[len(MEDIA_ROOT):])

This is fixed now for all STATIC strings in local_settings.py and the encyclopedia on the website is updated again.

You may notice that i removed a slash in between the "%s". I did that because MEDIA_URL contains a slash itself and putting in there a slash results in a doubleslash again.

Revision history for this message
GunChleoc (gunchleoc) wrote :

Thanks for cleaning up after me!

Running os.path.normpath(directory) should take care of any double slashes - this is how I fixed up things during the last code review round. Looks like we have missed a few :(

Are you still having problems with the pdf? Maybe it's also a path issue.

Revision history for this message
kaputtnik (franku) wrote :

> Running os.path.normpath(directory) should take care of any double slashes -
> this is how I fixed up things during the last code review round. Looks like we
> have missed a few :(
 I think having paths with double slashes should be fixed where they are build. Failures like this one would otherwise be triggered again and again when one writes new code.

> Are you still having problems with the pdf?
I have managed to fixed this too by renaming "media/wlhelp/network_graphs" and run

./manage.py update_help_pdf

again. This time it was running through without problems.

So all should be fine now on the productive website. What remains is then to manage the automatic update of the help...

Revision history for this message
GunChleoc (gunchleoc) wrote :

> > Running os.path.normpath(directory) should take care of any double slashes -
> > this is how I fixed up things during the last code review round. Looks like
> we
> > have missed a few :(
> I think having paths with double slashes should be fixed where they are
> build. Failures like this one would otherwise be triggered again and again
> when one writes new code.

Agreed - ron the normpath ove it at the place that it is built if possible

> > Are you still having problems with the pdf?
> I have managed to fixed this too by renaming "media/wlhelp/network_graphs" and
> run
>
> ./manage.py update_help_pdf
>
> again. This time it was running through without problems.

Looking good :)

> So all should be fine now on the productive website. What remains is then to
> manage the automatic update of the help...

I don't think we really need an automatic update here - this data doesn't change very often. Maybe as a wishlist bug?

Revision history for this message
kaputtnik (franku) wrote :

> Agreed - ron the normpath ove it at the place that it is built if possible

Hm, i don't know... running normpath over each path constant after it has been build?:

bd = "/path/to/some/thing/"
MEDIA = bd + "/extended/path/"
MEDIA = os.path.normpath(MEDIA)

Looks like the programmer doesn't trust himself :-D

> I don't think we really need an automatic update here - this data doesn't
> change very often. Maybe as a wishlist bug?

I have added a task for updating the encyclopedia to https://wl.widelands.org/wiki/ReleasingWidelands/

Nevertheless we should have a hint for the DISPLAY problem. The easiest way would be to modify the error message from:

"Error: Unable to execute 'wl_map_object_info' for generating the JSON files."

to:

"Error: Unable to execute 'wl_map_object_info' for generating the JSON files. Have you exported DISPLAY = ':1' before running update_help?"

Revision history for this message
GunChleoc (gunchleoc) wrote :

> "Error: Unable to execute 'wl_map_object_info' for generating the JSON files. Have you exported DISPLAY = ':1' before running update_help?"

+1

Unmerged revisions

407. By kaputtnik

add environment variable DISPLAY = :1 for update_help.py

406. By kaputtnik

merged with trunk

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'wlhelp/management/commands/update_help.py'
2--- wlhelp/management/commands/update_help.py 2016-05-22 11:35:57 +0000
3+++ wlhelp/management/commands/update_help.py 2016-05-25 18:51:24 +0000
4@@ -291,6 +291,14 @@
5 current_dir = os.path.dirname(os.path.realpath(__file__))
6 is_json_valid = False
7 os.chdir(WIDELANDS_SVN_DIR)
8+ # Because wl_map_object_info needs access to a graphical server, which is running at
9+ # DISPLAY :1 on the productive server, we set the environment variable
10+ # accordingly.
11+ display_set = False
12+ if not 'DISPLAY' in os.environ:
13+ # No DISPLAY set -> default on the server console
14+ display_set = True
15+ os.environ['DISPLAY'] = ':1'
16 try:
17 subprocess.check_call(
18 [os.path.normpath('wl_map_object_info'), json_directory])
19@@ -298,6 +306,10 @@
20 print(
21 "Error: Unable to execute 'wl_map_object_info' for generating the JSON files.")
22
23+ if display_set:
24+ # Unset DISPLAY
25+ os.environ.pop('DISPLAY')
26+
27 # Now we validate that they are indeed JSON files (syntax check only)
28 validator_script = os.path.normpath(
29 WIDELANDS_SVN_DIR + '/utils/validate_json.py')

Subscribers

People subscribed via source and target branches