aboutsummaryrefslogtreecommitdiffstats
path: root/settings.py
diff options
context:
space:
mode:
authorJesús <heckyel@hyperbola.info>2020-12-15 21:14:27 -0500
committerJesús <heckyel@hyperbola.info>2020-12-15 21:14:27 -0500
commitf4b36a220d085080a881dbe2f63e51b2fb28a003 (patch)
tree8f3ec6d5ce90e7fb489e7c270ef986d84dc279b2 /settings.py
parentcf8e8ea5b10c00639d68b8a04a292bda454cc18d (diff)
downloadyt-local-f4b36a220d085080a881dbe2f63e51b2fb28a003.tar.lz
yt-local-f4b36a220d085080a881dbe2f63e51b2fb28a003.tar.xz
yt-local-f4b36a220d085080a881dbe2f63e51b2fb28a003.zip
pep8
Diffstat (limited to 'settings.py')
-rw-r--r--settings.py24
1 files changed, 17 insertions, 7 deletions
diff --git a/settings.py b/settings.py
index 0b6f578..0d52bc5 100644
--- a/settings.py
+++ b/settings.py
@@ -235,19 +235,23 @@ def comment_string(comment):
result += '# ' + line + '\n'
return result
+
def save_settings(settings_dict):
with open(settings_file_path, 'w', encoding='utf-8') as file:
for setting_name, setting_info in SETTINGS_INFO.items():
file.write(comment_string(setting_info['comment']) + setting_name + ' = ' + repr(settings_dict[setting_name]) + '\n\n')
+
def add_missing_settings(settings_dict):
result = default_settings()
result.update(settings_dict)
return result
+
def default_settings():
return {key: setting_info['default'] for key, setting_info in SETTINGS_INFO.items()}
+
def upgrade_to_2(settings_dict):
'''Upgrade to settings version 2'''
new_settings = settings_dict.copy()
@@ -260,6 +264,7 @@ def upgrade_to_2(settings_dict):
new_settings['settings_version'] = 2
return new_settings
+
def upgrade_to_3(settings_dict):
new_settings = settings_dict.copy()
if 'route_tor' in settings_dict:
@@ -267,17 +272,17 @@ def upgrade_to_3(settings_dict):
new_settings['settings_version'] = 3
return new_settings
+
upgrade_functions = {
1: upgrade_to_2,
2: upgrade_to_3,
}
+
def log_ignored_line(line_number, message):
print("WARNING: Ignoring settings.txt line " + str(node.lineno) + " (" + message + ")")
-
-
if os.path.isfile("settings.txt"):
print("Running in portable mode")
settings_dir = os.path.normpath('./')
@@ -356,16 +361,15 @@ else:
globals().update(current_settings_dict)
-
if route_tor:
print("Tor routing is ON")
else:
print("Tor routing is OFF - your Youtube activity is NOT anonymous")
+hooks = {}
-hooks = {}
def add_setting_changed_hook(setting, func):
'''Called right before new settings take effect'''
if setting in hooks:
@@ -382,11 +386,16 @@ def set_img_prefix(old_value=None, value=None):
img_prefix = '/'
else:
img_prefix = ''
+
+
set_img_prefix()
+
add_setting_changed_hook('proxy_images', set_img_prefix)
categories = ['network', 'interface', 'playback', 'other']
+
+
def settings_page():
if request.method == 'GET':
settings_by_category = {categ: [] for categ in categories}
@@ -395,9 +404,10 @@ def settings_page():
settings_by_category[categ].append(
(setting_name, setting_info, current_settings_dict[setting_name])
)
- return flask.render_template('settings.html',
- categories = categories,
- settings_by_category = settings_by_category,
+ return flask.render_template(
+ 'settings.html',
+ categories=categories,
+ settings_by_category=settings_by_category,
)
elif request.method == 'POST':
for key, value in request.values.items():