userconfig
Handle reading and parsing, writing and saving of all user configurations.
This module handles the reading and writing of the pyRevit configuration files. It's been used extensively by pyRevit sub-modules. user_config is set up automatically in the global scope by this module and can be imported into scripts and other modules to access the default configurations.
All other modules use this module to query user config.
Examples:
from pyrevit.userconfig import user_config
user_config.add_section('newsection')
user_config.newsection.property = value
user_config.newsection.get_option('property', default_value)
user_config.save_changes()
The user_config object is also the destination for reading and writing
configuration by pyRevit scripts through :func:get_config
of
:mod:pyrevit.script
module. Here is the function source:
.. literalinclude:: ../../pyrevitlib/pyrevit/script.py :pyobject: get_config
Examples:
from pyrevit import script
cfg = script.get_config()
cfg.property = value
cfg.get_option('property', default_value)
script.save_config()
Attributes
DEFAULT_CSV_SEPARATOR = ','
module-attribute
mlogger = logger.get_logger(__name__)
module-attribute
CONSTS = PyRevit.PyRevitConsts
module-attribute
LOCAL_CONFIG_FILE = ''
module-attribute
ADMIN_CONFIG_FILE = ''
module-attribute
USER_CONFIG_FILE = ''
module-attribute
CONFIG_TYPE = 'Seed'
module-attribute
CONFIG_FILE = find_config_file(PYREVIT_APP_DIR)
module-attribute
user_config = PyRevitConfig(cfg_file_path=CONFIG_FILE, config_type=CONFIG_TYPE)
module-attribute
Classes
PyRevitConfig(cfg_file_path=None, config_type='Unknown')
Bases: PyRevitConfigParser
Provide read/write access to pyRevit configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cfg_file_path |
str
|
full path to config file to be used. |
None
|
config_type |
str
|
type of config file |
'Unknown'
|
Examples:
cfg = PyRevitConfig(cfg_file_path)
cfg.add_section('sectionname')
cfg.sectionname.property = value
cfg.sectionname.get_option('property', default_value)
cfg.save_changes()
Load settings from provided config file and setup parser.
Source code in pyrevitlib/pyrevit/userconfig.py
Attributes
config_type = config_type
instance-attribute
config_file
property
Current config file path.
environment
property
Environment section.
core
property
Core section.
routes
property
Routes section.
telemetry
property
Telemetry section.
bin_cache
property
writable
"Whether to use the cache for extensions.
check_updates
property
writable
Whether to check for updates.
auto_update
property
writable
Whether to automatically update pyRevit.
rocket_mode
property
writable
Whether to enable rocket mode.
log_level
property
writable
Logging level.
file_logging
property
writable
Whether to enable file logging.
startuplog_timeout
property
writable
Timeout for the startup log.
required_host_build
property
writable
Host build required to run the commands.
min_host_drivefreespace
property
writable
Minimum free space for running the commands.
load_beta
property
writable
Whether to load commands in beta.
cpython_engine_version
property
writable
CPython engine version to use.
user_locale
property
writable
User locale.
output_stylesheet
property
writable
Stylesheet used for output.
routes_host
property
writable
Routes API host.
routes_port
property
writable
API routes port.
load_core_api
property
writable
Whether to load pyRevit core api.
telemetry_utc_timestamp
property
writable
Whether to use UTC timestamps in telemetry.
telemetry_status
property
writable
Telemetry status.
telemetry_file_dir
property
writable
Telemetry file directory.
telemetry_server_url
property
writable
Telemetry server URL.
telemetry_include_hooks
property
writable
Whether to include hooks in telemetry.
apptelemetry_status
property
writable
Telemetry status.
apptelemetry_server_url
property
writable
App telemetry server URL.
apptelemetry_event_flags
property
writable
Telemetry event flags.
user_can_update
property
writable
Whether the user can update pyRevit repos.
user_can_extend
property
writable
Whether the user can manage pyRevit Extensions.
user_can_config
property
writable
Whether the user can access the configuration.
colorize_docs
property
writable
Whether to enable the document colorizer.
tooltip_debug_info
property
writable
Whether to append debug info on tooltips.
routes_server
property
writable
Whether the server routes are enabled.
respect_language_direction
property
writable
Whether the system respects the language direction.
is_readonly
property
bool: whether the config is read only.
Functions
get_config_file_hash()
Get calculated unique hash for this config.
Returns:
Type | Description |
---|---|
str
|
hash of the config. |
Source code in pyrevitlib/pyrevit/coreutils/configparser.py
has_section(section_name)
add_section(section_name)
get_section(section_name)
Get section with given name.
Raises:
Type | Description |
---|---|
AttributeError
|
if section is missing |
Source code in pyrevitlib/pyrevit/coreutils/configparser.py
remove_section(section_name)
Remove section from config.
Source code in pyrevitlib/pyrevit/coreutils/configparser.py
reload(cfg_file_path=None)
Reload config from original or given file.
Source code in pyrevitlib/pyrevit/coreutils/configparser.py
save(cfg_file_path=None)
Save config to original or given file.
Source code in pyrevitlib/pyrevit/coreutils/configparser.py
get_config_version()
Return version of config file used for change detection.
Returns:
Type | Description |
---|---|
str
|
hash of the config file |
get_thirdparty_ext_root_dirs(include_default=True)
Return a list of external extension directories set by the user.
Returns:
Type | Description |
---|---|
list[str]
|
External user extension directories. |
Source code in pyrevitlib/pyrevit/userconfig.py
get_ext_root_dirs()
Return a list of all extension directories.
Returns:
Type | Description |
---|---|
list[str]
|
user extension directories. |
Source code in pyrevitlib/pyrevit/userconfig.py
get_ext_sources()
Return a list of extension definition source files.
set_thirdparty_ext_root_dirs(path_list)
Updates list of external extension directories in config file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path_list |
list[str]
|
list of external extension paths |
required |
Source code in pyrevitlib/pyrevit/userconfig.py
get_current_attachment()
Return current pyRevit attachment.
Source code in pyrevitlib/pyrevit/userconfig.py
get_active_cpython_engine()
Return active cpython engine.
Source code in pyrevitlib/pyrevit/userconfig.py
set_active_cpython_engine(pyrevit_engine)
Set the active CPython engine.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pyrevit_engine |
PyRevitEngine
|
python engine to set as active |
required |
save_changes()
Save user config into associated config file.
Source code in pyrevitlib/pyrevit/userconfig.py
get_list_separator()
staticmethod
Get list separator defined in user os regional settings.
Source code in pyrevitlib/pyrevit/userconfig.py
Functions
find_config_file(target_path)
verify_configs(config_file_path=None)
Create a user settings file.
if config_file_path is not provided, configs will be in memory only
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config_file_path |
str
|
config file full name and path |
None
|
Returns:
Type | Description |
---|---|
PyRevitConfig
|
pyRevit config file handler |