Snake case

main
Bob Mottram 2021-12-27 20:38:02 +00:00
parent 438dcce9e3
commit 3128c724a1
6 changed files with 162 additions and 155 deletions

View File

@ -21,7 +21,7 @@ from utils import get_cached_post_filename
from utils import load_json from utils import load_json
from utils import save_json from utils import save_json
from utils import fileLastModified from utils import fileLastModified
from utils import setConfigParam from utils import set_config_param
from utils import has_users_path from utils import has_users_path
from utils import get_full_domain from utils import get_full_domain
from utils import remove_id_ending from utils import remove_id_ending
@ -945,7 +945,7 @@ def setBrochMode(base_dir: str, domain_full: str, enabled: bool) -> None:
print('EX: Broch mode not enabled due to file write ' + str(ex)) print('EX: Broch mode not enabled due to file write ' + str(ex))
return return
setConfigParam(base_dir, "broch_mode", enabled) set_config_param(base_dir, "broch_mode", enabled)
def broch_modeLapses(base_dir: str, lapseDays: int) -> bool: def broch_modeLapses(base_dir: str, lapseDays: int) -> bool:
@ -976,7 +976,7 @@ def broch_modeLapses(base_dir: str, lapseDays: int) -> bool:
print('EX: broch_modeLapses allow file not deleted ' + print('EX: broch_modeLapses allow file not deleted ' +
str(allowFilename)) str(allowFilename))
if removed: if removed:
setConfigParam(base_dir, "broch_mode", False) set_config_param(base_dir, "broch_mode", False)
print('Broch mode has elapsed') print('Broch mode has elapsed')
return True return True
return False return False

205
daemon.py
View File

