
from __future__ import unicode_literals

import os
import sys

scripts_dir = os.path.abspath(os.path.dirname(__file__))

# Source root directory
sys.path.insert(0, os.path.abspath(os.path.join(scripts_dir, '..', '..')))

# Script config directory
sys.path.insert(0, os.path.join(scripts_dir, 'conf'))

from reviewboard.dependencies import django_version

import __main__
__main__.__requires__ = ['Django' + django_version]
import pkg_resources

from django.core.management import call_command


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

    ret = call_command('collectstatic', interactive=False, verbosity=2)
    sys.exit(ret)


from __future__ import unicode_literals

import os
import sys

scripts_dir = os.path.abspath(os.path.dirname(__file__))

# Source root directory
sys.path.insert(0, os.path.abspath(os.path.join(scripts_dir, '..', '..')))

# Script config directory
sys.path.insert(0, os.path.join(scripts_dir, 'conf'))

from reviewboard.dependencies import django_version

import __main__
__main__.__requires__ = ['Django' + django_version]
import pkg_resources

from django.core.management import call_command


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

    # This will raise a CommandError or call sys.exit(1) on failure.
    call_command('collectstatic', interactive=False, verbosity=2)

Fix building static media on Django 1.11.
Fix building static media on Django 1.11.

Our wrapper script for building static media attempted to honor the
exit code of the `collectstatic` management command, passing it along to
`sys.exit()` so that we wouldn't have a failure show up as a successful
result.

However, exit codes are never returned. Instead, we were always getting
`None` back, which Python helpfully converts to an exit code of 0. Any
failure would have been an explicit `sys.exit(1)` or a raised exception.
So what we were doing was pointless.

On Django 1.11, though, we actually got a result back: The result of
`stdout`. We were then passing this to `sys.exit()`, which Python was
converting to an exit code of 1, resulting in the command always
failing.

We now just exit normally without trying to be clever and helpful,
letting Django do its own thing.

Testing Done:
Tested building static media on Django 1.6 and 1.11.

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

  
  from __future__ import unicode_literals
  
  import os
  import sys
  
  scripts_dir = os.path.abspath(os.path.dirname(__file__))
  
  # Source root directory
  sys.path.insert(0, os.path.abspath(os.path.join(scripts_dir, '..', '..')))
  
  # Script config directory
  sys.path.insert(0, os.path.join(scripts_dir, 'conf'))
  
  from reviewboard.dependencies import django_version
  
  import __main__
  __main__.__requires__ = ['Django' + django_version]
  import pkg_resources
  
  from django.core.management import call_command
  
  
  if __name__ == '__main__':
      os.putenv('FORCE_BUILD_MEDIA', '1')
      os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'reviewboard.settings')
  
+     # This will raise a CommandError or call sys.exit(1) on failure.
-     ret = call_command('collectstatic', interactive=False, verbosity=2)
+     call_command('collectstatic', interactive=False, verbosity=2)
-     sys.exit(ret)
  
Fix building static media on Django 1.11.
## Code Before:

from __future__ import unicode_literals

import os
import sys

scripts_dir = os.path.abspath(os.path.dirname(__file__))

# Source root directory
sys.path.insert(0, os.path.abspath(os.path.join(scripts_dir, '..', '..')))

# Script config directory
sys.path.insert(0, os.path.join(scripts_dir, 'conf'))

from reviewboard.dependencies import django_version

import __main__
__main__.__requires__ = ['Django' + django_version]
import pkg_resources

from django.core.management import call_command


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

    ret = call_command('collectstatic', interactive=False, verbosity=2)
    sys.exit(ret)

## Instruction:
Fix building static media on Django 1.11.
## Code After:

from __future__ import unicode_literals

import os
import sys

scripts_dir = os.path.abspath(os.path.dirname(__file__))

# Source root directory
sys.path.insert(0, os.path.abspath(os.path.join(scripts_dir, '..', '..')))

# Script config directory
sys.path.insert(0, os.path.join(scripts_dir, 'conf'))

from reviewboard.dependencies import django_version

import __main__
__main__.__requires__ = ['Django' + django_version]
import pkg_resources

from django.core.management import call_command


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

    # This will raise a CommandError or call sys.exit(1) on failure.
    call_command('collectstatic', interactive=False, verbosity=2)
