Skip to content
Snippets Groups Projects
Commit 6dc1e0ad authored by yvesn's avatar yvesn
Browse files

obis_SSDM-6476: obis - split config into multiple parts

parent 526fbf49
No related branches found
No related tags found
No related merge requests found
...@@ -103,10 +103,6 @@ class ConfigEnv(object): ...@@ -103,10 +103,6 @@ class ConfigEnv(object):
self.add_param(ConfigParam(name='fileservice_url', private=False)) self.add_param(ConfigParam(name='fileservice_url', private=False))
self.add_param(ConfigParam(name='user', private=True)) self.add_param(ConfigParam(name='user', private=True))
self.add_param(ConfigParam(name='verify_certificates', private=True, is_json=True, default_value=True)) self.add_param(ConfigParam(name='verify_certificates', private=True, is_json=True, default_value=True))
self.add_param(ConfigParam(name='object_id', private=False, ignore_global=True))
self.add_param(ConfigParam(name='collection_id', private=False, ignore_global=True))
self.add_param(ConfigParam(name='data_set_type', private=False))
self.add_param(ConfigParam(name='data_set_properties', private=False, is_json=True))
self.add_param(ConfigParam(name='hostname', private=False)) self.add_param(ConfigParam(name='hostname', private=False))
self.add_param(ConfigParam(name='git_annex_hash_as_checksum', private=False, is_json=True, default_value=True)) self.add_param(ConfigParam(name='git_annex_hash_as_checksum', private=False, is_json=True, default_value=True))
...@@ -123,6 +119,18 @@ class ConfigEnv(object): ...@@ -123,6 +119,18 @@ class ConfigEnv(object):
return True return True
class CollectionEnv(ConfigEnv):
def initialize_params(self):
self.add_param(ConfigParam(name='collection_id', private=False, ignore_global=True))
class ObjectEnv(ConfigEnv):
def initialize_params(self):
self.add_param(ConfigParam(name='object_id', private=False, ignore_global=True))
class DataSetEnv(ConfigEnv): class DataSetEnv(ConfigEnv):
# TODO remove data_set from property names # TODO remove data_set from property names
...@@ -136,6 +144,7 @@ class RepositoryEnv(ConfigEnv): ...@@ -136,6 +144,7 @@ class RepositoryEnv(ConfigEnv):
def initialize_params(self): def initialize_params(self):
self.add_param(ConfigParam(name='external_dms_id', private=True)) self.add_param(ConfigParam(name='external_dms_id', private=True))
# TODO remove repository_
self.add_param(ConfigParam(name='repository_id', private=True)) self.add_param(ConfigParam(name='repository_id', private=True))
self.add_param(ConfigParam(name='data_set_id', private=False)) self.add_param(ConfigParam(name='data_set_id', private=False))
...@@ -166,6 +175,9 @@ class ConfigResolver(object): ...@@ -166,6 +175,9 @@ class ConfigResolver(object):
self.is_initialized = False self.is_initialized = False
self.config_file = config_file self.config_file = config_file
def set_location_search_order(self, order):
self.location_search_order = order
def initialize_location_cache(self): def initialize_location_cache(self):
env = self.env env = self.env
for k, v in env.locations.items(): for k, v in env.locations.items():
...@@ -297,11 +309,17 @@ class SettingsResolver(object): ...@@ -297,11 +309,17 @@ class SettingsResolver(object):
def __init__(self, location_resolver=None): def __init__(self, location_resolver=None):
self.repository_resolver = ConfigResolver(location_resolver=location_resolver, env=RepositoryEnv(), config_file='repository.json') self.repository_resolver = ConfigResolver(location_resolver=location_resolver, env=RepositoryEnv(), config_file='repository.json')
# TODO remove config_resolver in the end self.data_set_resolver = ConfigResolver(location_resolver=location_resolver, env=DataSetEnv(), config_file='data_set.json')
self.object_resolver = ConfigResolver(location_resolver=location_resolver, env=ObjectEnv(), config_file='object.json')
self.collection_resolver = ConfigResolver(location_resolver=location_resolver, env=CollectionEnv(), config_file='collection.json')
self.config_resolver = ConfigResolver(location_resolver=location_resolver, env=ConfigEnv()) self.config_resolver = ConfigResolver(location_resolver=location_resolver, env=ConfigEnv())
# TODO remove self.resolvers and all methods
self.resolvers = [] self.resolvers = []
self.resolvers.append(self.config_resolver)
self.resolvers.append(self.repository_resolver) self.resolvers.append(self.repository_resolver)
self.resolvers.append(self.data_set_resolver)
self.resolvers.append(self.object_resolver)
self.resolvers.append(self.collection_resolver)
self.resolvers.append(self.config_resolver)
def config_dict(self, local_only=False): def config_dict(self, local_only=False):
combined_dict = {} combined_dict = {}
......
...@@ -139,29 +139,29 @@ def init_handle_cleanup(result, object_id, collection_id, folder, data_mgmt): ...@@ -139,29 +139,29 @@ def init_handle_cleanup(result, object_id, collection_id, folder, data_mgmt):
return check_result("init_data", set_property(data_mgmt, 'collection_id', collection_id, False, False)) return check_result("init_data", set_property(data_mgmt, 'collection_id', collection_id, False, False))
# setting commands # settings commands
# obis [type] [get|set] [-g]? [-p]? [[key]+ | [key=value]+]?
class GetOrSet(click.ParamType): class SettingsGet(click.ParamType):
name = 'get_or_set' name = 'settings_get'
def convert(self, value, param, ctx): def convert(self, value, param, ctx):
result = {} try:
result['get'] = value == 'get' split = list(filter(lambda term: len(term) > 0, value.split(',')))
result['set'] = value == 'set' return split
if result['get'] == False and result['set'] == False: except:
self.fail(param=param, message='Parameter has to be \'get\' or \'set\'.') self._fail(param)
return result
def _fail(self, param):
self.fail(param=param, message='Settings must be in the format: key1, key2, ...')
class Settings(click.ParamType):
name = 'settings' class SettingsSet(click.ParamType):
name = 'settings_set'
def convert(self, value, param, ctx): def convert(self, value, param, ctx):
print(value)
try: try:
properties = {} settings = {}
split = list(filter(lambda term: len(term) > 0, value.split(','))) split = list(filter(lambda term: len(term) > 0, value.split(',')))
for setting in split: for setting in split:
setting_split = setting.split('=') setting_split = setting.split('=')
...@@ -169,8 +169,8 @@ class Settings(click.ParamType): ...@@ -169,8 +169,8 @@ class Settings(click.ParamType):
self._fail(param) self._fail(param)
key = setting_split[0] key = setting_split[0]
value = setting_split[1] value = setting_split[1]
properties[key] = value settings[key] = value
return properties return settings
except: except:
self._fail(param) self._fail(param)
...@@ -178,7 +178,7 @@ class Settings(click.ParamType): ...@@ -178,7 +178,7 @@ class Settings(click.ParamType):
self.fail(param=param, message='Settings must be in the format: key1=value1, key2=value2, ...') self.fail(param=param, message='Settings must be in the format: key1=value1, key2=value2, ...')
def _join_settings(setting_dicts): def _join_settings_set(setting_dicts):
joined = {} joined = {}
for setting_dict in setting_dicts: for setting_dict in setting_dicts:
for key, value in setting_dict.items(): for key, value in setting_dict.items():
...@@ -186,23 +186,15 @@ def _join_settings(setting_dicts): ...@@ -186,23 +186,15 @@ def _join_settings(setting_dicts):
return joined return joined
@cli.command() def _join_settings_get(setting_lists):
@click.argument('get_or_set', type=GetOrSet()) joined = []
@click.option('-g', '--is_global', default=False, is_flag=True, help='Configure global or local.') for setting_list in setting_lists:
@click.argument('settings', type=Settings(), nargs=-1) joined += setting_list
@click.pass_context return joined
def repository(ctx, get_or_set, is_global, settings):
print(get_or_set)
print(is_global)
settings_dict = _join_settings(settings)
print(settings_dict)
for prop, value in settings_dict.items():
data_mgmt = shared_data_mgmt(ctx.obj)
resolver = data_mgmt.settings_resolver.properties_resolver
config_internal_new(data_mgmt, resolver, is_global, False, prop, value)
def config_internal_new(data_mgmt, resolver, is_global, is_data_set_property, prop, value): # TODO also get for is_data_set_property
def _config_internal_new(data_mgmt, resolver, is_global, is_data_set_property, prop, value):
if is_global: if is_global:
resolver.set_location_search_order(['global']) resolver.set_location_search_order(['global'])
else: else:
...@@ -225,45 +217,176 @@ def config_internal_new(data_mgmt, resolver, is_global, is_data_set_property, pr ...@@ -225,45 +217,176 @@ def config_internal_new(data_mgmt, resolver, is_global, is_data_set_property, pr
return check_result("config", set_property(data_mgmt, prop, value, is_global, is_data_set_property)) return check_result("config", set_property(data_mgmt, prop, value, is_global, is_data_set_property))
def _set(ctx, settings):
is_global = ctx.obj['is_global']
data_mgmt = ctx.obj['data_mgmt']
resolver = ctx.obj['resolver']
is_data_set_property = ctx.obj['is_data_set_property'] == True
settings_dict = _join_settings_set(settings)
for prop, value in settings_dict.items():
_config_internal_new(data_mgmt, resolver, is_global, is_data_set_property, prop, value)
## repository -> properties.json
### repository_id
### external_dms_id
### data_set_id
## config -> config.json def _get(ctx, settings):
### fileservice_url is_global = ctx.obj['is_global']
### git_annex_hash_as_checksum data_mgmt = ctx.obj['data_mgmt']
### hostname resolver = ctx.obj['resolver']
### openbis_url if 'is_data_set_property' in ctx.obj:
### user is_data_set_property = ctx.obj['is_data_set_property']
### verify_certificates else:
is_data_set_property = False
settings_list = _join_settings_get(settings)
if len(settings_list) == 0:
settings_list = [None]
for prop in settings_list:
_config_internal_new(data_mgmt, resolver, is_global, is_data_set_property, prop, None)
## object -> config.json
### id
## collection -> config.json ## repository: repository_id, external_dms_id, data_set_id
### id
## data_set -> config.json @cli.group()
### type @click.option('-g', '--is_global', default=False, is_flag=True, help='Set/get global or local.')
### properties @click.pass_context
def repository(ctx, is_global):
ctx.obj['is_global'] = is_global
ctx.obj['data_mgmt'] = shared_data_mgmt(ctx.obj)
ctx.obj['resolver'] = ctx.obj['data_mgmt'].settings_resolver.repository_resolver
# TODO replace by multiple commands @repository.command('set')
@cli.command() @click.argument('settings', type=SettingsSet(), nargs=-1)
@click.option('-g', '--is_global', default=False, is_flag=True, help='Configure global or local.') @click.pass_context
def repository_set(ctx, settings):
_set(ctx, settings)
@repository.command('get')
@click.argument('settings', type=SettingsGet(), nargs=-1)
@click.pass_context
def repository_get(ctx, settings):
_get(ctx, settings)
## data_set: type, properties
@cli.group()
@click.option('-g', '--is_global', default=False, is_flag=True, help='Set/get global or local.')
@click.option('-p', '--is_data_set_property', default=False, is_flag=True, help='Configure data set property.') @click.option('-p', '--is_data_set_property', default=False, is_flag=True, help='Configure data set property.')
@click.argument('prop', default="")
@click.argument('value', default="")
@click.pass_context @click.pass_context
def config(ctx, is_global, is_data_set_property, prop, value): def data_set(ctx, is_global, is_data_set_property):
"""Configure the openBIS setup. ctx.obj['is_global'] = is_global
ctx.obj['is_data_set_property'] = is_data_set_property
ctx.obj['data_mgmt'] = shared_data_mgmt(ctx.obj)
ctx.obj['resolver'] = ctx.obj['data_mgmt'].settings_resolver.data_set_resolver
Configure the openBIS server url, the data set type, and the data set properties.
""" @data_set.command('set')
data_mgmt = shared_data_mgmt(ctx.obj) @click.argument('settings', type=SettingsSet(), nargs=-1)
config_internal(data_mgmt, is_global, is_data_set_property, prop, value) @click.pass_context
def data_set_set(ctx, settings):
_set(ctx, settings)
@data_set.command('get')
@click.argument('settings', type=SettingsGet(), nargs=-1)
@click.pass_context
def data_set_get(ctx, settings):
_get(ctx, settings)
## object: object_id
@cli.group()
@click.option('-g', '--is_global', default=False, is_flag=True, help='Set/get global or local.')
@click.pass_context
def object(ctx, is_global):
ctx.obj['is_global'] = is_global
ctx.obj['data_mgmt'] = shared_data_mgmt(ctx.obj)
ctx.obj['resolver'] = ctx.obj['data_mgmt'].settings_resolver.object_resolver
@object.command('set')
@click.argument('settings', type=SettingsSet(), nargs=-1)
@click.pass_context
def object_set(ctx, settings):
_set(ctx, settings)
@object.command('get')
@click.argument('settings', type=SettingsGet(), nargs=-1)
@click.pass_context
def object_get(ctx, settings):
_get(ctx, settings)
## collection: collection_id
@cli.group()
@click.option('-g', '--is_global', default=False, is_flag=True, help='Set/get global or local.')
@click.pass_context
def collection(ctx, is_global):
ctx.obj['is_global'] = is_global
ctx.obj['data_mgmt'] = shared_data_mgmt(ctx.obj)
ctx.obj['resolver'] = ctx.obj['data_mgmt'].settings_resolver.collection_resolver
@collection.command('set')
@click.argument('settings', type=SettingsSet(), nargs=-1)
@click.pass_context
def collection_set(ctx, settings):
_set(ctx, settings)
@collection.command('get')
@click.argument('settings', type=SettingsGet(), nargs=-1)
@click.pass_context
def collection_get(ctx, settings):
_get(ctx, settings)
## config: fileservice_url, git_annex_hash_as_checksum, hostname, openbis_url, user, verify_certificates
@cli.group()
@click.option('-g', '--is_global', default=False, is_flag=True, help='Set/get global or local.')
@click.pass_context
def config(ctx, is_global):
ctx.obj['is_global'] = is_global
ctx.obj['data_mgmt'] = shared_data_mgmt(ctx.obj)
ctx.obj['resolver'] = ctx.obj['data_mgmt'].settings_resolver.config_resolver
@config.command('set')
@click.argument('settings', type=SettingsSet(), nargs=-1)
@click.pass_context
def config_set(ctx, settings):
_set(ctx, settings)
@config.command('get')
@click.argument('settings', type=SettingsGet(), nargs=-1)
@click.pass_context
def config_get(ctx, settings):
_get(ctx, settings)
# TODO replace by multiple commands
# @cli.command()
# @click.option('-g', '--is_global', default=False, is_flag=True, help='Configure global or local.')
# @click.option('-p', '--is_data_set_property', default=False, is_flag=True, help='Configure data set property.')
# @click.argument('prop', default="")
# @click.argument('value', default="")
# @click.pass_context
# def config(ctx, is_global, is_data_set_property, prop, value):
# """Configure the openBIS setup.
# Configure the openBIS server url, the data set type, and the data set properties.
# """
# data_mgmt = shared_data_mgmt(ctx.obj)
# config_internal(data_mgmt, is_global, is_data_set_property, prop, value)
# repository commands: status, sync, commit, init, addref, removeref, init_analysis # repository commands: status, sync, commit, init, addref, removeref, init_analysis
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment