Make flag and arg preparations stateless

This commit is contained in:
lash 2022-05-13 10:32:56 +00:00
parent 139e2772af
commit e5a18d1abf
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
5 changed files with 55 additions and 57 deletions

View File

@ -1,12 +1,12 @@
# standard imports ## standard imports
import os #import os
#
# local imports ## local imports
from .base import * #from .base import *
from .arg import process_flags #from .arg import process_flags
from .config import process_config #from .config import process_config
#
#
__script_dir = os.path.dirname(os.path.realpath(__file__)) #__script_dir = os.path.dirname(os.path.realpath(__file__))
data_dir = os.path.join(os.path.dirname(__script_dir), 'data') #data_dir = os.path.join(os.path.dirname(__script_dir), 'data')
config_dir = os.path.join(data_dir, 'config') #config_dir = os.path.join(data_dir, 'config')

View File

@ -1,17 +1,21 @@
# local imports def apply_flag(flag):
from .base import ChaindFlag flag.add('session')
flag.add('dispatch')
flag.add('socket')
flag.add('socket_client')
flag.add('token')
def process_flags(argparser, flags): flag.alias('chaind_base', 'session')
if flags & ChaindFlag.SESSION > 0: flag.alias('chaind_socket_client', 'session', 'socket', 'socket_client')
argparser.add_argument('--session-id', dest='session_id', type=str, help='Session to store state and data under')
argparser.add_argument('--runtime-dir', dest='runtime_dir', type=str, help='Directory to store volatile data')
argparser.add_argument('--data-dir', dest='data_dir', type=str, help='Directory to store persistent data')
if flags & ChaindFlag.SOCKET > 0: return flag
argparser.add_argument('--socket-path', dest='socket', type=str, help='UNIX socket path')
if flags & ChaindFlag.SOCKET_CLIENT > 0:
argparser.add_argument('--send-socket', dest='socket_send', action='store_true', help='Send to UNIX socket')
if flags & ChaindFlag.TOKEN > 0: def apply_arg(arg):
argparser.add_argument('--token-module', dest='token_module', type=str, help='Python module path to resolve tokens from identifiers') arg.add_long('session-id', 'session', help='Session to store state and data under')
arg.add_long('runtime-dir', 'session', help='Directory to store volatile data')
arg.add_long('data-dir', 'session', help='Directory to store persistent data')
arg.add_long('socket-path', 'socket', help='UNIX socket path')
arg.add_long('send-socket', 'socket_client', typ=bool, help='Send to UNIX socket')
arg.add_long('token-module', 'token', help='Python module path to resolve tokens from identifiers')
return arg

View File

@ -68,18 +68,13 @@ def process_session(settings, config):
settings.set('SESSION_RUNTIME_DIR', runtime_dir) settings.set('SESSION_RUNTIME_DIR', runtime_dir)
settings.set('SESSION_DIR', session_dir) settings.set('SESSION_DIR', session_dir)
settings.set('SESSION_DATA_DIR'], data_dir) settings.set('SESSION_DATA_DIR', data_dir)
settings.set('SESSION_ID', session_id) settings.set('SESSION_ID', session_id)
return settings return settings
def process_sync_interface(settings, config):
raise NotImplementedError('no sync interface implementation defined')
def process_sync(settings, config): def process_sync(settings, config):
settings = process_sync_interface(settings, config)
settings = process_sync_range(settings, config) settings = process_sync_range(settings, config)
return settings return settings
@ -137,24 +132,22 @@ def process_chaind_queue(settings, config):
return settings return settings
def process_settings(settings, config): #def process_settings(settings, config):
settings = process_common(settings, config) # if settings = include_queue:
# settings = process_queue_backend(settings, config)
if settings = include_queue: # if settings = include_sync:
settings = process_queue_backend(settings, config) # settings = process_sync_backend(settings, config)
if settings = include_sync: #
settings = process_sync_backend(settings, config) # settings = process_backend(settings, config)
# settings = process_session(settings, config)
settings = process_backend(settings, config) #
settings = process_session(settings, config) # if settings = include_sync:
# settings = process_sync(settings, config)
if settings = include_sync: # if settings = include_queue:
settings = process_sync(settings, config) # settings = process_chaind_queue(settings, config)
if settings = include_queue: # settings = process_dispatch(settings, config)
settings = process_chaind_queue(settings, config) # settings = process_token(settings, config)
settings = process_dispatch(settings, config) #
settings = process_token(settings, config) # settings = process_socket(settings, config)
#
settings = process_socket(settings, config) # return settings
return settings

View File

@ -1,6 +1,6 @@
chainlib~=0.2.0 chainlib~=0.3.0
chainqueue~=0.1.16 chainqueue~=0.1.17
chainsyncer~=0.4.9 chainsyncer~=0.4.11
confini~=0.6.0 confini~=0.6.1
funga~=0.5.2 funga~=0.5.2
pyxdg~=0.26 pyxdg~=0.26

View File

@ -1,6 +1,6 @@
[metadata] [metadata]
name = chaind name = chaind
version = 0.2.12 version = 0.2.13
description = Base package for chain queue service description = Base package for chain queue service
author = Louis Holbrook author = Louis Holbrook
author_email = dev@holbrook.no author_email = dev@holbrook.no
@ -30,6 +30,7 @@ packages =
# chaind.runnable # chaind.runnable
chaind.adapters chaind.adapters
chaind.unittest chaind.unittest
chaind.data
chaind.cli chaind.cli
#[options.entry_points] #[options.entry_points]