Set the remaining Codebase attributes `temp_dir` is the base temporary directory to use to cache resources on disk and other temporary files. `max_in_memory` is the maximum number of Resource instances to keep in memory. Beyond this number, Resource are sav
(self, temp_dir=temp_dir, max_in_memory=10000)
| 358 | return sorted(paths, key=_sorter) |
| 359 | |
| 360 | def _setup_essentials(self, temp_dir=temp_dir, max_in_memory=10000): |
| 361 | """ |
| 362 | Set the remaining Codebase attributes |
| 363 | |
| 364 | `temp_dir` is the base temporary directory to use to cache resources on |
| 365 | disk and other temporary files. |
| 366 | |
| 367 | `max_in_memory` is the maximum number of Resource instances to keep in |
| 368 | memory. Beyond this number, Resource are saved on disk instead. -1 means |
| 369 | no memory is used and 0 means unlimited memory is used. |
| 370 | """ |
| 371 | |
| 372 | # setup Resources |
| 373 | ######################################################################## |
| 374 | # root resource, never cached on disk |
| 375 | self.root = None |
| 376 | |
| 377 | # mapping of {path: Resource}. This the key data structure of a Codebase. |
| 378 | # All resources MUST exist there. When cached to disk the value is CACHED_RESOURCE |
| 379 | self.resources_by_path = {} |
| 380 | self.resources_count = 0 |
| 381 | |
| 382 | # setup caching |
| 383 | ######################################################################## |
| 384 | # dir used for caching and other temp files |
| 385 | self.temp_dir = temp_dir |
| 386 | |
| 387 | # maximum number of Resource objects kept in memory cached in this |
| 388 | # Codebase. When the number of in-memory Resources exceed this number, |
| 389 | # the next Resource instances are saved to disk instead and re-loaded |
| 390 | # from disk when used/needed. |
| 391 | self.max_in_memory = max_in_memory |
| 392 | # use only memory |
| 393 | self.all_in_memory = max_in_memory == 0 |
| 394 | # use only disk |
| 395 | self.all_on_disk = max_in_memory == -1 |
| 396 | |
| 397 | # dir where the on-disk cache is stored |
| 398 | self.cache_dir = None |
| 399 | if not self.all_in_memory: |
| 400 | # this is unique to this codebase instance |
| 401 | self.cache_dir = get_codebase_cache_dir(temp_dir=temp_dir) |
| 402 | |
| 403 | # setup extra and misc attributes |
| 404 | ######################################################################## |
| 405 | |
| 406 | # stores a list of Header records for this codebase |
| 407 | self.headers = [] |
| 408 | self.current_header = None |
| 409 | |
| 410 | # mapping of scan counters at the codebase level such |
| 411 | # as the number of files and directories, etc |
| 412 | self.counters = dict() |
| 413 | |
| 414 | # mapping of timings for scan stage as {stage: time in seconds as float} |
| 415 | # This is populated automatically. |
| 416 | self.timings = dict() |
| 417 |
no test coverage detected