Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def do_reload():
"""
This will reload uwsgi if it's available
"""
try:
import uwsgi
uwsgi.reload()
return
except ImportError:
pass
def auto_reload(request):
if defaults.WSGI_AUTO_RELOAD is True:
env = request.environ.get
if env('mod_wsgi.process_group') and env('SCRIPT_FILENAME'):
if int(env('mod_wsgi.script_reloading', 0)):
try:
if os.path.exists(env('SCRIPT_FILENAME')):
os.utime(env('SCRIPT_FILENAME'), None)
except OSError:
pass
if defaults.UWSGI_AUTO_RELOAD is True:
try:
import uwsgi
uwsgi.reload()
except ImportError:
pass
# Try auto-reloading via the WSGI daemon mode reload mechanism
if rosetta_settings.WSGI_AUTO_RELOAD and \
request.environ.has_key('mod_wsgi.process_group') and \
request.environ.get('mod_wsgi.process_group',None) and \
request.environ.has_key('SCRIPT_FILENAME') and \
int(request.environ.get('mod_wsgi.script_reloading', '0')):
try:
os.utime(request.environ.get('SCRIPT_FILENAME'), None)
except OSError:
pass
# Try auto-reloading via uwsgi daemon reload mechanism
if rosetta_settings.UWSGI_AUTO_RELOAD:
try:
import uwsgi
# pretty easy right?
uwsgi.reload()
except:
# we may not be running under uwsgi :P
pass
except:
request.session['rosetta_i18n_write'] = False
request.session['rosetta_i18n_pofile']=rosetta_i18n_pofile
# Retain query arguments
query_arg = ''
if 'query' in request.REQUEST:
query_arg = '?query=%s' %request.REQUEST.get('query')
if 'page' in request.GET:
if query_arg:
query_arg = query_arg + '&'
def get(self, request):
try:
import uwsgi
uwsgi.reload()
except ImportError:
pass # Probably the django started with runserver
return HttpResponseRedirect(reverse('rosetta-home'))
def change_code_gracefull_reload(sig):
if autoreload.code_changed():
uwsgi.reload()
except Exception as error:
# Try auto-reloading via the WSGI daemon mode reload mechanism
if rosetta_settings.WSGI_AUTO_RELOAD and \
request.environ.has_key('mod_wsgi.process_group') and \
request.environ.get('mod_wsgi.process_group',None) and \
request.environ.has_key('SCRIPT_FILENAME') and \
int(request.environ.get('mod_wsgi.script_reloading', '0')):
try:
os.utime(request.environ.get('SCRIPT_FILENAME'), None)
except OSError:
pass
# Try auto-reloading via uwsgi daemon reload mechanism
if rosetta_settings.UWSGI_AUTO_RELOAD:
try:
import uwsgi
# pretty easy right?
uwsgi.reload()
except:
# we may not be running under uwsgi :P
pass
except:
request.session['rosetta_i18n_write'] = False
request.session['rosetta_i18n_pofile']=rosetta_i18n_pofile
# Retain query arguments
query_arg = ''
if 'query' in request.REQUEST:
query_arg = '?query=%s' %request.REQUEST.get('query')
if 'page' in request.GET:
if query_arg:
query_arg = query_arg + '&'
DBSession.flush()
# Clear the settings cache unless there are multiple processes.
# We have no way of notifying the other processes that they need
# to clear their caches too, so we've just gotta let it play out
# until all the caches expire.
if not request.environ.get('wsgi.multiprocess', False):
app_globals.settings_cache.clear()
else:
# uWSGI provides an automagically included module
# that we can use to call a graceful restart of all
# the uwsgi processes.
# http://projects.unbit.it/uwsgi/wiki/uWSGIReload
try:
import uwsgi
uwsgi.reload()
except ImportError:
pass
# Try auto-reloading via the WSGI daemon mode reload mechanism
if rosetta_settings.WSGI_AUTO_RELOAD and \
'mod_wsgi.process_group' in request.environ and \
request.environ.get('mod_wsgi.process_group', None) and \
'SCRIPT_FILENAME' in request.environ and \
int(request.environ.get('mod_wsgi.script_reloading', '0')):
try:
os.utime(request.environ.get('SCRIPT_FILENAME'), None)
except OSError:
pass
# Try auto-reloading via uwsgi daemon reload mechanism
if rosetta_settings.UWSGI_AUTO_RELOAD:
try:
import uwsgi
# pretty easy right?
uwsgi.reload()
except:
# we may not be running under uwsgi :P
pass
except:
storage.set('rosetta_i18n_write', False)
storage.set('rosetta_i18n_pofile', rosetta_i18n_pofile)
# Retain query arguments
query_arg = '?_next=1'
if 'query' in request.GET or 'query' in request.POST:
query_arg += '&query=%s' % request.REQUEST.get('query')
if 'page' in request.GET:
query_arg += '&page=%d&_next=1' % int(request.GET.get('page'))
return HttpResponseRedirect(reverse('rosetta-home') + iri_to_uri(query_arg))
rosetta_i18n_lang_name = _(storage.get('rosetta_i18n_lang_name'))