コード例 #1
0
ファイル: configure.py プロジェクト: SagesWang/pasta
def get_configuration(configfile=None):
    """Returns an instance of PastaUserSettings that reflects the current
    defaults based on:
        1. paths inferred from PASTA_SYSTEM_PATHS_CFGFILE
        2. any settings in `configfile` (these will overwrite the settings
            based on the defaults from pasta_home).
    """
    cfg = PastaUserSettings()
    set_configuration_from_defaults(cfg)

    if os.path.exists(PASTA_SYSTEM_PATHS_CFGFILE):
        paths_parser = ConfigParser.RawConfigParser()
        try:
            paths_parser.read(PASTA_SYSTEM_PATHS_CFGFILE)
        except:
            ### TODO: wrap up in messaging system
            sys.stderr.write("The specified configuration file %s cannot be read, the default settings are used instead.\n" % PASTA_SYSTEM_PATHS_CFGFILE)
        else:
            for tool_class in get_external_tool_classes():
                try:
                    new_path = paths_parser.get(tool_class.section_name, 'path')
                    if new_path:
                        tool_name = tool_class.section_name.split()[0] # TODO: this (taking the first word) is a bad idea we can get clashes in _DEFAULT_TOOLS_PATH
                        getattr(cfg, tool_name).path = new_path
                except:
                    ### TODO: wrap up in messaging system
                    sys.stderr.write("Section '%s' not found: using default settings instead.\n" % tool_class.section_name)

    if configfile is not None:
        if os.path.isfile(configfile):
            cfg.read_config_filepath(configfile)
        else:
            ### TODO: wrap up in messaging system
            sys.stderr.write("The specified configuration file %s cannot be found, the default settings are used instead.\n" % configfile)
    return cfg
コード例 #2
0
def init_pasta(pasta_home=None):
    """
    Sets the _DEFAULT_TOOLS_PATH.
    """
    global _DEFAULT_TOOLS_PATH
    bin_dir = pasta.pasta_tools_deploy_dir(default_to_dev_dir=True)
    if _DEFAULT_TOOLS_PATH is None:
        _DEFAULT_TOOLS_PATH = {}
    for i in get_external_tool_classes():
        tool_name = i.section_name.split()[0]
        _DEFAULT_TOOLS_PATH[tool_name] = os.path.join(bin_dir, tool_name)
        if platform.system() == 'Windows' and tool_name != 'opal':
            _DEFAULT_TOOLS_PATH[tool_name] += '.exe'
    _DEFAULT_TOOLS_PATH['opal'] += '.jar'
コード例 #3
0
ファイル: configure.py プロジェクト: SagesWang/pasta
def init_pasta(pasta_home=None):
    """
    Sets the _DEFAULT_TOOLS_PATH.
    """
    global _DEFAULT_TOOLS_PATH
    bin_dir = pasta.pasta_tools_deploy_dir(default_to_dev_dir=True)
    if _DEFAULT_TOOLS_PATH is None:
        _DEFAULT_TOOLS_PATH = {}
    for i in get_external_tool_classes():
        tool_name = i.section_name.split()[0]
        _DEFAULT_TOOLS_PATH[tool_name] = os.path.join(bin_dir, tool_name)
        if platform.system() == 'Windows' and tool_name != 'opal':
            _DEFAULT_TOOLS_PATH[tool_name] += '.exe'
    _DEFAULT_TOOLS_PATH['opal'] += '.jar'
コード例 #4
0
ファイル: configure.py プロジェクト: MGNute/pasta
def get_configuration(configfile=None):
    """Returns an instance of PastaUserSettings that reflects the current
    defaults based on:
        1. paths inferred from PASTA_SYSTEM_PATHS_CFGFILE
        2. any settings in `configfile` (these will overwrite the settings
            based on the defaults from pasta_home).
    """
    cfg = PastaUserSettings()
    set_configuration_from_defaults(cfg)

    if os.path.exists(PASTA_SYSTEM_PATHS_CFGFILE):
        print 'Reading system paths file: %s\n' % PASTA_SYSTEM_PATHS_CFGFILE
        paths_parser = ConfigParser.RawConfigParser()
        try:
            paths_parser.read(PASTA_SYSTEM_PATHS_CFGFILE)
        except:
            ### TODO: wrap up in messaging system
            sys.stderr.write(
                "The specified configuration file %s cannot be read, the default settings are used instead.\n"
                % PASTA_SYSTEM_PATHS_CFGFILE)
        else:
            for tool_class in get_external_tool_classes():
                try:
                    new_path = paths_parser.get(tool_class.section_name,
                                                'path')
                    if new_path:
                        tool_name = tool_class.section_name.split(
                        )[0]  # TODO: this (taking the first word) is a bad idea we can get clashes in _DEFAULT_TOOLS_PATH
                        getattr(cfg, tool_name).path = new_path
                except:
                    ### TODO: wrap up in messaging system
                    sys.stderr.write(
                        "Section '%s' not found: using default settings instead.\n"
                        % tool_class.section_name)

    if configfile is not None:
        print 'Reading config file: %s' % configfile
        if os.path.isfile(configfile):
            cfg.read_config_filepath(configfile)
        else:
            ### TODO: wrap up in messaging system
            sys.stderr.write(
                "The specified configuration file %s cannot be found, the default settings are used instead.\n"
                % configfile)
    return cfg