def setup_environ(settings_mod, original_settings_path=None):
 if ('__init__.py' in settings_mod.__file__):
  p = os.path.dirname(settings_mod.__file__)
 else:
  p = settings_mod.__file__
 (project_directory, settings_filename) = os.path.split(p)
 if ((project_directory == os.curdir) or (not project_directory)):
  project_directory = os.getcwd()
 project_name = os.path.basename(project_directory)
 settings_name = os.path.splitext(settings_filename)[0]
 if settings_name.endswith('$py'):
  settings_name = settings_name[:(-3)]
 if original_settings_path:
  os.environ['DJANGO_SETTINGS_MODULE'] = original_settings_path
 else:
  os.environ['DJANGO_SETTINGS_MODULE'] = ('%s.%s' % (project_name, settings_name))
 sys.path.append(os.path.join(project_directory, os.pardir))
 project_module = import_module(project_name)
 sys.path.pop()
 return project_directory

def setup_environ ( settings_mod , original_settings_path = None ) : if ( '__init__.py' in settings_mod . __file__ ) : p = os . path . dirname ( settings_mod . __file__ ) else : p = settings_mod . __file__ ( project_directory , settings_filename ) = os . path . split ( p ) if ( ( project_directory == os . curdir ) or ( not project_directory ) ) : project_directory = os . getcwd ( ) project_name = os . path . basename ( project_directory ) settings_name = os . path . splitext ( settings_filename ) [ 0 ] if settings_name . endswith ( '$py' ) : settings_name = settings_name [ : ( - 3 ) ] if original_settings_path : os . environ [ 'DJANGO_SETTINGS_MODULE' ] = original_settings_path else : os . environ [ 'DJANGO_SETTINGS_MODULE' ] = ( '%s.%s' % ( project_name , settings_name ) ) sys . path . append ( os . path . join ( project_directory , os . pardir ) ) project_module = import_module ( project_name ) sys . path . pop ( ) return project_directory
configure the runtime environment .