old_contents: #!/usr/bin/env python
  
  import sys
  import os
  
  
  def _set_source_root_parent(source_root_parent):
      """
      add everything under `source_root_parent` to the list of source roots
      e.g. if you call this with param 'submodules'
      and you have the file structure
  
      project/
          submodules/
              foo-src/
                  foo/
              bar-src/
                  bar/
  
      (where foo and bar are python modules)
      then foo and bar would become top-level importable
  
      """
      filedir = os.path.dirname(__file__)
      submodules_list = os.listdir(os.path.join(filedir, source_root_parent))
      for d in submodules_list:
          if d == "__init__.py" or d == '.' or d == '..':
              continue
          sys.path.insert(1, os.path.join(filedir, source_root_parent, d))
  
      sys.path.append(os.path.join(filedir, source_root_parent))
  
  
  def _set_source_root(source_root):
      filedir = os.path.dirname(__file__)
      sys.path.insert(1, os.path.join(filedir, source_root))
  
  
  def init_hq_python_path():
      _set_source_root_parent('submodules')
      _set_source_root(os.path.join('corehq', 'ex-submodules'))
      _set_source_root(os.path.join('custom', '_legacy'))
  
  if __name__ == "__main__":
      init_hq_python_path()
  
      # important to apply gevent monkey patches before running any other code
      # applying this later can lead to inconsistencies and threading issues
      # but compressor doesn't like it
      # ('module' object has no attribute 'poll' which has to do with
      # gevent-patching subprocess)
      GEVENT_COMMANDS = (
          'bihar_run_calcs',
          'mvp_force_update',
          'run_gunicorn',
          'preindex_everything',
          'prime_views',
          'ptop_preindex',
          'sync_prepare_couchdb_multi',
          'sync_couchdb',
      )
      if len(sys.argv) > 1 and sys.argv[1] in GEVENT_COMMANDS:
          from restkit.session import set_session; set_session("gevent")
          from gevent.monkey import patch_all; patch_all(subprocess=True)
          from psycogreen.gevent import patch_psycopg; patch_psycopg()
  
      os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
      from django.core.management import execute_from_command_line
      execute_from_command_line(sys.argv)
  
new_contents: #!/usr/bin/env python
  
  import sys
  import os
  import mimetypes
  
  
  def _set_source_root_parent(source_root_parent):
      """
      add everything under `source_root_parent` to the list of source roots
      e.g. if you call this with param 'submodules'
      and you have the file structure
  
      project/
          submodules/
              foo-src/
                  foo/
              bar-src/
                  bar/
  
      (where foo and bar are python modules)
      then foo and bar would become top-level importable
  
      """
      filedir = os.path.dirname(__file__)
      submodules_list = os.listdir(os.path.join(filedir, source_root_parent))
      for d in submodules_list:
          if d == "__init__.py" or d == '.' or d == '..':
              continue
          sys.path.insert(1, os.path.join(filedir, source_root_parent, d))
  
      sys.path.append(os.path.join(filedir, source_root_parent))
  
  
  def _set_source_root(source_root):
      filedir = os.path.dirname(__file__)
      sys.path.insert(1, os.path.join(filedir, source_root))
  
  
  def init_hq_python_path():
      _set_source_root_parent('submodules')
      _set_source_root(os.path.join('corehq', 'ex-submodules'))
      _set_source_root(os.path.join('custom', '_legacy'))
  
  if __name__ == "__main__":
      init_hq_python_path()
  
      # important to apply gevent monkey patches before running any other code
      # applying this later can lead to inconsistencies and threading issues
      # but compressor doesn't like it
      # ('module' object has no attribute 'poll' which has to do with
      # gevent-patching subprocess)
      GEVENT_COMMANDS = (
          'bihar_run_calcs',
          'mvp_force_update',
          'run_gunicorn',
          'preindex_everything',
          'prime_views',
          'ptop_preindex',
          'sync_prepare_couchdb_multi',
          'sync_couchdb',
      )
      if len(sys.argv) > 1 and sys.argv[1] in GEVENT_COMMANDS:
          from restkit.session import set_session; set_session("gevent")
          from gevent.monkey import patch_all; patch_all(subprocess=True)
          from psycogreen.gevent import patch_psycopg; patch_psycopg()
  
      # workaround for https://github.com/smore-inc/tinys3/issues/33
      mimetypes.init()
  
      os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
      from django.core.management import execute_from_command_line
      execute_from_command_line(sys.argv)
  
subject: initialize mimetype