def from_test_repr(file_test_repr, base_path=None): assert is_arrayish(file_test_repr) assert len(file_test_repr) >= 2 file_type, old_path, *remainder = file_test_repr old_file_ref = FileReference( BAONPath.from_test_repr(base_path, old_path), file_type == 'DIR', ) new_path = old_path override = False if len(remainder) > 0 and remainder[-1] == 'OVERRIDE': remainder = remainder[:-1] override = True if len(remainder) > 0 and not is_arrayish(remainder[0]): new_path, *remainder = remainder return RenamedFileReference( old_file_ref, BAONPath.from_test_repr(base_path, new_path), [BAONError.from_test_repr(error_repr) for error_repr in remainder], override, )
def _replace_rec(value): if is_string(value): return _replace_scalar(value) elif is_arrayish(value): return tuple(_replace_rec(subitem) for subitem in value) elif is_dictish(value): return {key: _replace_rec(value) for key, value in value.items()} else: return value
def from_json_representation(cls, json_repr): if not is_arrayish(json_repr): raise ValueError('JSON representation of action should be a vector') if len(json_repr) == 0: raise ValueError('JSON representation of action should start with the action type') action_type = json_repr[0] action_class = get_action_class(action_type) return action_class.from_json_representation(json_repr)
def from_json_representation(cls, json_repr): if not is_arrayish(json_repr): raise ValueError('JSON representation of action should be a vector') if len(json_repr) != 3: raise ValueError('JSON representation of action has incorrect length') action_type, from_path, to_path = json_repr if action_type != cls.action_name_for_json_representation(): raise ValueError("Expected JSON representation to start with '{0}' for this action".format(action_type)) return cls(from_path, to_path)
def parse_qcolor(color_spec): try: if is_string(color_spec): return _parse_qcolor_string(color_spec) elif is_arrayish(color_spec): return _parse_qcolor_arrayish(color_spec) elif is_dictish(color_spec): return _parse_qcolor_dictish(color_spec) raise ValueError('Unsupported format') except Exception as e: message = 'Invalid QColor spec "{0}" - {1}'.format(color_spec, e) raise ValueError(message) from None
def from_test_repr(file_test_repr, base_path=None): assert is_arrayish(file_test_repr) assert len(file_test_repr) >= 2 file_type, path, *errors = file_test_repr assert file_type in ['FILE', 'DIR'] file_ref = FileReference( BAONPath.from_test_repr(base_path, path), file_type == 'DIR', problems=[BAONError.from_test_repr(error_repr) for error_repr in errors], ) return file_ref
def from_json_representation(json_repr): if not is_dictish(json_repr): raise ValueError("JSON representation of plan should be a dictionary") if 'steps' not in json_repr: raise ValueError("Missing top-level field 'steps'") steps_repr = json_repr['steps'] if not is_arrayish(steps_repr): raise ValueError("Expected vector for 'steps' field") steps = [RenamePlanAction.from_json_representation(action_repr) for action_repr in steps_repr] comment = None if 'comment' in json_repr: if not is_string(json_repr['comment']): raise ValueError("Expected string for 'comment' field") comment = json_repr['comment'] return RenamePlan(steps, comment)
def from_test_repr(error_repr): assert is_arrayish(error_repr) assert len(error_repr) > 0 error_class = error_repr[0] assert error_class in [ "SyntheticFileError", "SyntheticFileWarning", ], "Only SyntheticFileError and SyntheticFileWarning are supported" if error_class == "SyntheticFileError": from baon.core.files.__errors__.file_reference_errors import SyntheticFileError return SyntheticFileError() elif error_class == "SyntheticFileWarning": from baon.core.files.__errors__.file_reference_errors import SyntheticFileWarning return SyntheticFileWarning()