def create_symbolic_links(): """Create symbolic links for files and dirs, following what's stored on the config file.""" dot_files_dir = read_config( 'dirs', 'dotfiles', os.path.realpath(os.path.join(os.path.dirname(__file__), '../dotfiles'))) if not os.path.exists(dot_files_dir): LOGGER.warning("The directory '%s' does not exist", dot_files_dir) return LOGGER.info("Directory with dot files: '%s'", dot_files_dir) LOGGER.info("Creating links for files in [%s]", SECTION_SYMLINKS_FILES) links = {} cut = len(dot_files_dir) + 1 for root, _, files in os.walk(dot_files_dir): for one_file in files: source_file = os.path.join(root, one_file) key = source_file[cut:] raw_link_name = read_config(SECTION_SYMLINKS_FILES, key, '') links[key] = (source_file, raw_link_name) # http://stackoverflow.com/questions/9001509/how-can-i-sort-a-python-dictionary-sort-by-key/13990710#13990710 for key in sorted(links): (source_file, raw_link_name) = links[key] create_link(key, source_file, raw_link_name, False) LOGGER.info("Creating links for dirs in [%s]", SECTION_SYMLINKS_DIRS) if CONFIG.has_section(SECTION_SYMLINKS_DIRS): for key in CONFIG.options(SECTION_SYMLINKS_DIRS): raw_link_name = read_config(SECTION_SYMLINKS_DIRS, key, '') create_link(key, key, raw_link_name, True) save_config()
def video_root_path(): """Get the video root path from the config file. :return: Video root path. :raise ValueError: if the key is empty """ path = os.path.join(read_config('dirs', 'video_root', ''), '') if not path: raise ValueError("The video_root key is empty in config.ini") return path