2222from flask import (
2323 Flask ,
2424 abort ,
25+ current_app ,
2526 flash ,
2627 g ,
2728 make_response ,
@@ -133,17 +134,17 @@ def decorated_view(*args, **kwargs):
133134 has_password_enabled = g .datastore .data ['settings' ]['application' ].get ('password' ) or os .getenv ("SALTED_PASS" , False )
134135
135136 # Permitted
136- if request .endpoint == 'static_content' and request .view_args ['group' ] == 'styles' :
137+ if request .endpoint == 'static_content' and request .view_args and request . view_args ['group' ] == 'styles' :
137138 return func (* args , ** kwargs )
138139 # Permitted
139140 elif request .endpoint == 'diff_history_page' and g .datastore .data ['settings' ]['application' ].get ('shared_diff_access' ):
140141 return func (* args , ** kwargs )
141142 elif request .method in flask_login .config .EXEMPT_METHODS :
142143 return func (* args , ** kwargs )
143- elif g . app .config .get ('LOGIN_DISABLED' ):
144+ elif current_app .config .get ('LOGIN_DISABLED' ):
144145 return func (* args , ** kwargs )
145146 elif has_password_enabled and not current_user .is_authenticated :
146- return g . app .login_manager .unauthorized ()
147+ return current_app .login_manager .unauthorized ()
147148
148149 return func (* args , ** kwargs )
149150
@@ -165,7 +166,8 @@ def changedetection_app(config, datastore):
165166
166167 # Stop browser caching of assets
167168 app .config ['SEND_FILE_MAX_AGE_DEFAULT' ] = 0
168- app .config .exit = Event ()
169+ exit_event = Event ()
170+ app .config .exit = exit_event
169171
170172 app .config ['NEW_VERSION_AVAILABLE' ] = False
171173
@@ -182,8 +184,6 @@ def changedetection_app(config, datastore):
182184
183185 app .config ["notification_debug_log" ] = []
184186
185- app .config ['DATASTORE' ] = datastore
186-
187187 login_manager = flask_login .LoginManager (app )
188188 login_manager .login_view = 'login'
189189 app .secret_key = init_app_secret (config ['datastore_path' ])
@@ -322,7 +322,6 @@ def login():
322322
323323 @app .before_request
324324 def remember_app_and_datastore ():
325- g .app = app
326325 g .datastore = datastore
327326
328327 @app .before_request
@@ -1630,25 +1629,23 @@ def highlight_submit_ignore_url():
16301629
16311630
16321631 # @todo handle ctrl break
1633- threading .Thread (target = ticker_thread_check_time_launch_checks , args = ( app ,) ).start ()
1634- threading .Thread (target = notification_runner , args = ( app ,) ).start ()
1632+ threading .Thread (target = ticker_thread_check_time_launch_checks , kwargs = { ' app' : app , 'datastore' : datastore , 'exit_event' : exit_event } ).start ()
1633+ threading .Thread (target = notification_runner , kwargs = { ' app' : app , 'datastore' : datastore , 'exit_event' : exit_event } ).start ()
16351634
16361635 # Check for new release version, but not when running in test/build or pytest
16371636 if not os .getenv ("GITHUB_REF" , False ) and not strtobool (os .getenv ('DISABLE_VERSION_CHECK' , 'no' )):
1638- threading .Thread (target = check_for_new_version , args = ( app ,) ).start ()
1637+ threading .Thread (target = check_for_new_version , kwargs = { ' app' : app , 'datastore' : datastore , 'exit_event' : exit_event } ).start ()
16391638
16401639 return app
16411640
16421641
16431642# Check for new version and anonymous stats
1644- def check_for_new_version (app , url = "https://changedetection.io/check-ver.php" , delay_time = 86400 ):
1643+ def check_for_new_version (* , app , datastore , exit_event , url = "https://changedetection.io/check-ver.php" , delay_time = 86400 ):
16451644 import requests
16461645 import urllib3
16471646 urllib3 .disable_warnings (urllib3 .exceptions .InsecureRequestWarning )
16481647
1649- datastore = app .config ["DATASTORE" ]
1650-
1651- while not app .config .exit .is_set ():
1648+ while not exit_event .is_set ():
16521649 try :
16531650 r = requests .post (url ,
16541651 data = {'version' : __version__ ,
@@ -1667,13 +1664,13 @@ def check_for_new_version(app, url="https://changedetection.io/check-ver.php", d
16671664 pass
16681665
16691666 # Check daily
1670- app . config . exit .wait (delay_time )
1667+ exit_event .wait (delay_time )
16711668
16721669
1673- def notification_runner (app ):
1670+ def notification_runner (* , app , datastore , exit_event ):
16741671 from datetime import datetime
16751672 import json
1676- while not app . config . exit .is_set ():
1673+ while not exit_event .is_set ():
16771674 try :
16781675 # At the moment only one thread runs (single runner)
16791676 n_object = notification_q .get (block = False )
@@ -1687,8 +1684,6 @@ def notification_runner(app):
16871684
16881685 notification_debug_log = app .config ["notification_debug_log" ]
16891686
1690- datastore = app .config ["DATASTORE" ]
1691-
16921687 try :
16931688 from changedetectionio import notification
16941689 # Fallback to system config if not set
@@ -1720,12 +1715,10 @@ def notification_runner(app):
17201715 notification_debug_log = notification_debug_log [- 100 :]
17211716
17221717# Threaded runner, look for new watches to feed into the Queue.
1723- def ticker_thread_check_time_launch_checks (app ):
1718+ def ticker_thread_check_time_launch_checks (* , app , datastore , exit_event ):
17241719 import random
17251720 from changedetectionio import update_worker
17261721
1727- datastore = app .config ["DATASTORE" ]
1728-
17291722 proxy_last_called_time = {}
17301723
17311724 recheck_time_minimum_seconds = int (os .getenv ('MINIMUM_SECONDS_RECHECK_TIME' , 3 ))
@@ -1739,7 +1732,7 @@ def ticker_thread_check_time_launch_checks(app):
17391732 running_update_threads .append (new_worker )
17401733 new_worker .start ()
17411734
1742- while not app . config . exit .is_set ():
1735+ while not exit_event .is_set ():
17431736
17441737 # Get a list of watches by UUID that are currently fetching data
17451738 running_uuids = []
@@ -1835,4 +1828,4 @@ def ticker_thread_check_time_launch_checks(app):
18351828 time .sleep (1 )
18361829
18371830 # Should be low so we can break this out in testing
1838- app . config . exit .wait (1 )
1831+ exit_event .wait (1 )
0 commit comments