--- a/filecache.py Fri Sep 18 21:57:36 2020 +0300 +++ b/filecache.py Fri Sep 18 23:51:45 2020 +0300 @@ -40,19 +40,12 @@ self.problem = None self.has_studs = None # Whether or not it contains studs self.vertices = set() - def __init__(self, ldraw_directories): + def __init__(self, context): ''' Initializes a new subfile cache ''' self.cache = dict() - if ldraw_directories and isinstance(ldraw_directories[0], str): - self.ldraw_directories = [ - Path(os.path.expanduser(directory)) - for directory in ldraw_directories - ] - else: - from copy import copy - self.ldraw_directories = copy(ldraw_directories) + self.context = context self.reference_stack = [] def flatness_of(self, filename): ''' @@ -69,7 +62,7 @@ def find_file(self, filename): return find_ldraw_file( filename = filename, - libraries = self.ldraw_directories, + libraries = self.context.libraries, ) def prepare_file(self, filename): ''' @@ -90,10 +83,7 @@ try: path = self.find_file(filename) with path.open('rb') as file: - model = parse.read_ldraw( - file, - ldraw_directories = self.ldraw_directories, - ) + model = parse.read_ldraw(file, context = self.context) except (FileNotFoundError, IOError, PermissionError) as error: subfile.valid = False subfile.problem = str(error) @@ -129,6 +119,3 @@ for subfile_reference in model.subfile_references ) self.reference_stack.pop() - -if __name__ == '__main__': - cache = SubfileCache(ldraw_directories = ["~/ldraw"])