
from __future__ import unicode_literals

import os
import sys

from django.core.management.commands.compilemessages import compile_messages
from djblets.util.filesystem import is_exe_in_path


if __name__ == '__main__':
    if not is_exe_in_path('msgfmt'):
        raise RuntimeError('Could not find the "msgfmt" binary.')

    cwd = os.getcwd()
    os.chdir(os.path.realpath('reviewboard'))
    compile_messages(sys.stdout)
    os.chdir(cwd)


from __future__ import unicode_literals

import os
import sys

import django
from django.core.management import call_command

import reviewboard


if __name__ == '__main__':
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'reviewboard.settings')

    if hasattr(django, 'setup'):
        # Django >= 1.7
        django.setup()

    os.chdir(os.path.dirname(reviewboard.__file__))
    sys.exit(call_command('compilemessages', interactive=False, verbosity=2))

Fix building localization files on modern versions of Django.
Fix building localization files on modern versions of Django.

Our build-i18n script, which wraps the building of localization files,
had a failed import on modern versions of Django. We previously were
attempting to import and run the `compilemessages` command class itself.
Now we're doing it correctly by telling Django to invoke the command,
letting it handle the proper lookup and execution itself.

Testing Done:
Successfully built packages against Django 1.11.

Reviewed at https://reviews.reviewboard.org/r/10744/

  
  from __future__ import unicode_literals
  
  import os
  import sys
  
- from django.core.management.commands.compilemessages import compile_messages
- from djblets.util.filesystem import is_exe_in_path
+ import django
+ from django.core.management import call_command
+ 
+ import reviewboard
  
  
  if __name__ == '__main__':
+     os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'reviewboard.settings')
-     if not is_exe_in_path('msgfmt'):
-         raise RuntimeError('Could not find the "msgfmt" binary.')
  
+     if hasattr(django, 'setup'):
+         # Django >= 1.7
+         django.setup()
-     cwd = os.getcwd()
-     os.chdir(os.path.realpath('reviewboard'))
-     compile_messages(sys.stdout)
-     os.chdir(cwd)
  
+     os.chdir(os.path.dirname(reviewboard.__file__))
+     sys.exit(call_command('compilemessages', interactive=False, verbosity=2))
+ 
Fix building localization files on modern versions of Django.
## Code Before:

from __future__ import unicode_literals

import os
import sys

from django.core.management.commands.compilemessages import compile_messages
from djblets.util.filesystem import is_exe_in_path


if __name__ == '__main__':
    if not is_exe_in_path('msgfmt'):
        raise RuntimeError('Could not find the "msgfmt" binary.')

    cwd = os.getcwd()
    os.chdir(os.path.realpath('reviewboard'))
    compile_messages(sys.stdout)
    os.chdir(cwd)

## Instruction:
Fix building localization files on modern versions of Django.
## Code After:

from __future__ import unicode_literals

import os
import sys

import django
from django.core.management import call_command

import reviewboard


if __name__ == '__main__':
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'reviewboard.settings')

    if hasattr(django, 'setup'):
        # Django >= 1.7
        django.setup()

    os.chdir(os.path.dirname(reviewboard.__file__))
    sys.exit(call_command('compilemessages', interactive=False, verbosity=2))
