class Task(db.Model, AbstractModel): __tablename__ = 'TASK' _properties = TaskProperties() # --------- Columns --------- id = db.Column(**_properties.get_sql_attr_column('id')) action = db.Column(db.ForeignKey('ACTION.ID'), **_properties.get_sql_attr_column('action')) task_params = db.Column(db.ForeignKey('TASK_PARAMS.ID'), **_properties.get_sql_attr_column('task_params')) custom_label = db.Column(**_properties.get_sql_attr_column('custom_label')) created_at = db.Column(**_properties.get_sql_attr_column('created_at')) # --------- Relationships --------- task_params_relation = db.relationship( **_properties.get_relation('task_params')) action_relation = db.relationship(**_properties.get_relation('action')) # --------- Constraints --------- UniqueConstraint(action, task_params) def __init__(self, action, task_params, custom_label=""): super().__init__() self.custom_label = custom_label self.action = action self.task_params = task_params # --- Display functions --- @property def serialize(self): lazy_dict = self.serialize_lazy lazy_dict['task_params'] = self.task_params_relation.serialize return lazy_dict @property def serialize_lazy(self): return { 'id': self.id, 'action': self.action, 'custom_label': self.custom_label, 'task_params': self.task_params, 'created_at': self.created_at, } def __repr__(self): return '{} : {}'.format(self.table_name(), self.serialize_lazy)
class TaskParams(db.Model, AbstractModel): __tablename__ = 'TASK_PARAMS' _properties = TaskParamsProperties() # --------- Columns --------- id = db.Column( **_properties.get_sql_attr_column('id')) generic_params_patterns = db.Column( db.ForeignKey('GENERIC_PARAMS_PATTERNS.ID'), **_properties.get_sql_attr_column('generic_params_patterns')) params_dictionaries = db.Column( db.ForeignKey('PARAMS_DICTIONARIES.ID'), **_properties.get_sql_attr_column('params_dictionaries')) # --------- Relationships --------- generic_params_patterns_relation = db.relationship( **_properties.get_relation('generic_params_patterns')) params_dictionaries_relation = db.relationship( **_properties.get_relation('params_dictionaries')) # --------- Constraints --------- UniqueConstraint(generic_params_patterns, params_dictionaries) def __init__(self, generic_params_patterns, params_dictionaries): super().__init__() self.generic_params_patterns = generic_params_patterns self.params_dictionaries = params_dictionaries # --- Display functions --- @property def serialize(self): lazy_dict = self.serialize_lazy lazy_dict['generic_params_patterns'] = self.\ generic_params_patterns_relation\ .serialize_lazy lazy_dict['params_dictionaries'] = self.params_dictionaries_relation\ .serialize_lazy return lazy_dict @property def serialize_lazy(self): return { 'id': self.id, 'generic_params_patterns': self.generic_params_patterns, 'params_dictionaries': self.params_dictionaries }
class UserTask(db.Model, AbstractModel): __tablename__ = 'USER_TASK' _properties = UserTaskProperties() # --------- Columns --------- id = db.Column(**_properties.get_sql_attr_column('id')) task = db.Column(db.ForeignKey('TASK.ID'), **_properties.get_sql_attr_column('task')) params_dictionaries = db.Column( db.ForeignKey('PARAMS_DICTIONARIES.ID'), **_properties.get_sql_attr_column('params_dictionaries')) created_at = db.Column(**_properties.get_sql_attr_column('created_at')) # --------- Relationships --------- params_dictionaries_relation = db.relationship( **_properties.get_relation('params_dictionaries')) task_relation = db.relationship(**_properties.get_relation('task')) # --------- Constraints --------- UniqueConstraint(task, params_dictionaries) def __init__(self, task, params_dictionaries): super().__init__() self.task = task self.params_dictionaries = params_dictionaries # --- Display functions --- @property def serialize(self): lazy_dict = self.serialize_lazy lazy_dict['task'] = self.task_relation.serialize lazy_dict[ 'params_dictionaries'] = self.params_dictionaries_relation.serialize return lazy_dict @property def serialize_lazy(self): return { 'id': self.id, 'task': self.task, 'params_dictionaries': self.params_dictionaries, 'created_at': self.created_at, }
class TaskEvent(db.Model, AbstractModel): __tablename__ = 'TASK_EVENT' _properties = TaskEventProperties() id = db.Column( **_properties.get_sql_attr_column('id')) user_task = db.Column( db.ForeignKey('USER_TASK.ID'), **_properties.get_sql_attr_column('user_task')) begin = db.Column( **_properties.get_sql_attr_column('begin')) end = db.Column( **_properties.get_sql_attr_column('end')) status = db.Column( **_properties.get_sql_attr_column('status')) # --------- Relationships --------- user_task_relation = db.relationship( **_properties.get_relation('user_task')) def __init__(self, user_task): super().__init__() self.user_task = user_task # --- Display functions --- @property def serialize(self): lazy_dict = self.serialize_lazy return lazy_dict @property def serialize_lazy(self): return { 'id': self.id, 'user_task': self.user_task, 'begin': self.begin, 'end': self.end, 'status': self.status, }
class LogEvent(db.Model, AbstractModel): __tablename__ = 'LOG_EVENT' _properties = LogEventProperties() id = db.Column( **_properties.get_sql_attr_column('id')) task_event = db.Column( db.ForeignKey('TASK_EVENT.ID'), **_properties.get_sql_attr_column('task_event')) status_code = db.Column( **_properties.get_sql_attr_column('status_code')) stderr = db.Column( **_properties.get_sql_attr_column('stderr')) stdout = db.Column( **_properties.get_sql_attr_column('stdout')) # --------- Relationships --------- task_event_relation = db.relationship( **_properties.get_relation('task_event')) def __init__(self, task_event): super().__init__() self.task_event = task_event # --- Display functions --- @property def serialize(self): lazy_dict = self.serialize_lazy return lazy_dict @property def serialize_lazy(self): return { 'id': self.id, 'task_event': self.task_event, 'status_code': self.status_code, 'stdout': self.stdout, 'stderr': self.stderr, }
class GenericParamsPatterns(db.Model, AbstractModel): __tablename__ = 'GENERIC_PARAMS_PATTERNS' _properties = GenericParamsPatternsProperties() # --------- Columns --------- id = db.Column( **_properties.get_sql_attr_column('id')) generic_args_pattern = db.Column( **_properties.get_sql_attr_column('generic_args_pattern')) generic_target_pattern = db.Column( **_properties.get_sql_attr_column('generic_target_pattern')) # --------- Constraints --------- UniqueConstraint(generic_args_pattern, generic_target_pattern) # --------- Constructor --------- def __init__(self, generic_args_pattern, generic_target_pattern): super().__init__() self.generic_args_pattern = generic_args_pattern self.generic_target_pattern = generic_target_pattern # --- Display functions --- @property def serialize(self): lazy_dict = self.serialize_lazy return lazy_dict @property def serialize_lazy(self): return { 'id': self.id, 'generic_args_pattern': self.generic_args_pattern, 'generic_target_pattern': self.generic_target_pattern }
class ParamsDictionaries(db.Model, AbstractModel): __tablename__ = 'PARAMS_DICTIONARIES' _properties = ParamsDictionariesProperties() # --------- Columns --------- id = db.Column(**_properties.get_sql_attr_column('id')) args_dictionary = db.Column( **_properties.get_sql_attr_column('args_dictionary')) target_dictionary = db.Column( **_properties.get_sql_attr_column('target_dictionary')) # --------- Constraints --------- UniqueConstraint(args_dictionary, target_dictionary) # --------- Constructor --------- def __init__(self, args_dictionary, target_dictionary): super().__init__() self.args_dictionary = args_dictionary self.target_dictionary = target_dictionary # --- Display functions --- @property def serialize(self): serialized_dict = self.serialize_lazy return serialized_dict @property def serialize_lazy(self): return { 'id': self.id, 'args_dictionary': json.loads(self.args_dictionary), 'target_dictionary': json.loads(self.target_dictionary) }
class Module(db.Model, AbstractModel): __tablename__ = 'MODULE' _properties = ModuleProperties() # --------- Columns --------- id = db.Column(**_properties.get_sql_attr_column('id')) label = db.Column(**_properties.get_sql_attr_column('label')) command = db.Column(**_properties.get_sql_attr_column('command')) is_preset = db.Column(**_properties.get_sql_attr_column('is_preset')) # --------- Relationships --------- action_list = db.relationship(**_properties.get_relation('action_list')) # --------- Constraints --------- UniqueConstraint(command, label) # --------- Constructor --------- def __init__(self, label, command, is_preset=False): super(Module, self).__init__() self.label = label self.command = command self.is_preset = is_preset # --- Display functions --- @property def serialize(self): lazy_dict = self.serialize_lazy lazy_dict['action_list'] = list_to_json(self.action_list) return lazy_dict @property def serialize_lazy(self): return super(Module, self).serialize_lazy
class Action(db.Model, AbstractModel): __tablename__ = 'ACTION' _properties = ActionProperties() # --------- Columns --------- id = db.Column(**_properties.get_sql_attr_column('id')) module = db.Column(db.ForeignKey('MODULE.ID'), **_properties.get_sql_attr_column('module')) category = db.Column(**_properties.get_sql_attr_column('category')) label = db.Column(**_properties.get_sql_attr_column('label')) command = db.Column(**_properties.get_sql_attr_column('command')) is_tested = db.Column(**_properties.get_sql_attr_column('is_tested')) is_preset = db.Column(**_properties.get_sql_attr_column('is_preset')) # --------- Constraints --------- UniqueConstraint(module, command) # --------- Constructor --------- def __init__(self, module, label, command, category='', is_preset=False, is_tested=False): super(Action, self).__init__() self.module = module self.category = category self.label = label self.command = command self.is_tested = is_tested self.is_preset = is_preset # --- Display functions --- @property def serialize(self): lazy_dict = self.serialize_lazy return lazy_dict