def __init__(self, name, textbook_id): if not name: raise ParamError("name should not be None") if not textbook_id: raise ParamError("textbook_id should not be None") self.name = name self.textbook = textbook_id
def __init__(self, name, edition_id): if not name: raise ParamError("name should not be None") if not edition_id: raise ParamError("edition_id should not be None") self.name = name self.edition = edition_id
def __init__(self, name, subject_id): if not name: raise ParamError("name should not be None") if not subject_id: raise ParamError("subject_id should not be None") self.name = name self.subject = subject_id
def __init__(self, username, password): if not username: raise ParamError("username should not be None") if not password: raise ParamError("password should not be None") self.username = username self.password = base64.b64encode( password.encode("utf8")).decode("ascii")
def __init__(self, name, phase_id, num=100): if not name: raise ParamError("name should not be None") if not phase_id: raise ParamError("phase_id should not be None") self.name = name self.phase = phase_id self.num = num
def __init__(self, subject_id, file_path): if not subject_id: raise ParamError("subject_id should not be None") if not file_path: raise ParamError("file_path should not be None") if not os.path.exists(file_path): raise ParamError("file_path={} not exists".format(file_path)) self.subject_id = subject_id self.file_obj = open(file_path, "rb")
def __init__(self, name, province, city, area): if not name: raise ParamError("name should not be None") if not province: raise ParamError("province should not be None") if not city: raise ParamError("city should not be None") if not area: raise ParamError("area should not be None") self.name = name self.province = province self.city = city self.area = area
def __init__(self, resource_id, knowledges: List): if not isinstance(knowledges, (list, tuple)): raise ParamError( "chapters should be type of list, but {} found".format( type(chapters))) self.knowledges = knowledges self.resource_id = resource_id
def __init__(self, question_ids: List[str], subject_id: str = None, chapters: List[str] = None, knowledges: List[str] = None, labels: List[str] = None): if not isinstance(question_ids, (list, tuple)): raise ParamError( "question_ids should not be type of list or tuple, but {} found" .format(type(question_ids))) self.questions = question_ids self.subject_id = subject_id self.chapters = chapters self.knowledges = knowledges self.labels = labels
def get_params(): """ Create the object of the parameters used for the updater, in the file which path is given by filename. It also verifies using JSON Schema specs draft 4 (python implementation) if the json is valid. If an optional parameter isn't in the file, its default value is set. It's still advised to choose a value even if its the default. If a non-optional parameter isn't in the file, an error is raised. Refer to the params JSON schema (whose filename is given in PARAMS_SCHEMA_FILENAME) to build a valid params schema (whose filename is given in PARAMS_FILENAME). More info about JSON Schema : https://json-schema.org/ :return: an object similar to the JSON pattern :raise errors.ParamError: when a parameter isn't present, isn't a correct type or isn't valid """ # get the file JSON structure try: with open(PARAMS_FILENAME, 'r') as p_file: p = json.load(p_file) except SyntaxError as err: msg = "The path of the params file {} might not be valid.".format( PARAMS_FILENAME) log(msg, LOG_ERROR) raise ParamError(msg) from err except FileNotFoundError as err: msg = "The JSON params file {} was not found.".format(PARAMS_FILENAME) log(msg, LOG_ERROR) raise ParamError(msg) from err except json.decoder.JSONDecodeError as err: msg = "The JSON params file {} couldn't be decoded.".format( PARAMS_FILENAME) log(msg, LOG_ERROR) raise ParamError(msg) from err except OSError as err: msg = "Unknown system error while using the JSON params file {}.".format( PARAMS_FILENAME) log(msg, LOG_ERROR) raise ParamError(msg) from err # get the JSON schema used for validation try: with open(PARAMS_SCHEMA_FILENAME, 'r') as p_file: p_schema = json.load(p_file) except SyntaxError as err: msg = "The path of the JSON Schema params file {} might not be valid.".format( PARAMS_SCHEMA_FILENAME) log(msg, LOG_ERROR) raise ParamError(msg) from err except FileNotFoundError as err: msg = "The JSON Schema params file {} was not found.".format( PARAMS_SCHEMA_FILENAME) log(msg, LOG_ERROR) raise ParamError(msg) from err except json.decoder.JSONDecodeError as err: msg = "The JSON Schema params file {} coudln't be decoded.".format( PARAMS_SCHEMA_FILENAME) log(msg, LOG_ERROR) raise ParamError(msg) from err except OSError as err: msg = "Unknow system error while using the JSON params file {}.".format( PARAMS_SCHEMA_FILENAME) log(msg, LOG_ERROR) raise ParamError(msg) from err # validate the parameters try: validate(p, p_schema) except ValidationError as err: msg = "The parameters ({}) aren't valid according to the schema ({}).".format( PARAMS_FILENAME, PARAMS_SCHEMA_FILENAME) log(msg, LOG_ERROR) raise ParamError(msg) from err except SchemaError as err: msg = "The parameters schema {} itself is invalid.".format( PARAMS_SCHEMA_FILENAME) log(msg, LOG_ERROR) raise ParamError(msg) from err # we do not check the branch mode requirements... # maybe a restructuration is necessary ? msg = "{} valid according to the schema {}".format(PARAMS_FILENAME, PARAMS_SCHEMA_FILENAME) log(msg, LOG_INFO) return p
def __init__(self, name, num=100): if not name: raise ParamError("name should not be None") self.name = name self.num = num
def __init__(self, resources=None): if resources and not isinstance(resources, (list, tuple)): raise ParamError( "resources should be list or tuple, but {} found".format( type(resources))) self.resources = resources if resources else []
def __init__(self, question_ids: List[str]): if not isinstance(question_ids, (list, tuple)): raise ParamError( "question_ids should be type of list, but {} found".format( type(question_ids))) self.questions = question_ids