def get_model(ldraw_path): """" get model from ldraw path """ config = get_config() parts = Parts(config['parts.lst']) try: model = Part(ldraw_path) except PartError: sys.stderr.write("Failed to read LDraw file: %s\n" % ldraw_path) sys.exit(1) return model, parts
def try_download_generate_lib(): # Download the library and generate it, if needed config = get_config() parts_lst_path = config['parts.lst'] output_dir = os.path.dirname(parts_lst_path) if not os.path.exists(output_dir) and not os.path.exists(parts_lst_path): download(output_dir) data_dir = get_data_dir() library_path = config.get('library') if library_path is not None: generate(parts_lst_path, library_path) return library_path else: try: # try to write the library to ldraw package folder (can work if user-writeable) ldraw_path = os.path.abspath(os.path.dirname(__file__)) generate(parts_lst_path, ldraw_path) return ldraw_path except (OSError, IOError): # Failed, then write it to data_dir generate(parts_lst_path, data_dir) return data_dir
from ldraw.geometry import Vector from ldraw.lines import MetaCommand from ldraw.parts import Parts from ldraw.config import get_config from ldraw.pieces import Piece from constants import * config = get_config() parts = Parts(config['parts.lst']) class Connections: def __init__(self, top=None, bottom=None, left=None, right=None, front=None, back=None): self.top = top self.bottom = bottom self.left = left self.right = right self.front = front self.back = back class BoudingBox(object): def __init__(self, min, max):
def __init__(self, parts_lst=None, others_threshold=None): config = get_config() if parts_lst is None: parts_lst = config['parts.lst'] if others_threshold is None: others_threshold = config.get('others_threshold', 5) self.path = None self.parts_dirs = [] self.parts_subdirs = {} self.parts_by_name = {} self.parts_by_code = {} self.parts_by_code_name = {} self.primitives_by_name = {} self.primitives_by_code = {} self.colours = {} self.alpha_values = {} self.colour_attributes = {} self.colours_by_name = {} self.colours_by_code = {} self.parts = AttrDict(minifig=AttrDict(hats={}, heads={}, torsos={}, hips={}, legs={}, arms={}, hands={}, accessories={})) self.minifig_descriptions = { 'torsos': 'Torso', 'hips': 'Hip', 'arms': 'Arm', 'heads': 'Head', 'accessories': 'Accessory', 'hands': 'Hand', 'hats': 'Hat', 'legs': 'Leg' } self.parts_by_category = defaultdict(lambda: {}) self.load(parts_lst) # relatively useless categories for k in list(self.parts_by_category.keys()): if len(self.parts_by_category.get(k)) < others_threshold: self.parts_by_category['others'].update( self.parts_by_category.pop(k)) # reference in others for v in self.parts_by_category.values(): self.parts_by_category['others'].update(v) for k in list(self.parts_by_category.keys()): split = k.split() if len(split) == 1: value = self.parts_by_category.pop(k) if k in self.parts: self.parts[k][''] = value else: self.parts[k] = value pass
def test_config_can_load(open_mock): assert get_config() == {'parts.lst': '/home/file_path'}
def test_config_can_load_Win(open_mock): assert get_config() == {'parts.lst': 'C:\\file_path'}
def test_config_cant_load(yaml_load_mock): yaml_load_mock.side_effect = fails expected = os.path.join(get_data_dir(), 'ldraw', 'parts.lst') assert get_config()['parts.lst'] == expected