Пример #1
0
def get_universal_data_file(file_id, file_ext, add_cmd_name=False):
    """Return filename to be used by a user script to store data.

    File name is generated in this format:
    ``pyRevit_{file_id}.{file_ext}``

    Example:
        >>> script.get_universal_data_file('mydata', 'data')
        '.../pyRevit_mydata.data'
        >>> script.get_universal_data_file('mydata', 'data', add_cmd_name=True)
        '.../pyRevit_Command Name_mydata.data'

    Universal data files are not cleaned up at pyRevit startup.
    Script should manage cleaning up these files.

    Args:
        file_id (str): unique id for the filename
        file_ext (str): file extension
        add_cmd_name (bool, optional): add command name to file name

    Returns:
        str: full file path
    """
    if add_cmd_name:
        script_file_id = '{}_{}'.format(EXEC_PARAMS.command_name, file_id)
    else:
        script_file_id = file_id

    return appdata.get_universal_data_file(script_file_id, file_ext)
Пример #2
0
 def get_universal_data_file(file_id, file_ext):
     """Returns a filename to be used by a user script to store data.
     These files are not marked by host Revit version and could be shared between all Revit versions and instances.
     Data files are saved in app directory and are NOT cleaned up at Revit restart.
     Script should manage cleaning up these data files.
     """
     from pyrevit.coreutils.appdata import get_universal_data_file
     script_file_id = '{}_{}'.format(COMMAND_NAME, file_id)
     return get_universal_data_file(script_file_id, file_ext)
Пример #3
0
def remove_leftover_temp_files():
    """4.8.5 had a bug that would create temp files with extension ..bak
    This cleans them up
    """
    univ_path = op.dirname(appdata.get_universal_data_file("X", 'bak'))
    if op.exists(univ_path):
        for entry in os.listdir(univ_path):
            if op.isfile(entry) and entry.lower().endswith('..bak'):
                appdata.garbage_data_file(op.join(univ_path, entry))
Пример #4
0
            CONFIG_TYPE = 'Seed'
            PyRevit.PyRevitConfigs.SeedConfig(False, ADMIN_CONFIG_FILE)
            CONFIG_FILE = find_config_file(PYREVIT_APP_DIR)
        # unless it's locked. then read that config file and set admin-mode
        else:
            CONFIG_TYPE = 'Admin'
            CONFIG_FILE = ADMIN_CONFIG_FILE
    # if a config file is available for user use that
    elif USER_CONFIG_FILE:
        CONFIG_TYPE = 'User'
        CONFIG_FILE = USER_CONFIG_FILE
    # if nothing can be found, make one
    else:
        CONFIG_TYPE = 'New'
        # setup config file name and path
        CONFIG_FILE = appdata.get_universal_data_file(file_id='config',
                                                      file_ext='ini')

    mlogger.debug('Using %s config file: %s', CONFIG_TYPE, CONFIG_FILE)

    # read config, or setup default config file if not available
    # this pushes reading settings at first import of this module.
    try:
        verify_configs(CONFIG_FILE)
        user_config = PyRevitConfig(cfg_file_path=CONFIG_FILE,
                                    config_type=CONFIG_TYPE)
        upgrade.upgrade_user_config(user_config)
        user_config.save_changes()
    except Exception as cfg_err:
        mlogger.debug('Can not read confing file at: %s | %s', CONFIG_FILE,
                      cfg_err)
        mlogger.debug('Using configs in memory...')