Move get state function to main module

This commit is contained in:
nolash 2021-09-29 07:27:39 +02:00
parent fae3258c72
commit 86592b837a
Signed by untrusted user who does not match committer: lash
GPG Key ID: 21D2E7BB88C2A746
3 changed files with 35 additions and 30 deletions

View File

@ -1,2 +1,3 @@
"""Initness reports the initialization state and entry-point variables for the contract migrations process of the CIC services deployment. """Initness reports the initialization state and entry-point variables for the contract migrations process of the CIC services deployment.
""" """
from .state import *

View File

@ -12,6 +12,9 @@ from http.server import (
# external imports # external imports
import confini import confini
# local imports
from initness import get_state
logging.basicConfig(level=logging.WARNING) logging.basicConfig(level=logging.WARNING)
logg = logging.getLogger() logg = logging.getLogger()
@ -47,36 +50,6 @@ config.dict_override(args_override, 'cli flag')
logg.debug('loaded config: {}\n'.format(config)) logg.debug('loaded config: {}\n'.format(config))
def get_state(state_store_dir):
init_path = os.path.join(state_store_dir, 'init')
init_level = 0
registry_address = None
try:
f = open(init_path, 'r')
init_level = f.read()
init_level = init_level.rstrip()
f.close()
except FileNotFoundError:
pass
registry_path = os.path.join(state_store_dir, 'registry')
try:
f = open(registry_path, 'r')
registry_address = f.read()
registry_address = registry_address.rstrip()
f.close()
except FileNotFoundError:
pass
o = {
'runlevel': init_level,
'registry': registry_address,
}
return o
class StateRequestHandler(BaseHTTPRequestHandler): class StateRequestHandler(BaseHTTPRequestHandler):
state_store_dir = None state_store_dir = None

View File

@ -0,0 +1,31 @@
# standard imports
import os
def get_state(state_store_dir):
init_path = os.path.join(state_store_dir, 'init')
init_level = 0
registry_address = None
try:
f = open(init_path, 'r')
init_level = f.read()
init_level = init_level.rstrip()
f.close()
except FileNotFoundError:
pass
registry_path = os.path.join(state_store_dir, 'registry')
try:
f = open(registry_path, 'r')
registry_address = f.read()
registry_address = registry_address.rstrip()
f.close()
except FileNotFoundError:
pass
o = {
'runlevel': init_level,
'registry': registry_address,
}
return o