Source code for hylite.Parameters

#!/usr/bin/env python3

#    (c) Copyright 2013-2018 Murray Cox, Wandrille Duchemin, Pierre-Yves Dupont.
#
#
#    This file is part of HyLiTE.
#
#    HyLiTE is a free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License version 3 as published by
#    the Free Software Foundation.
#
#    HyLiTE is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with HyLiTE.  If not, see <http://www.gnu.org/licenses/>


#===============================#
# author: Wandrille Duchemin    #
#         Murray Cox            #
# last modified: 9 January 2018 #
#===============================#


def singleton(class_):
    instances = {}
    def getinstance(*args, **kwargs):
        if class_ not in instances:
            instances[class_] = class_(*args, **kwargs)
        return instances[class_]
    return getinstance


def isparam(x):
    '''Determine if x (variable name) is a parameter
    
    Args:
         - x (str): a variable name
    
    Returns:
        bool.
    '''
    return x.isupper()


[docs]@singleton class Parameters: def __init__(self): from . import params a = vars(params) self.arg = dict((x, a[x]) for x in filter(isparam, list(a.keys()))) return def set_param(self, param, value): '''Set a params to a value Args: - param (str): name of the parameter - value : value of the parameter ''' self.arg[param] = value return def get_param(self, param): '''get a param's value Args: - param (str): name of the parameter ''' return self.arg[param] def __del__(self): self.arg = {}