| 5244 | self.add(item) |
| 5245 | |
| 5246 | def add(self, item): |
| 5247 | if item == '/': |
| 5248 | self.filemap[f'/{self.url_prefix}[root]'] = '/' |
| 5249 | return '/[root]' |
| 5250 | |
| 5251 | item = os.path.abspath(normalize_path(item)) |
| 5252 | |
| 5253 | if not os.path.exists(item): |
| 5254 | if not self.quiet: |
| 5255 | logger.warning(f"'{item}' does not exist and will be ignored.") |
| 5256 | return None |
| 5257 | |
| 5258 | if item in self.filemap.values(): |
| 5259 | for _urlpath, _item in self.filemap.items(): |
| 5260 | if _item == item: |
| 5261 | return _urlpath |
| 5262 | |
| 5263 | urlpath = f"/{self.url_prefix}{os.path.basename(item)}" |
| 5264 | while urlpath in self.filemap: |
| 5265 | root, ext = os.path.splitext(urlpath) |
| 5266 | urlpath = root + '_' + ext |
| 5267 | self.filemap[urlpath] = item |
| 5268 | return urlpath |
| 5269 | |
| 5270 | def remove(self, item): |
| 5271 | item = os.path.abspath(normalize_path(item)) |