Ignore missing sites.json gracefully

This commit is contained in:
caryoscelus 2023-07-23 19:55:59 +00:00
parent 9d8be57025
commit 76d1b14eaf
2 changed files with 9 additions and 4 deletions

View file

@ -87,7 +87,11 @@ class Site(object):
# Load site settings from data/sites.json
def loadSettings(self, settings=None):
if not settings:
settings = json.load(open("%s/sites.json" % config.data_dir)).get(self.address)
try:
settings = json.load(open(f'{config.data_dir}/sites.json')).get(self.address)
except Exception as err:
logging.error(f'Error loading {config.data_dir}/sites.json: {err}')
settings = {}
if settings:
self.settings = settings
if "cache" not in settings:

View file

@ -31,17 +31,18 @@ class SiteManager(object):
@util.Noparallel()
def load(self, cleanup=True, startup=False):
from .Site import Site
self.log.info("Loading sites... (cleanup: %s, startup: %s)" % (cleanup, startup))
self.log.info(f'Loading sites... ({cleanup=}, {startup=})')
self.loaded = False
address_found = []
added = 0
load_s = time.time()
# Load new adresses
try:
json_path = "%s/sites.json" % config.data_dir
json_path = f"{config.data_dir}/sites.json"
data = json.load(open(json_path))
except Exception as err:
raise Exception("Unable to load %s: %s" % (json_path, err))
self.log.error(f"Unable to load {json_path}: {err}")
data = {}
sites_need = []