~widelands-dev/widelands-website/trunk

« back to all changes in this revision

Viewing changes to wlhelp/management/commands/update_help.py

  • Committer: kaputtnik
  • Date: 2019-03-31 11:08:21 UTC
  • mto: This revision was merged to the branch mainline in revision 531.
  • Revision ID: kaputtnik-20190331110821-1o6c8ebh1sag7xat
mv main files into mainpage directory; apply needed changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
import subprocess
27
27
import collections
28
28
 
29
 
from settings import MEDIA_ROOT, WIDELANDS_SVN_DIR, MEDIA_URL
 
29
from django.conf import settings
30
30
 
31
31
from widelandslib.tribe import *
32
32
from widelandslib.make_flow_diagram import make_all_subgraphs
45
45
        self._delete_old_media_dir(
46
46
            name)  # You can deactivate this line if you don't need to clean house.
47
47
 
48
 
        base_directory = os.path.normpath(WIDELANDS_SVN_DIR + '/data')
49
 
        json_directory = os.path.normpath(MEDIA_ROOT + '/map_object_info')
 
48
        base_directory = os.path.normpath(settings.WIDELANDS_SVN_DIR + '/data')
 
49
        json_directory = os.path.normpath(settings.MEDIA_ROOT + '/map_object_info')
50
50
 
51
51
        tribeinfo_file = open(os.path.normpath(
52
52
            json_directory + '/tribe_' + name + '.json'), 'r')
59
59
        self._to.descr = tribeinfo['tooltip']
60
60
        # copy icon
61
61
        dn = os.path.normpath('%s/wlhelp/img/%s/' %
62
 
                              (MEDIA_ROOT, tribeinfo['name']))
 
62
                              (settings.MEDIA_ROOT, tribeinfo['name']))
63
63
        try:
64
64
            os.makedirs(dn)
65
65
        except OSError, o:
69
69
        file = os.path.normpath(base_directory + '/' + tribeinfo['icon'])
70
70
        shutil.copy(file, new_name)
71
71
        self._to.icon_url = path.normpath(
72
 
            '%s/%s' % (MEDIA_URL, new_name[len(MEDIA_ROOT):]))
 
72
            '%s/%s' % (settings.MEDIA_URL, new_name[len(settings.MEDIA_ROOT):]))
73
73
        self._to.save()
74
74
 
75
75
    def parse(self, tribename, base_directory, json_directory):
117
117
 
118
118
        print('Deleting old media files...')
119
119
        sdir = os.path.normpath(os.path.join(
120
 
            MEDIA_ROOT, 'wlhelp/img', tribename))
 
120
            settings.MEDIA_ROOT, 'wlhelp/img', tribename))
121
121
        if os.path.exists(sdir):
122
122
            shutil.rmtree(sdir)
123
123
 
144
144
 
145
145
        """
146
146
        dn = os.path.normpath('%s/wlhelp/img/%s/%s/' %
147
 
                              (MEDIA_ROOT, self._to.name, name))
 
147
                              (settings.MEDIA_ROOT, self._to.name, name))
148
148
        try:
149
149
            os.makedirs(dn)
150
150
        except OSError, o:
153
153
        new_name = path.join(dn, fname)
154
154
        shutil.copy(file, new_name)
155
155
 
156
 
        return '%s%s' % (MEDIA_URL, new_name[len(MEDIA_ROOT):])
 
156
        return '%s%s' % (settings.MEDIA_URL, new_name[len(settings.MEDIA_ROOT):])
157
157
 
158
158
    def _parse_workers(self, base_directory, workersinfo):
159
159
        """Put the workers into the database."""
283
283
    help =\
284
284
        '''Regenerates and parses the json files in a current checkout. '''
285
285
 
286
 
    def handle(self, directory=os.path.normpath(WIDELANDS_SVN_DIR + '/data'), **kwargs):
 
286
    def handle(self, directory=os.path.normpath(settings.WIDELANDS_SVN_DIR + '/data'), **kwargs):
287
287
 
288
 
        json_directory = os.path.normpath(MEDIA_ROOT + '/map_object_info')
 
288
        json_directory = os.path.normpath(settings.MEDIA_ROOT + '/map_object_info')
289
289
 
290
290
        if not os.path.exists(json_directory):
291
291
            os.makedirs(json_directory)
295
295
        # First, we make sure that JSON files have been generated.
296
296
        current_dir = os.path.dirname(os.path.realpath(__file__))
297
297
        is_json_valid = False
298
 
        os.chdir(WIDELANDS_SVN_DIR)
 
298
        os.chdir(settings.WIDELANDS_SVN_DIR)
299
299
        try:
300
300
            subprocess.check_call(
301
301
                [os.path.normpath('wl_map_object_info'), json_directory])
306
306
 
307
307
        # Now we validate that they are indeed JSON files (syntax check only)
308
308
        validator_script = os.path.normpath(
309
 
            WIDELANDS_SVN_DIR + '/utils/validate_json.py')
 
309
            settings.WIDELANDS_SVN_DIR + '/utils/validate_json.py')
310
310
        if not os.path.isfile(validator_script):
311
311
            print("Wrong path for 'utils/validate_json.py': " +
312
312
                  validator_script + ' does not exist!')