Return full absolute base path to the content pack directory. Note: This function looks for a pack in all the load paths and return path to the first pack which matched the provided name. If a pack is not found, we return a pack which points to the first packs directory (this is
(pack_name, include_trailing_slash=False, use_pack_cache=False)
| 133 | |
| 134 | |
| 135 | def get_pack_base_path(pack_name, include_trailing_slash=False, use_pack_cache=False): |
| 136 | """ |
| 137 | Return full absolute base path to the content pack directory. |
| 138 | |
| 139 | Note: This function looks for a pack in all the load paths and return path to the first pack |
| 140 | which matched the provided name. |
| 141 | |
| 142 | If a pack is not found, we return a pack which points to the first packs directory (this is |
| 143 | here for backward compatibility reasons). |
| 144 | |
| 145 | :param pack_name: Content pack name. |
| 146 | :type pack_name: ``str`` |
| 147 | |
| 148 | :param include_trailing_slash: True to include trailing slash. |
| 149 | :type include_trailing_slash: ``bool`` |
| 150 | |
| 151 | :param use_pack_cache: True to cache base paths on per-pack basis. This help in situations |
| 152 | where this method is called multiple times with the same pack name. |
| 153 | :type use_pack_cache`` ``bool`` |
| 154 | |
| 155 | :rtype: ``str`` |
| 156 | """ |
| 157 | if not pack_name: |
| 158 | return None |
| 159 | |
| 160 | if use_pack_cache and pack_name in PACK_NAME_TO_BASE_PATH_CACHE: |
| 161 | return PACK_NAME_TO_BASE_PATH_CACHE[pack_name] |
| 162 | |
| 163 | packs_base_paths = get_packs_base_paths() |
| 164 | for packs_base_path in packs_base_paths: |
| 165 | pack_base_path = os.path.join(packs_base_path, quote_unix(pack_name)) |
| 166 | pack_base_path = os.path.abspath(pack_base_path) |
| 167 | |
| 168 | if os.path.isdir(pack_base_path): |
| 169 | if include_trailing_slash and not pack_base_path.endswith(os.path.sep): |
| 170 | pack_base_path += os.path.sep |
| 171 | |
| 172 | PACK_NAME_TO_BASE_PATH_CACHE[pack_name] = pack_base_path |
| 173 | return pack_base_path |
| 174 | |
| 175 | # Path with the provided name not found |
| 176 | pack_base_path = os.path.join(packs_base_paths[0], quote_unix(pack_name)) |
| 177 | pack_base_path = os.path.abspath(pack_base_path) |
| 178 | |
| 179 | if include_trailing_slash and not pack_base_path.endswith(os.path.sep): |
| 180 | pack_base_path += os.path.sep |
| 181 | |
| 182 | PACK_NAME_TO_BASE_PATH_CACHE[pack_name] = pack_base_path |
| 183 | return pack_base_path |
| 184 | |
| 185 | |
| 186 | def get_pack_directory(pack_name): |