示例#1
0
    def __init__(self, directive=None, sh_param=None, material=None, aeff=None, folder=None):

        if (directive is None) or (material is None):
            # If available, settings come from default.par file       
            default = utils.resolve_profile('default.par')
            if default is not None: 
                vals = self._read_values(default)
                if directive is None:
                    directive= vals['directive']
                    sh_param = vals['sh_param']
                    material = vals['material']
                    self.aeff = aeff
                elif material is None:
                    material = vals['material']
            
        self.directive = directive
        
        if isinstance(material, (list, tuple)):
            self.material = list(material)
        elif isinstance(material, str):
            self.material = [material]
        else:
            raise TypeError('Material must be a string or list of strings')
            
        if sh_param:
            self.sh_param = sh_param

        if aeff is not None:
            self.aeff = aeff
                
        if folder is None:
            self._folder='.'
        else:
            self._folder=folder
示例#2
0
文件: core.py 项目: hohlraum/ScatPy
    def __init__(self, folder=None, **kwargs):

        # If available, settings come from default.par file
        default = utils.resolve_profile("default.par")
        if default is not None:
            kwargs = dict(self._read_values(default).items() + kwargs.items())

        for (key, val) in kwargs.iteritems():
            if hasattr(self, key):
                setattr(self, key, val)
            else:
                raise AttributeError("Settings has no attribute %s" % key)
示例#3
0
文件: core.py 项目: dalerxli/ScatPy
    def __init__(self, folder=None, **kwargs):

        # If available, settings come from default.par file
        default = utils.resolve_profile('default.par')
        if default is not None:
            kwargs = dict(self._read_values(default).items() + kwargs.items())

        for (key, val) in kwargs.iteritems():
            if hasattr(self, key):
                setattr(self, key, val)
            else:
                raise AttributeError('Settings has no attribute %s' % key)
示例#4
0
文件: core.py 项目: hohlraum/ScatPy
def set_config(fname=None):
    """
    Select which configuration profile to use for ScatPy

    :param fname: The name of the file that contains the configuration
                  If None then load the default profile
                  
    Profiles are stored in Python script files.
    
    The search scheme is to first look for the file in the CWD, followed by
    the folder ~/.ScatPy/ and finally the subdiretory profiles/ relative to
    where the config.py module resides.
    """
    global config

    if fname is None:
        fname = "default.py"

    if not fname.endswith(".py"):
        fname += ".py"

    full_name = utils.resolve_profile(fname)

    if full_name is None:
        raise (IOError("Could not find configuration profile"))

    execfile(full_name, {}, config)

    # Remove any imported modules from config
    for (k, v) in config.items():
        if inspect.ismodule(v):
            del config[k]

    config["profile"] = os.path.abspath(full_name)

    # Associate the correct path style based on OS
    if config["os"].lower() == "unix" or config["os"].lower() == "mac":
        config["path_style"] = posixpath
    elif config["os"].lower() == "windows":
        config["path_style"] = ntpath
    else:
        raise ValueError("Unknown OS: %s" % config["os"])
示例#5
0
文件: core.py 项目: dalerxli/ScatPy
def set_config(fname=None):
    """
    Select which configuration profile to use for ScatPy

    :param fname: The name of the file that contains the configuration
                  If None then load the default profile
                  
    Profiles are stored in Python script files.
    
    The search scheme is to first look for the file in the CWD, followed by
    the folder ~/.ScatPy/ and finally the subdiretory profiles/ relative to
    where the config.py module resides.
    """
    global config

    if fname is None:
        fname = 'default.py'

    if not fname.endswith('.py'):
        fname += '.py'

    full_name = utils.resolve_profile(fname)

    if full_name is None:
        raise (IOError('Could not find configuration profile'))

    execfile(full_name, {}, config)

    # Remove any imported modules from config
    for (k, v) in config.items():
        if inspect.ismodule(v):
            del config[k]

    config['profile'] = os.path.abspath(full_name)

    # Associate the correct path style based on OS
    if config['os'].lower() == 'unix' or config['os'].lower() == 'mac':
        config['path_style'] = posixpath
    elif config['os'].lower() == 'windows':
        config['path_style'] = ntpath
    else:
        raise ValueError('Unknown OS: %s' % config['os'])