def setup_usage_logfile(session_id=None): """Sets up the usage logging default config and environment values.""" if not session_id: session_id = get_session_uuid() # default file path and name for usage logging filelogging_filename = FILE_LOG_FILENAME_TEMPLATE \ .format(PYREVIT_FILE_PREFIX, session_id, FILE_LOG_EXT) # default server url for usage logging usagelog_serverurl = '' # initialize env variables related to usage logging _init_usagelogging_envvars() # setup config section if does not exist if not user_config.has_section('usagelogging'): user_config.add_section('usagelogging') # GLOBAL SWITCH ------------------------------------------------------------ # setup default value for usage logging global switch ul_config = user_config.usagelogging usageloggingactive = ul_config.get_option('active', default_value=False) set_pyrevit_env_var(USAGELOG_STATE_ISC_KEYNAME, usageloggingactive) # FILE usage logging ------------------------------------------------------- # read or setup default values for file usage logging logfilepath = ul_config.get_option('logfilepath', default_value=PYREVIT_VERSION_APP_DIR) # check file usage logging config and setup destination if not logfilepath or is_blank(logfilepath): # if no config is provided, disable output _disable_file_usage_logging() else: # if config exists, create new usage log file under the same address if op.isdir(logfilepath): # if directory is valid logfile_fullpath = op.join(logfilepath, filelogging_filename) _setup_default_logfile(logfile_fullpath) else: # if not, show error and disable usage logging if usageloggingactive: logger.error('Provided usage log address does not exits or is ' 'not a directory. Usage logging disabled.') _disable_usage_logging() # SERVER usage logging ----------------------------------------------------- # read or setup default values for server usage logging logserverurl = ul_config.get_option('logserverurl', default_value=usagelog_serverurl) # check server usage logging config and setup destination if not logserverurl or is_blank(logserverurl): # if no config is provided, disable output _disable_server_usage_logging() else: # if config exists, setup server logging set_pyrevit_env_var(USAGELOG_SERVERURL_ISC_KEYNAME, logserverurl)
def config(self): from pyrevit.userconfig import user_config script_cfg_postfix = 'config' try: return user_config.get_section(COMMAND_NAME + script_cfg_postfix) except: return user_config.add_section(COMMAND_NAME + script_cfg_postfix)
def get_config(): """Create and return config section parser object for current script. Returns: :obj:`pyrevit.coreutils.configparser.PyRevitConfigSectionParser`: Config section parser object """ from pyrevit.userconfig import user_config script_cfg_postfix = 'config' try: return user_config.get_section(EXEC_PARAMS.command_name + script_cfg_postfix) except Exception: return user_config.add_section(EXEC_PARAMS.command_name + script_cfg_postfix)
def config(self): """ Returns a valid config manager for this extension. All config parameters will be saved in user config file. Returns: pyrevit.coreutils.configparser.PyRevitConfigSectionParser: Config section handler """ try: return user_config.get_section(self.ext_dirname) except: cfg_section = user_config.add_section(self.ext_dirname) self.config.disabled = not self._enable_default self.config.private_repo = self.builtin self.config.username = self.config.password = '' user_config.save_changes() return cfg_section
def get_config(section=None): """Create and return config section parser object for current script. Args: section (str, optional): config section name Returns: :obj:`pyrevit.coreutils.configparser.PyRevitConfigSectionParser`: Config section parser object """ from pyrevit.userconfig import user_config if not section: script_cfg_postfix = 'config' section = EXEC_PARAMS.command_name + script_cfg_postfix try: return user_config.get_section(section) except Exception: return user_config.add_section(section)
def setup_usage_logfile(session_id=None): """Sets up the usage logging default config and environment values.""" if not session_id: session_id = get_session_uuid() # default file path and name for usage logging filelogging_filename = FILE_LOG_FILENAME_TEMPLATE \ .format(PYREVIT_FILE_PREFIX, session_id, FILE_LOG_EXT) # default server url for usage logging usagelog_serverurl = 'https://design-tech-analytics.herokuapp.com/analytics/' \ 'pyRevit?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9' \ '.eyJhcHBsaWNhdGlvbiI6IldSSVRFX1dFV09SS1BZUkVWSVQiLCJpYXQiOjE1NDM1MTYxMzN9' \ '.9G-LxWLQYYWoOF3fBOl8Uf2p9pLjI5FNtBlYoXUemOE' # initialize env variables related to usage logging _init_usagelogging_envvars() # setup config section if does not exist if not user_config.has_section('usagelogging'): user_config.add_section('usagelogging') # GLOBAL SWITCH ------------------------------------------------------------ # setup default value for usage logging global switch ul_config = user_config.usagelogging usageloggingactive = ul_config.get_option('active', default_value=True) envvars.set_pyrevit_env_var(PYREVIT_USAGELOGSTATE_ENVVAR, usageloggingactive) # FILE usage logging ------------------------------------------------------- # read or setup default values for file usage logging logfilepath = ul_config.get_option('logfilepath', default_value=PYREVIT_VERSION_APP_DIR) # check file usage logging config and setup destination if not logfilepath or is_blank(logfilepath): # if no config is provided, disable output _disable_file_usage_logging() else: # if config exists, create new usage log file under the same address if usageloggingactive: if op.isdir(logfilepath): # if directory is valid logfile_fullpath = op.join(logfilepath, filelogging_filename) _setup_default_logfile(logfile_fullpath) else: # if not, show error and disable usage logging logger.error('Provided usage log address does not exits or is ' 'not a directory. Usage logging disabled.') _disable_usage_logging() # SERVER usage logging ----------------------------------------------------- # read or setup default values for server usage logging logserverurl = ul_config.get_option('logserverurl', default_value=usagelog_serverurl) # check server usage logging config and setup destination if not logserverurl or is_blank(logserverurl): # if no config is provided, disable output _disable_server_usage_logging() else: # if config exists, setup server logging envvars.set_pyrevit_env_var(PYREVIT_USAGELOGSERVER_ENVVAR, logserverurl)