# Cache for redundant SQL queries
-cache = {}
+_cache = {}
##### Cache #####
def is_cache_initialized(key: str) -> bool:
- return key in cache
+ return key in _cache
def set_all_cache_key(key: str, rows: list, value: any):
# NOISY-DEBUG: print(f"DEBUG: key='{key}',rows()={len(rows)},value[]={type(value)} - CALLED!")
raise ValueError("Parameter key[]='{type(key)}' is not 'str'")
elif not is_cache_initialized(key):
# NOISY-DEBUG: print(f"DEBUG: Cache for key='{key}' not initialized.")
- cache[key] = {}
+ _cache[key] = {}
for sub in rows:
# NOISY-DEBUG: print(f"DEBUG: Setting key='{key}',sub[{type(sub)}]='{sub}'")
if isinstance(sub, tuple):
- cache[key][sub[0]] = value
+ _cache[key][sub[0]] = value
else:
print(f"WARNING: Unsupported type row[]='{type(row)}'")
print(f"WARNING: Bad method call, key='{key}' is not initialized yet.")
raise Exception(f"Cache for key='{key}' is not initialized, but function called")
- cache[key][sub] = value
+ _cache[key][sub] = value
def is_cache_key_set(key: str, sub: str) -> bool:
if type(key) != str:
print(f"WARNING: Bad method call, key='{key}' is not initialized yet.")
raise Exception(f"Cache for key='{key}' is not initialized, but function called")
- return sub in cache[key]
+ return sub in _cache[key]
import json
with open("config.json") as f:
- config = json.loads(f.read())
+ _config = json.loads(f.read())
def get(key: str) -> any:
# DEBUG: print(f"DEBUG: key[{type(key)}]={key} - CALLED!")
raise ValueError(f"Parameter key[]='{type(key)}' is not 'str'")
elif key == "":
raise ValueError("Parameter 'key' cannot be empty")
- elif not key in config:
- raise KeyError(f"key='{key}' does not exist in config array")
+ elif not key in _config:
+ raise KeyError(f"key='{key}' does not exist in _config array")
- # DEBUG: print(f"DEBUG: config[{key}]={config[key]} - EXIT!")
- return config[key]
\ No newline at end of file
+ # DEBUG: print(f"DEBUG: _config[{key}]={_config[key]} - EXIT!")
+ return _config[key]
# Found info from node, such as nodeinfo URL, detection mode that needs to be
# written to database. Both arrays must be filled at the same time or else
# update_instance_data() will fail
-instance_data = {
+_pending = {
# Detection mode: 'AUTO_DISCOVERY', 'STATIC_CHECKS' or 'GENERATOR'
# NULL means all detection methods have failed (maybe still reachable instance)
"detection_mode" : {},
raise ValueError("Parameter domain[]='{type(domain)}' is not 'str'")
elif domain == "":
raise ValueError(f"Parameter 'domain' cannot be empty")
- elif not key in instance_data:
- raise ValueError(f"key='{key}' not found in instance_data")
+ elif not key in _pending:
+ raise ValueError(f"key='{key}' not found in _pending")
elif not fba.is_primitive(value):
raise ValueError(f"value[]='{type(value)}' is not a primitive type")
# Set it
- instance_data[key][domain] = value
+ _pending[key][domain] = value
# DEBUG: print("DEBUG: EXIT!")
raise ValueError(f"Parameter 'domain' cannot be empty")
has_pending = False
- for key in instance_data:
- # DEBUG: print(f"DEBUG: key='{key}',domain='{domain}',instance_data[key]()='{len(instance_data[key])}'")
- if domain in instance_data[key]:
+ for key in _pending:
+ # DEBUG: print(f"DEBUG: key='{key}',domain='{domain}',_pending[key]()='{len(_pending[key])}'")
+ if domain in _pending[key]:
has_pending = True
break
# DEBUG: print(f"DEBUG: Updating nodeinfo for domain='{domain}' ...")
sql_string = ''
fields = list()
- for key in instance_data:
+ for key in _pending:
# DEBUG: print("DEBUG: key:", key)
- if domain in instance_data[key]:
- # DEBUG: print(f"DEBUG: Adding '{instance_data[key][domain]}' for key='{key}' ...")
- fields.append(instance_data[key][domain])
+ if domain in _pending[key]:
+ # DEBUG: print(f"DEBUG: Adding '{_pending[key][domain]}' for key='{key}' ...")
+ fields.append(_pending[key][domain])
sql_string += f" {key} = ?,"
fields.append(domain)
# DEBUG: print("DEBUG: Committing changes ...")
fba.connection.commit()
- # DEBUG: print("DEBUG: Deleting instance_data for domain:", domain)
- for key in instance_data:
+ # DEBUG: print("DEBUG: Deleting _pending for domain:", domain)
+ for key in _pending:
try:
# DEBUG: print("DEBUG: Deleting key:", key)
- del instance_data[key][domain]
+ del _pending[key][domain]
except:
pass