def sid_to_dict(sid): templates = [] for name, pattern in six.iteritems(sid_templates): template = Template( name, pattern, anchor=lucidity.Template.ANCHOR_BOTH, default_placeholder_expression= '[^/]*', # allows for empty keys // should it be '[^|]*' ? duplicate_placeholder_mode=lucidity.Template.STRICT) # template.template_resolver = resolvers templates.append(template) try: """ if len(sid.split('/')) >= 8: data = [] for ext in sid.split('/')[-1].split(','): sid_copy = sid sid_copy = sid_copy.replace(sid_copy.split('/')[-1], ext) data.extend(lucidity.parse(str(sid_copy), templates)[0]) else: """ data, template = lucidity.parse(str(sid), templates) # print 'found', data, template except Exception as e: warn(e) return None if not data: return None ''' for key in list(data.keys()): if key not in shot_keys + asset_keys: data.pop(key) ''' # return template.name, data # need the name ? return data
def path_to_dict(path): path = str(path) # path = os.path.normcase(path) path = path.replace(os.sep, '/') templates = [] for name, pattern in six.iteritems(path_templates): template = Template( name, pattern, anchor=lucidity.Template.ANCHOR_BOTH, default_placeholder_expression= '[^/]*', # needed to use '#' for a path duplicate_placeholder_mode=lucidity.Template.STRICT) template.template_resolver = resolvers templates.append(template) try: data, template = lucidity.parse(path, templates) # print 'found', data, template except Exception as e: warn(e) return None, None if not data: return None, None for key, value in six.iteritems(data): if path_mapping.get(key): value = path_mapping.get(key).get(value, value) data[key] = value for key in list(data.keys()): if key not in shot_keys + asset_keys: data.pop(key) return template.name, data # need the name ?
def test_unsuccessfull_parse(templates): '''Unsuccessful parse of path against multiple candidate templates.''' with pytest.raises(lucidity.ParseError): lucidity.parse('/not/matching', templates)
def test_successfull_parse(path, expected, templates): '''Parse path successfully against multiple candidate templates.''' data, template = lucidity.parse(path, templates) assert data == expected