Exemple #1
0
def _get_default_config_parser(config_file_path):
    """Create a user settings file.

    Args:
        config_file_path (str): config file full name and path

    Returns:
        :obj:`pyrevit.userconfig.PyRevitConfig`: pyRevit config file handler
    """
    logger.debug(
        'Creating default config file at: {} '.format(CONFIG_FILE_PATH))
    touch(config_file_path)

    try:
        parser = PyRevitConfig(cfg_file_path=config_file_path)
    except Exception as read_err:
        # can not create default user config file under appdata folder
        logger.debug('Can not create config file under: {} | {}'.format(
            config_file_path, read_err))
        parser = PyRevitConfig()

    # set hard-coded values
    _set_hardcoded_config_values(parser)

    # save config into config file
    parser.save_changes()
    logger.debug('Default config saved to: {}'.format(config_file_path))

    return parser
Exemple #2
0
def verify_configs(config_file_path=None):
    """Create a user settings file.

    if config_file_path is not provided, configs will be in memory only

    Args:
        config_file_path (str, optional): config file full name and path

    Returns:
        :obj:`pyrevit.userconfig.PyRevitConfig`: pyRevit config file handler
    """
    if config_file_path:
        mlogger.debug('Creating default config file at: %s', config_file_path)
        coreutils.touch(config_file_path)

    try:
        parser = PyRevitConfig(cfg_file_path=config_file_path)
    except Exception as read_err:
        # can not create default user config file under appdata folder
        mlogger.warning('Can not create config file under: %s | %s',
                        config_file_path, read_err)
        parser = PyRevitConfig()

    return parser
Exemple #3
0
def verify_configs(config_file_path=None):
    """Create a user settings file.

    if config_file_path is not provided, configs will be in memory only

    Args:
        config_file_path (str, optional): config file full name and path

    Returns:
        :obj:`pyrevit.userconfig.PyRevitConfig`: pyRevit config file handler
    """
    if config_file_path:
        mlogger.debug('Creating default config file at: %s', config_file_path)
        touch(config_file_path)

    try:
        parser = PyRevitConfig(cfg_file_path=config_file_path)
    except Exception as read_err:
        # can not create default user config file under appdata folder
        mlogger.warning('Can not create config file under: %s | %s',
                        config_file_path, read_err)
        parser = PyRevitConfig()

    # set hard-coded values
    consts = TargetApps.Revit.PyRevitConsts
    # core section
    if not parser.has_section(consts.ConfigsCoreSection):
        parser.add_section(consts.ConfigsCoreSection)
    # checkupates
    if not parser.core.has_option(consts.ConfigsCheckUpdatesKey):
        parser.core.set_option(consts.ConfigsCheckUpdatesKey, False)
    # autoupdate
    if not parser.core.has_option(consts.ConfigsAutoUpdateKey):
        parser.core.set_option(consts.ConfigsAutoUpdateKey, False)
    # verbose
    if not parser.core.has_option(consts.ConfigsVerboseKey):
        parser.core.set_option(consts.ConfigsVerboseKey, True)
    # debug
    if not parser.core.has_option(consts.ConfigsDebugKey):
        parser.core.set_option(consts.ConfigsDebugKey, False)
    # filelogging
    if not parser.core.has_option(consts.ConfigsFileLoggingKey):
        parser.core.set_option(consts.ConfigsFileLoggingKey, False)
    # startuplogtimeout
    if not parser.core.has_option(consts.ConfigsStartupLogTimeoutKey):
        parser.core.set_option(consts.ConfigsStartupLogTimeoutKey, 10)
    # userextensions
    if not parser.core.has_option(consts.ConfigsUserExtensionsKey):
        parser.core.set_option(consts.ConfigsUserExtensionsKey, [])
    # compilecsharp
    if not parser.core.has_option(consts.ConfigsCompileCSharpKey):
        parser.core.set_option(consts.ConfigsCompileCSharpKey, True)
    # compilevb
    if not parser.core.has_option(consts.ConfigsCompileVBKey):
        parser.core.set_option(consts.ConfigsCompileVBKey, True)
    # loadbeta
    if not parser.core.has_option(consts.ConfigsLoadBetaKey):
        parser.core.set_option(consts.ConfigsLoadBetaKey, False)
    # rocketmode
    if not parser.core.has_option(consts.ConfigsRocketModeKey):
        parser.core.set_option(consts.ConfigsRocketModeKey, True)
    # bincache
    if not parser.core.has_option(consts.ConfigsBinaryCacheKey):
        parser.core.set_option(consts.ConfigsBinaryCacheKey, True)
    # usercanupdate
    if not parser.core.has_option(consts.ConfigsUserCanUpdateKey):
        parser.core.set_option(consts.ConfigsUserCanUpdateKey, True)
    # usercanextend
    if not parser.core.has_option(consts.ConfigsUserCanExtendKey):
        parser.core.set_option(consts.ConfigsUserCanExtendKey, True)
    # usercanconfig
    if not parser.core.has_option(consts.ConfigsUserCanConfigKey):
        parser.core.set_option(consts.ConfigsUserCanConfigKey, True)

    # usagelogging section
    if not parser.has_section(consts.ConfigsUsageLoggingSection):
        parser.add_section(consts.ConfigsUsageLoggingSection)
    # usagelogging active
    if not parser.usagelogging.has_option(consts.ConfigsUsageLoggingStatusKey):
        parser.usagelogging.set_option(consts.ConfigsUsageLoggingStatusKey,
                                       False)
    # usagelogging file
    if not parser.usagelogging.has_option(consts.ConfigsUsageLogFilePathKey):
        parser.usagelogging.set_option(consts.ConfigsUsageLogFilePathKey, "")
    # usagelogging server
    if not parser.usagelogging.has_option(consts.ConfigsUsageLogServerUrlKey):
        parser.usagelogging.set_option(consts.ConfigsUsageLogServerUrlKey, "")

    # save config into config file
    if config_file_path:
        parser.save_changes()
        mlogger.debug('Default config saved to: %s', config_file_path)

    return parser