@ -283,7 +283,7 @@ from utils import first_paragraph_from_string
from utils import clearFromPostCaches from utils import clearFromPostCaches
from utils import contains_invalid_chars from utils import contains_invalid_chars
from utils import is_system_account from utils import is_system_account
from utils import setConfigParam from utils import set_config_param
from utils import get_config_param from utils import get_config_param
from utils import remove_id_ending from utils import remove_id_ending
from utils import undoLikesCollectionEntry from utils import undoLikesCollectionEntry
@ -5055,22 +5055,22 @@ class PubServer(BaseHTTPRequestHandler):
self.server.blogs_instance = False self.server.blogs_instance = False
self.server.news_instance = False self.server.news_instance = False
self.server.defaultTimeline = 'tlmedia' self.server.defaultTimeline = 'tlmedia'
setConfigParam(base_dir, set_config_param(base_dir,
"media_instance", "media_instance",
self.server.media_instance) self.server.media_instance)
setConfigParam(base_dir, set_config_param(base_dir,
"blogs_instance", "blogs_instance",
self.server.blogs_instance) self.server.blogs_instance)
setConfigParam(base_dir, set_config_param(base_dir,
"news_instance", "news_instance",
self.server.news_instance) self.server.news_instance)
else: else:
if self.server.media_instance: if self.server.media_instance:
self.server.media_instance = False self.server.media_instance = False
self.server.defaultTimeline = 'inbox' self.server.defaultTimeline = 'inbox'
setConfigParam(base_dir, set_config_param(base_dir,
"media_instance", "media_instance",
self.server.media_instance) self.server.media_instance)
# is this a news theme? # is this a news theme?
if isNewsThemeName(self.server.base_dir, if isNewsThemeName(self.server.base_dir,
@ -5086,22 +5086,22 @@ class PubServer(BaseHTTPRequestHandler):
self.server.blogs_instance = False self.server.blogs_instance = False
self.server.media_instance = False self.server.media_instance = False
self.server.defaultTimeline = 'tlfeatures' self.server.defaultTimeline = 'tlfeatures'
setConfigParam(base_dir, set_config_param(base_dir,
"media_instance", "media_instance",
self.server.media_instance) self.server.media_instance)
setConfigParam(base_dir, set_config_param(base_dir,
"blogs_instance", "blogs_instance",
self.server.blogs_instance) self.server.blogs_instance)
setConfigParam(base_dir, set_config_param(base_dir,
"news_instance", "news_instance",
self.server.news_instance) self.server.news_instance)
else: else:
if self.server.news_instance: if self.server.news_instance:
self.server.news_instance = False self.server.news_instance = False
self.server.defaultTimeline = 'inbox' self.server.defaultTimeline = 'inbox'
setConfigParam(base_dir, set_config_param(base_dir,
"news_instance", "news_instance",
self.server.media_instance) self.server.media_instance)
# change blog instance status # change blog instance status
if fields.get('blogs_instance'): if fields.get('blogs_instance'):
@ -5112,30 +5112,30 @@ class PubServer(BaseHTTPRequestHandler):
self.server.media_instance = False self.server.media_instance = False
self.server.news_instance = False self.server.news_instance = False
self.server.defaultTimeline = 'tlblogs' self.server.defaultTimeline = 'tlblogs'
setConfigParam(base_dir, set_config_param(base_dir,
"blogs_instance", "blogs_instance",
self.server.blogs_instance) self.server.blogs_instance)
setConfigParam(base_dir, set_config_param(base_dir,
"media_instance", "media_instance",
self.server.media_instance) self.server.media_instance)
setConfigParam(base_dir, set_config_param(base_dir,
"news_instance", "news_instance",
self.server.news_instance) self.server.news_instance)
else: else:
if self.server.blogs_instance: if self.server.blogs_instance:
self.server.blogs_instance = False self.server.blogs_instance = False
self.server.defaultTimeline = 'inbox' self.server.defaultTimeline = 'inbox'
setConfigParam(base_dir, set_config_param(base_dir,
"blogs_instance", "blogs_instance",
self.server.blogs_instance) self.server.blogs_instance)
# change instance title # change instance title
if fields.get('instanceTitle'): if fields.get('instanceTitle'):
currInstanceTitle = \ currInstanceTitle = \
get_config_param(base_dir, 'instanceTitle') get_config_param(base_dir, 'instanceTitle')
if fields['instanceTitle'] != currInstanceTitle: if fields['instanceTitle'] != currInstanceTitle:
setConfigParam(base_dir, 'instanceTitle', set_config_param(base_dir, 'instanceTitle',
fields['instanceTitle']) fields['instanceTitle'])
# change YouTube alternate domain # change YouTube alternate domain
if fields.get('ytdomain'): if fields.get('ytdomain'):
@ -5147,14 +5147,14 @@ class PubServer(BaseHTTPRequestHandler):
if '/' in newYTDomain: if '/' in newYTDomain:
newYTDomain = newYTDomain.split('/')[0] newYTDomain = newYTDomain.split('/')[0]
if '.' in newYTDomain: if '.' in newYTDomain:
setConfigParam(base_dir, set_config_param(base_dir,
'youtubedomain', 'youtubedomain',
newYTDomain) newYTDomain)
self.server.yt_replace_domain = \ self.server.yt_replace_domain = \
newYTDomain newYTDomain
else: else:
setConfigParam(base_dir, set_config_param(base_dir,
'youtubedomain', '') 'youtubedomain', '')
self.server.yt_replace_domain = None self.server.yt_replace_domain = None
# change twitter alternate domain # change twitter alternate domain
@ -5170,14 +5170,14 @@ class PubServer(BaseHTTPRequestHandler):
newTwitterDomain = \ newTwitterDomain = \
newTwitterDomain.split('/')[0] newTwitterDomain.split('/')[0]
if '.' in newTwitterDomain: if '.' in newTwitterDomain:
setConfigParam(base_dir, set_config_param(base_dir,
'twitterdomain', 'twitterdomain',
newTwitterDomain) newTwitterDomain)
self.server.twitter_replacement_domain = \ self.server.twitter_replacement_domain = \
newTwitterDomain newTwitterDomain
else: else:
setConfigParam(base_dir, set_config_param(base_dir,
'twitterdomain', '') 'twitterdomain', '')
self.server.twitter_replacement_domain = None self.server.twitter_replacement_domain = None
# change custom post submit button text # change custom post submit button text
@ -5187,13 +5187,13 @@ class PubServer(BaseHTTPRequestHandler):
if fields['customSubmitText'] != \ if fields['customSubmitText'] != \
currCustomSubmitText: currCustomSubmitText:
customText = fields['customSubmitText'] customText = fields['customSubmitText']
setConfigParam(base_dir, set_config_param(base_dir,
'customSubmitText', 'customSubmitText',
customText) customText)
else: else:
if currCustomSubmitText: if currCustomSubmitText:
setConfigParam(base_dir, set_config_param(base_dir,
'customSubmitText', '') 'customSubmitText', '')
# libretranslate URL # libretranslate URL
currLibretranslateUrl = \ currLibretranslateUrl = \
@ -5205,13 +5205,13 @@ class PubServer(BaseHTTPRequestHandler):
ltUrl = fields['libretranslateUrl'] ltUrl = fields['libretranslateUrl']
if '://' in ltUrl and \ if '://' in ltUrl and \
'.' in ltUrl: '.' in ltUrl:
setConfigParam(base_dir, set_config_param(base_dir,
'libretranslateUrl', 'libretranslateUrl',
ltUrl) ltUrl)
else: else:
if currLibretranslateUrl: if currLibretranslateUrl:
setConfigParam(base_dir, set_config_param(base_dir,
'libretranslateUrl', '') 'libretranslateUrl', '')
# libretranslate API Key # libretranslate API Key
currLibretranslateApiKey = \ currLibretranslateApiKey = \
@ -5221,30 +5221,30 @@ class PubServer(BaseHTTPRequestHandler):
if fields['libretranslateApiKey'] != \ if fields['libretranslateApiKey'] != \
currLibretranslateApiKey: currLibretranslateApiKey:
ltApiKey = fields['libretranslateApiKey'] ltApiKey = fields['libretranslateApiKey']
setConfigParam(base_dir, set_config_param(base_dir,
'libretranslateApiKey', 'libretranslateApiKey',
ltApiKey) ltApiKey)
else: else:
if currLibretranslateApiKey: if currLibretranslateApiKey:
setConfigParam(base_dir, set_config_param(base_dir,
'libretranslateApiKey', '') 'libretranslateApiKey', '')
# change instance short description # change instance short description
if fields.get('content_license_url'): if fields.get('content_license_url'):
if fields['content_license_url'] != \ if fields['content_license_url'] != \
self.server.content_license_url: self.server.content_license_url:
licenseStr = fields['content_license_url'] licenseStr = fields['content_license_url']
setConfigParam(base_dir, set_config_param(base_dir,
'content_license_url', 'content_license_url',
licenseStr) licenseStr)
self.server.content_license_url = \ self.server.content_license_url = \
licenseStr licenseStr
else: else:
licenseStr = \ licenseStr = \
'https://creativecommons.org/licenses/by/4.0' 'https://creativecommons.org/licenses/by/4.0'
setConfigParam(base_dir, set_config_param(base_dir,
'content_license_url', 'content_license_url',
licenseStr) licenseStr)
self.server.content_license_url = licenseStr self.server.content_license_url = licenseStr
# change instance short description # change instance short description
@ -5255,13 +5255,14 @@ class PubServer(BaseHTTPRequestHandler):
if fields['instanceDescriptionShort'] != \ if fields['instanceDescriptionShort'] != \
currInstanceDescriptionShort: currInstanceDescriptionShort:
iDesc = fields['instanceDescriptionShort'] iDesc = fields['instanceDescriptionShort']
setConfigParam(base_dir, set_config_param(base_dir,
'instanceDescriptionShort', 'instanceDescriptionShort',
iDesc) iDesc)
else: else:
if currInstanceDescriptionShort: if currInstanceDescriptionShort:
setConfigParam(base_dir, set_config_param(base_dir,
'instanceDescriptionShort', '') 'instanceDescriptionShort',
'')
# change instance description # change instance description
currInstanceDescription = \ currInstanceDescription = \
@ -5269,13 +5270,13 @@ class PubServer(BaseHTTPRequestHandler):
if fields.get('instanceDescription'): if fields.get('instanceDescription'):
if fields['instanceDescription'] != \ if fields['instanceDescription'] != \
currInstanceDescription: currInstanceDescription:
setConfigParam(base_dir, set_config_param(base_dir,
'instanceDescription', 'instanceDescription',
fields['instanceDescription']) fields['instanceDescription'])
else: else:
if currInstanceDescription: if currInstanceDescription:
setConfigParam(base_dir, set_config_param(base_dir,
'instanceDescription', '') 'instanceDescription', '')
# change email address # change email address
currentEmailAddress = getEmailAddress(actor_json) currentEmailAddress = getEmailAddress(actor_json)
@ -5560,8 +5561,9 @@ class PubServer(BaseHTTPRequestHandler):
show_node_info_accounts = True show_node_info_accounts = True
self.server.show_node_info_accounts = \ self.server.show_node_info_accounts = \
show_node_info_accounts show_node_info_accounts
setConfigParam(base_dir, "show_node_info_accounts", set_config_param(base_dir,
show_node_info_accounts) "show_node_info_accounts",
show_node_info_accounts)
show_node_info_version = False show_node_info_version = False
if fields.get('show_node_info_version'): if fields.get('show_node_info_version'):
@ -5569,8 +5571,9 @@ class PubServer(BaseHTTPRequestHandler):
show_node_info_version = True show_node_info_version = True
self.server.show_node_info_version = \ self.server.show_node_info_version = \
show_node_info_version show_node_info_version
setConfigParam(base_dir, "show_node_info_version", set_config_param(base_dir,
show_node_info_version) "show_node_info_version",
show_node_info_version)
verify_all_signatures = False verify_all_signatures = False
if fields.get('verifyallsignatures'): if fields.get('verifyallsignatures'):
@ -5578,8 +5581,8 @@ class PubServer(BaseHTTPRequestHandler):
verify_all_signatures = True verify_all_signatures = True
self.server.verify_all_signatures = \ self.server.verify_all_signatures = \
verify_all_signatures verify_all_signatures
setConfigParam(base_dir, "verify_all_signatures", set_config_param(base_dir, "verify_all_signatures",
verify_all_signatures) verify_all_signatures)
broch_mode = False broch_mode = False
if fields.get('broch_mode'): if fields.get('broch_mode'):
@ -5591,8 +5594,8 @@ class PubServer(BaseHTTPRequestHandler):
setBrochMode(self.server.base_dir, setBrochMode(self.server.base_dir,
self.server.domain_full, self.server.domain_full,
broch_mode) broch_mode)
setConfigParam(base_dir, "broch_mode", set_config_param(base_dir, "broch_mode",
broch_mode) broch_mode)
# shared item federation domains # shared item federation domains
siDomainUpdated = False siDomainUpdated = False
@ -5618,15 +5621,17 @@ class PubServer(BaseHTTPRequestHandler):
shareDomainList.replace('\n', ',') shareDomainList.replace('\n', ',')
sharedItemsField = \ sharedItemsField = \
"shared_items_federated_domains" "shared_items_federated_domains"
setConfigParam(base_dir, sharedItemsField, set_config_param(base_dir,
sharedItemsFormStr2) sharedItemsField,
sharedItemsFormStr2)
siDomainUpdated = True siDomainUpdated = True
else: else:
if fed_domains_str: if fed_domains_str:
sharedItemsField = \ sharedItemsField = \
"shared_items_federated_domains" "shared_items_federated_domains"
setConfigParam(base_dir, sharedItemsField, set_config_param(base_dir,
'') sharedItemsField,
'')
siDomainUpdated = True siDomainUpdated = True
if siDomainUpdated: if siDomainUpdated:
siDomains = sharedItemsFormStr.split('\n') siDomains = sharedItemsFormStr.split('\n')
@ -6219,8 +6224,8 @@ class PubServer(BaseHTTPRequestHandler):
if fields['low_bandwidth'] == 'on': if fields['low_bandwidth'] == 'on':
low_bandwidth = True low_bandwidth = True
if currLowBandwidth != low_bandwidth: if currLowBandwidth != low_bandwidth:
setConfigParam(base_dir, 'low_bandwidth', set_config_param(base_dir, 'low_bandwidth',
low_bandwidth) low_bandwidth)
self.server.low_bandwidth = low_bandwidth self.server.low_bandwidth = low_bandwidth
# save filtered words list # save filtered words list
@ -6400,9 +6405,9 @@ class PubServer(BaseHTTPRequestHandler):
newListsEnabled += name newListsEnabled += name
if newListsEnabled != self.server.lists_enabled: if newListsEnabled != self.server.lists_enabled:
self.server.lists_enabled = newListsEnabled self.server.lists_enabled = newListsEnabled
setConfigParam(self.server.base_dir, set_config_param(self.server.base_dir,
"lists_enabled", "lists_enabled",
newListsEnabled) newListsEnabled)
# save blocked user agents # save blocked user agents
user_agents_blocked = [] user_agents_blocked = []
@ -6424,8 +6429,8 @@ class PubServer(BaseHTTPRequestHandler):
if user_agents_blockedStr: if user_agents_blockedStr:
user_agents_blockedStr += ',' user_agents_blockedStr += ','
user_agents_blockedStr += ua user_agents_blockedStr += ua
setConfigParam(base_dir, 'user_agents_blocked', set_config_param(base_dir, 'user_agents_blocked',
user_agents_blockedStr) user_agents_blockedStr)
# save peertube instances list # save peertube instances list
peertube_instancesFile = \ peertube_instancesFile = \
@ -18809,7 +18814,7 @@ def runDaemon(content_license_url: str,
if not os.path.isdir(base_dir + '/accounts/news@' + domain): if not os.path.isdir(base_dir + '/accounts/news@' + domain):
print('Creating news inbox: news@' + domain) print('Creating news inbox: news@' + domain)
createNewsInbox(base_dir, domain, port, http_prefix) createNewsInbox(base_dir, domain, port, http_prefix)
setConfigParam(base_dir, "lists_enabled", "Murdoch press") set_config_param(base_dir, "lists_enabled", "Murdoch press")
# dict of known web crawlers accessing nodeinfo or the masto API # dict of known web crawlers accessing nodeinfo or the masto API
# and how many times they have been seen # and how many times they have been seen

View File

@ -69,7 +69,7 @@ from utils import remove_domain_port
from utils import get_port_from_domain from utils import get_port_from_domain
from utils import has_users_path from utils import has_users_path
from utils import get_full_domain from utils import get_full_domain
from utils import setConfigParam from utils import set_config_param
from utils import get_config_param from utils import get_config_param
from utils import get_domain_from_actor from utils import get_domain_from_actor
from utils import getNicknameFromActor from utils import getNicknameFromActor
@ -688,9 +688,10 @@ if base_dir.endswith('/'):
if args.libretranslateUrl: if args.libretranslateUrl:
if '://' in args.libretranslateUrl and \ if '://' in args.libretranslateUrl and \
'.' in args.libretranslateUrl: '.' in args.libretranslateUrl:
setConfigParam(base_dir, 'libretranslateUrl', args.libretranslateUrl) set_config_param(base_dir, 'libretranslateUrl', args.libretranslateUrl)
if args.libretranslateApiKey: if args.libretranslateApiKey:
setConfigParam(base_dir, 'libretranslateApiKey', args.libretranslateApiKey) set_config_param(base_dir, 'libretranslateApiKey',
args.libretranslateApiKey)
if args.posts: if args.posts:
if not args.domain: if not args.domain:
@ -994,7 +995,7 @@ if not os.path.isdir(base_dir + '/cache/announce'):
# set the theme in config.json # set the theme in config.json
theme_name = get_config_param(base_dir, 'theme') theme_name = get_config_param(base_dir, 'theme')
if not theme_name: if not theme_name:
setConfigParam(base_dir, 'theme', 'default') set_config_param(base_dir, 'theme', 'default')
theme_name = 'default' theme_name = 'default'
if not args.mediainstance: if not args.mediainstance:
@ -1024,23 +1025,23 @@ if not args.blogsinstance:
# set the instance title in config.json # set the instance title in config.json
title = get_config_param(base_dir, 'instanceTitle') title = get_config_param(base_dir, 'instanceTitle')
if not title: if not title:
setConfigParam(base_dir, 'instanceTitle', 'Epicyon') set_config_param(base_dir, 'instanceTitle', 'Epicyon')
# set the instance description in config.json # set the instance description in config.json
descFull = get_config_param(base_dir, 'instanceDescription') descFull = get_config_param(base_dir, 'instanceDescription')
if not descFull: if not descFull:
setConfigParam(base_dir, 'instanceDescription', set_config_param(base_dir, 'instanceDescription',
'Just another ActivityPub server') 'Just another ActivityPub server')
# set the short instance description in config.json # set the short instance description in config.json
descShort = get_config_param(base_dir, 'instanceDescriptionShort') descShort = get_config_param(base_dir, 'instanceDescriptionShort')
if not descShort: if not descShort:
setConfigParam(base_dir, 'instanceDescriptionShort', set_config_param(base_dir, 'instanceDescriptionShort',
'Just another ActivityPub server') 'Just another ActivityPub server')
if args.domain: if args.domain:
domain = args.domain domain = args.domain
setConfigParam(base_dir, 'domain', domain) set_config_param(base_dir, 'domain', domain)
if args.rss: if args.rss:
session = createSession(None) session = createSession(None)
@ -1056,7 +1057,7 @@ if args.onion:
if '://' in args.onion: if '://' in args.onion:
args.onion = args.onion.split('://')[1] args.onion = args.onion.split('://')[1]
onion_domain = args.onion onion_domain = args.onion
setConfigParam(base_dir, 'onion', onion_domain) set_config_param(base_dir, 'onion', onion_domain)
i2p_domain = None i2p_domain = None
if args.i2p_domain: if args.i2p_domain:
@ -1066,7 +1067,7 @@ if args.i2p_domain:
if '://' in args.i2p_domain: if '://' in args.i2p_domain:
args.onion = args.onion.split('://')[1] args.onion = args.onion.split('://')[1]
i2p_domain = args.i2p_domain i2p_domain = args.i2p_domain
setConfigParam(base_dir, 'i2p_domain', i2p_domain) set_config_param(base_dir, 'i2p_domain', i2p_domain)
if not args.language: if not args.language:
languageCode = get_config_param(base_dir, 'language') languageCode = get_config_param(base_dir, 'language')
@ -1080,30 +1081,30 @@ if not args.maxRegistrations:
maxRegistrations = get_config_param(base_dir, 'maxRegistrations') maxRegistrations = get_config_param(base_dir, 'maxRegistrations')
if not maxRegistrations: if not maxRegistrations:
maxRegistrations = 10 maxRegistrations = 10
setConfigParam(base_dir, 'maxRegistrations', str(maxRegistrations)) set_config_param(base_dir, 'maxRegistrations', str(maxRegistrations))
else: else:
maxRegistrations = int(maxRegistrations) maxRegistrations = int(maxRegistrations)
else: else:
maxRegistrations = args.maxRegistrations maxRegistrations = args.maxRegistrations
setConfigParam(base_dir, 'maxRegistrations', str(maxRegistrations)) set_config_param(base_dir, 'maxRegistrations', str(maxRegistrations))
# if this is the initial run then allow new registrations # if this is the initial run then allow new registrations
if not get_config_param(base_dir, 'registration'): if not get_config_param(base_dir, 'registration'):
if args.registration.lower() == 'open': if args.registration.lower() == 'open':
setConfigParam(base_dir, 'registration', 'open') set_config_param(base_dir, 'registration', 'open')
setConfigParam(base_dir, 'maxRegistrations', str(maxRegistrations)) set_config_param(base_dir, 'maxRegistrations', str(maxRegistrations))
setConfigParam(base_dir, 'registrationsRemaining', set_config_param(base_dir, 'registrationsRemaining',
str(maxRegistrations)) str(maxRegistrations))
if args.resetregistrations: if args.resetregistrations:
setConfigParam(base_dir, 'registrationsRemaining', str(maxRegistrations)) set_config_param(base_dir, 'registrationsRemaining', str(maxRegistrations))
print('Number of new registrations reset to ' + str(maxRegistrations)) print('Number of new registrations reset to ' + str(maxRegistrations))
# unique ID for the instance # unique ID for the instance
instance_id = get_config_param(base_dir, 'instance_id') instance_id = get_config_param(base_dir, 'instance_id')
if not instance_id: if not instance_id:
instance_id = createPassword(32) instance_id = createPassword(32)
setConfigParam(base_dir, 'instance_id', instance_id) set_config_param(base_dir, 'instance_id', instance_id)
print('Instance ID: ' + instance_id) print('Instance ID: ' + instance_id)
# get domain name from configuration # get domain name from configuration
@ -1160,7 +1161,7 @@ if args.federation_list:
': Federate with domains, not individual accounts') ': Federate with domains, not individual accounts')
sys.exit() sys.exit()
federation_list = args.federation_list.copy() federation_list = args.federation_list.copy()
setConfigParam(base_dir, 'federation_list', federation_list) set_config_param(base_dir, 'federation_list', federation_list)
else: else:
configFederationList = get_config_param(base_dir, 'federation_list') configFederationList = get_config_param(base_dir, 'federation_list')
if configFederationList: if configFederationList:
@ -2058,13 +2059,13 @@ if args.followRequestsList:
nickname = 'admin' nickname = 'admin'
if args.domain: if args.domain:
domain = args.domain domain = args.domain
setConfigParam(base_dir, 'domain', domain) set_config_param(base_dir, 'domain', domain)
if args.port: if args.port:
port = args.port port = args.port
setConfigParam(base_dir, 'port', port) set_config_param(base_dir, 'port', port)
if args.proxy_port: if args.proxy_port:
proxy_port = args.proxy_port proxy_port = args.proxy_port
setConfigParam(base_dir, 'proxy_port', proxy_port) set_config_param(base_dir, 'proxy_port', proxy_port)
if args.gnunet: if args.gnunet:
http_prefix = 'gnunet' http_prefix = 'gnunet'
if args.dat or args.hyper: if args.dat or args.hyper:
@ -2610,8 +2611,8 @@ if args.shared_items_federated_domains:
shared_items_federated_domains = [] shared_items_federated_domains = []
if args.shared_items_federated_domains: if args.shared_items_federated_domains:
fed_domains_str = args.shared_items_federated_domains fed_domains_str = args.shared_items_federated_domains
setConfigParam(base_dir, 'shared_items_federated_domains', set_config_param(base_dir, 'shared_items_federated_domains',
fed_domains_str) fed_domains_str)
else: else:
fed_domains_str = \ fed_domains_str = \
get_config_param(base_dir, 'shared_items_federated_domains') get_config_param(base_dir, 'shared_items_federated_domains')
@ -2811,8 +2812,8 @@ if args.testdata:
shutil.rmtree(base_dir + '/wfendpoints', shutil.rmtree(base_dir + '/wfendpoints',
ignore_errors=False, onerror=None) ignore_errors=False, onerror=None)
setConfigParam(base_dir, 'registrationsRemaining', set_config_param(base_dir, 'registrationsRemaining',
str(maxRegistrations)) str(maxRegistrations))
createPerson(base_dir, 'maxboardroom', domain, port, http_prefix, createPerson(base_dir, 'maxboardroom', domain, port, http_prefix,
True, False, password) True, False, password)
@ -2994,7 +2995,7 @@ if args.testdata:
federation_list, False, False) federation_list, False, False)
followerOfPerson(base_dir, nickname, domain, 'maxboardroom', domain_full, followerOfPerson(base_dir, nickname, domain, 'maxboardroom', domain_full,
federation_list, False, False) federation_list, False, False)
setConfigParam(base_dir, 'admin', nickname) set_config_param(base_dir, 'admin', nickname)
# set a lower bound to the maximum mentions # set a lower bound to the maximum mentions
# so that it can't be accidentally set to zero and disable replies # so that it can't be accidentally set to zero and disable replies
@ -3012,7 +3013,7 @@ if minimumvotes:
content_license_url = '' content_license_url = ''
if args.content_license_url: if args.content_license_url:
content_license_url = args.content_license_url content_license_url = args.content_license_url
setConfigParam(base_dir, 'content_license_url', content_license_url) set_config_param(base_dir, 'content_license_url', content_license_url)
else: else:
content_license_url = get_config_param(base_dir, 'content_license_url') content_license_url = get_config_param(base_dir, 'content_license_url')
@ -3141,7 +3142,7 @@ if low_bandwidth is not None:
user_agents_blocked = [] user_agents_blocked = []
if args.userAgentBlocks: if args.userAgentBlocks:
user_agents_blockedStr = args.userAgentBlocks user_agents_blockedStr = args.userAgentBlocks
setConfigParam(base_dir, 'user_agents_blocked', user_agents_blockedStr) set_config_param(base_dir, 'user_agents_blocked', user_agents_blockedStr)
else: else:
user_agents_blockedStr = \ user_agents_blockedStr = \
get_config_param(base_dir, 'user_agents_blocked') get_config_param(base_dir, 'user_agents_blocked')
@ -3153,7 +3154,7 @@ if user_agents_blockedStr:
lists_enabled = '' lists_enabled = ''
if args.lists_enabled: if args.lists_enabled:
lists_enabled = args.lists_enabled lists_enabled = args.lists_enabled
setConfigParam(base_dir, 'lists_enabled', lists_enabled) set_config_param(base_dir, 'lists_enabled', lists_enabled)
else: else:
lists_enabled = get_config_param(base_dir, 'lists_enabled') lists_enabled = get_config_param(base_dir, 'lists_enabled')
@ -3189,24 +3190,24 @@ if args.registration:
if args.registration.lower() == 'open': if args.registration.lower() == 'open':
registration = get_config_param(base_dir, 'registration') registration = get_config_param(base_dir, 'registration')
if not registration: if not registration:
setConfigParam(base_dir, 'registrationsRemaining', set_config_param(base_dir, 'registrationsRemaining',
str(maxRegistrations)) str(maxRegistrations))
else: else:
if registration != 'open': if registration != 'open':
setConfigParam(base_dir, 'registrationsRemaining', set_config_param(base_dir, 'registrationsRemaining',
str(maxRegistrations)) str(maxRegistrations))
setConfigParam(base_dir, 'registration', 'open') set_config_param(base_dir, 'registration', 'open')
print('New registrations open') print('New registrations open')
else: else:
setConfigParam(base_dir, 'registration', 'closed') set_config_param(base_dir, 'registration', 'closed')
print('New registrations closed') print('New registrations closed')
defaultCurrency = get_config_param(base_dir, 'defaultCurrency') defaultCurrency = get_config_param(base_dir, 'defaultCurrency')
if not defaultCurrency: if not defaultCurrency:
setConfigParam(base_dir, 'defaultCurrency', 'EUR') set_config_param(base_dir, 'defaultCurrency', 'EUR')
if args.defaultCurrency: if args.defaultCurrency:
if args.defaultCurrency == args.defaultCurrency.upper(): if args.defaultCurrency == args.defaultCurrency.upper():
setConfigParam(base_dir, 'defaultCurrency', args.defaultCurrency) set_config_param(base_dir, 'defaultCurrency', args.defaultCurrency)
print('Default currency set to ' + args.defaultCurrency) print('Default currency set to ' + args.defaultCurrency)
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -48,7 +48,7 @@ from utils import get_full_domain
from utils import validNickname from utils import validNickname
from utils import load_json from utils import load_json
from utils import save_json from utils import save_json
from utils import setConfigParam from utils import set_config_param
from utils import get_config_param from utils import get_config_param
from utils import refresh_newswire from utils import refresh_newswire
from utils import get_protocol_prefixes from utils import get_protocol_prefixes
@ -628,7 +628,7 @@ def createPerson(base_dir: str, nickname: str, domain: str, port: int,
if not get_config_param(base_dir, 'admin'): if not get_config_param(base_dir, 'admin'):
if nickname != 'news': if nickname != 'news':
# print(nickname+' becomes the instance admin and a moderator') # print(nickname+' becomes the instance admin and a moderator')
setConfigParam(base_dir, 'admin', nickname) set_config_param(base_dir, 'admin', nickname)
setRole(base_dir, nickname, domain, 'admin') setRole(base_dir, nickname, domain, 'admin')
setRole(base_dir, nickname, domain, 'moderator') setRole(base_dir, nickname, domain, 'moderator')
setRole(base_dir, nickname, domain, 'editor') setRole(base_dir, nickname, domain, 'editor')
@ -701,8 +701,8 @@ def createPerson(base_dir: str, nickname: str, domain: str, port: int,
copyfile(defaultBannerFilename, accountDir + '/banner.png') copyfile(defaultBannerFilename, accountDir + '/banner.png')
if nickname != 'news' and remainingConfigExists: if nickname != 'news' and remainingConfigExists:
registrationsRemaining -= 1 registrationsRemaining -= 1
setConfigParam(base_dir, 'registrationsRemaining', set_config_param(base_dir, 'registrationsRemaining',
str(registrationsRemaining)) str(registrationsRemaining))
savePersonQrcode(base_dir, nickname, domain, port) savePersonQrcode(base_dir, nickname, domain, port)
return privateKeyPem, publicKeyPem, newPerson, webfingerEndpoint return privateKeyPem, publicKeyPem, newPerson, webfingerEndpoint

View File

@ -61,7 +61,7 @@ from utils import is_group_account
from utils import get_actor_languages_list from utils import get_actor_languages_list
from utils import get_category_types from utils import get_category_types
from utils import get_supported_languages from utils import get_supported_languages
from utils import setConfigParam from utils import set_config_param
from utils import is_group_actor from utils import is_group_actor
from utils import date_string_to_seconds from utils import date_string_to_seconds
from utils import date_seconds_to_string from utils import date_seconds_to_string
@ -1723,8 +1723,8 @@ def testSharedItemsFederation(base_dir: str) -> None:
print("Alice and Bob agree to share items catalogs") print("Alice and Bob agree to share items catalogs")
assert os.path.isdir(aliceDir) assert os.path.isdir(aliceDir)
assert os.path.isdir(bobDir) assert os.path.isdir(bobDir)
setConfigParam(aliceDir, 'shared_items_federated_domains', bobAddress) set_config_param(aliceDir, 'shared_items_federated_domains', bobAddress)
setConfigParam(bobDir, 'shared_items_federated_domains', aliceAddress) set_config_param(bobDir, 'shared_items_federated_domains', aliceAddress)
print('*********************************************************') print('*********************************************************')
print('Alice sends a follow request to Bob') print('Alice sends a follow request to Bob')

View File

@ -501,16 +501,17 @@ def _create_config(base_dir: str) -> None:
save_json(config_json, config_filename) save_json(config_json, config_filename)
def setConfigParam(base_dir: str, variable_name: str, variable_value) -> None: def set_config_param(base_dir: str, variable_name: str,
variable_value) -> None:
"""Sets a configuration value """Sets a configuration value
""" """
_create_config(base_dir) _create_config(base_dir)
config_filename = base_dir + '/config.json' config_filename = base_dir + '/config.json'
configJson = {} config_json = {}
if os.path.isfile(config_filename): if os.path.isfile(config_filename):
configJson = load_json(config_filename) config_json = load_json(config_filename)
configJson[variable_name] = variable_value config_json[variable_name] = variable_value
save_json(configJson, config_filename) save_json(config_json, config_filename)
def get_config_param(base_dir: str, variable_name: str): def get_config_param(base_dir: str, variable_name: str):